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

发布于 2024-11-05 01:31:54 字数 1534 浏览 5 评论 0原文

我以为我终于成功地正确编写了我的第一个 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。我认为这不是问题,因为其他服务(例如

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

如果我运行 sudo service start-foo start ,它就会起作用。但是当我重新启动时,它不会自动启动。我缺少什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北城孤痞 2024-11-12 01:31:54

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

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.

樱花细雨 2024-11-12 01:31:54

执行的 chkconfig 将其添加到必要的运行级别

# chkconfig foo on

尝试使用您可能需要

# chkconfig --add foo

首先

Try adding it to the necessary run-levels using chkconfig

# chkconfig foo on

you might need to do

# chkconfig --add foo

first

审判长 2024-11-12 01:31:54

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

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

我偏爱纯白色 2024-11-12 01:31:54

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文