linuxubuntudebianinit.dstart-stop-daemon

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 didn'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 ) 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?


Solution

  • 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.