为什么我的init.d start-stop-daemon脚本在启动时没有启动应用程序,但我可以手动启动该服务?

时间:2011-05-03 20:26:34

标签: linux ubuntu debian init.d start-stop-daemon

我以为我最终设法正确编写了我的第一个init.d脚本但是当我重新启动时,启动没有发生。脚本start-foo如下所示:

#! /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需要sudo,因为它是打开端口。我认为这不是问题,因为其他服务(如)必须需要相同的东西。我有一个makefile执行以下操作:

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

如果我运行sudo service start-foo start,它就有效。然而,当我重新启动时,它不是自动启动的。我错过了什么?

4 个答案:

答案 0 :(得分:2)

您确实将脚本链接到各种运行级init目录中。假设你的盒子安装了chkconfig,请尝试chkconfig start-foo on启用它。否则,您需要手动将符号链接放入每个运行级别的init dir,并指向该脚本。

答案 1 :(得分:1)

尝试使用chkconfig

将其添加到必要的运行级别
# chkconfig foo on

你可能需要做

# chkconfig --add foo

第一

答案 2 :(得分:1)

您需要在各种/etc/rc.x目录中使用符号链接。

update-rc.d start-foo defaults

这将为您创建符号链接。并删除它们:

update-rc.d start-foo remove

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

答案 3 :(得分:0)

这可能与您尝试启动它的顺序有关。如果您需要在脚本运行之前启动其他服务,则应尝试在执行顺序中进一步向下推送。