【问题标题】:Why didn't my init.d start-stop-daemon script start the application on boot, but I can start the service manually?为什么我的 init.d start-stop-daemon 脚本在启动时没有启动应用程序,但我可以手动启动服务?
【发布时间】:2023-03-31 12:56:01
【问题描述】:

我以为我终于成功地编写了我的第一个 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,它会起作用。然而,当我重新启动时,它并没有自动启动。我错过了什么?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      尝试使用 chkconfig 将其添加到必要的运行级别

      # chkconfig foo on
      

      你可能需要这样做

      # chkconfig --add foo
      

      第一

      【讨论】:

        【解决方案3】:

        您需要各种 /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

        【讨论】:

          【解决方案4】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-07-24
            • 1970-01-01
            • 2014-01-02
            • 1970-01-01
            • 1970-01-01
            • 2013-01-16
            • 2018-06-30
            • 1970-01-01
            相关资源
            最近更新 更多