开发者

Why didn't my init.d start-stop-daemon script start the application on boot, but I can start the service manually?

I thought I finally had managed to write my first init.d script properly but when I went to reboot, the launch did开发者_开发百科n't happen. The script start-foo looks like this:

#! /bin/sh
# chkconfig 345 85 60
# description: startup script for foo
# processname: foo

NAME=foo
DIR=/etc/foo/services
EXEC=foo.py
PID_FILE=/var/run/foo.pid
IEXE=/etc/init.d/foo
RUN_AS=root

### BEGIN INIT INFO
# Provides:          foo
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     5
# Default-Stop:      0 1 2 3 6
# Description:       Starts the foo service
### END INIT INFO

if [ ! -f $DIR/$EXEC ]
then
        echo "$DIR/$EXEC not found."
        exit
fi

case "$1" in
  start)
        echo -n "Starting $NAME"
    cd $DIR
    start-stop-daemon -d $DIR --start --background --pidfile $PID_FILE --make-pidfile --exec $EXEC --quiet
        echo "$NAME are now running."
        ;;
  stop)
    echo -n "Stopping $NAME"
        kill -TERM `cat $PID_FILE`
    rm $PID_FILE
        echo "$NAME."
        ;;
  force-reload|restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Use: /etc/init.d/$NAME {start|stop|restart|force-reload}"
        exit 1
    ;;
esac
exit 0

foo.py requires sudo as it's opening ports. I assume this is not a problem since other services (like apache) must need the same thing. I have a makefile that does the following:

make install:
  chmod +x start-foo
  cp start-foo /etc/init.d

If I run sudo service start-foo start it works. Yet when I reboot, it's not being auto-started. What am I missing?


You do have the link the script into the various run-level init directories. Try chkconfig start-foo on to enable that, assuming your box has chkconfig installed. Otherwise you need to manually put symlinks into each run level's init dir pointing back at the script.


Try adding it to the necessary run-levels using chkconfig

# chkconfig foo on

you might need to do

# chkconfig --add foo

first


You need symlinks in the various /etc/rc.x directories.

update-rc.d start-foo defaults

This will create the symlinks for you. And to remove them:

update-rc.d start-foo remove

http://manpages.ubuntu.com/manpages/precise/man8/update-rc.d.8.html


It might have something to do with the order of where you're trying to start it. If you need other services started before your script can run, you should try to push it further down in the execution order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜