-1

First of all sorry for my bad english

Ok, i wrote a init.d script and i don't know its true or false (i am new at this things)

#!/bin/sh
. /etc/init.d/someserver

start () {
    echo -n $"Starting someserver.jar: "

    java -jar /home/someserver/someserver.jar &
    echo $! > /home/someserver/someserver.pid
}

stop () {
    echo -n $"Stopping someserver.jar: "

    PID=$(/home/someserver/someserver.pid) 
    kill -9 $PID
}

restart() {
    stop
    start
}

case $1 in
    start)
        start
    ;;
    stop)
        stop
    ;;
    *)

    echo $"Usage: someserver {start|stop}"
    exit 1
esac

after that i use this commands;

$ sudo chmod 755 /etc/init.d/someserver

$ sudo update-rc.d someserver defaults

i am getting this info;

insserv: warning: script 'someserver' missing LSB tags and overrides

/etc/init.d/someserver: 6: .: 3: Too many open files

I search the errors and info's but i can't understand so what does it mean and what should i do?

Note:os debian, and i writing this for mmonit

C.T
  • 33
  • 1
  • 4

1 Answers1

3

Have you looked at other init scripts for reference?

Let's go through this section by section. First let's name a shell to be executed. Ok.

#!/bin/sh

Now please put LSB tags there as the init system suggests (tells the init system the dependencies)

### BEGIN INIT INFO
# Provides:          someserver
# Required-Start:    $syslog $network $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      $local_fs $named
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: someserver
# Description:       Some Server
### END INIT INFO

Then you sourced the init script itself, why? That's probably why the error you mentioned occurs, as this way it's called recursively, which is probably not what was intended.

Usually you source some script to get a config or so:

# source some config (can be omitted)
[ -f /etc/configs/someserver ] && source /etc/configs/someserver

Why do you have the dollar signs in every echo statement? (Ok, localization, I believe)

(Note: By looking at some other init script you see that debian uses the start-stop-daemon to manage daemons, so you may implement that. I don't do that here.)

start () {
    echo -n "Starting someserver.jar: "

    java -jar /home/someserver/someserver.jar &
    echo $! > /home/someserver/someserver.pid
}

You forgot a cat in stop().

Also I would not necessarily kill -9 but first only kill. You can put in a check if it really disappears and then kill -9. Again, maybe you should use start-stop-daemon.

stop () {
    echo -n "Stopping someserver.jar: "

    PID=$(cat /home/someserver/someserver.pid) 
    kill $PID
}

You generally want to wait a little bit before restarting

restart() {
    stop
    sleep 10
    start
}

Finally you should also implement restart.

case "$1" in
    start)
      start
      ;;

    stop)
      stop
      ;;

    restart)
      restart
      ;;

    *)
      echo "Usage: someserver {start|stop|restart}"
      exit 1
      ;;
esac

Wasn't that bad. But you missed some details.

Marki
  • 2,795
  • 3
  • 27
  • 45
  • Thank you i did it and it works now and i do some changes `screen -A -m -d -S someserver java -jar /home/someserver/someserver.jar screen -list | grep someserver | cut -f1 -d'.' | sed 's/\W//g' > /home/someserver/someserver.pid` little bit complex but it works – C.T Nov 22 '14 at 21:18