为什么我的 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。我认为这不是问题,因为其他服务(例如 apache) 必须需要同样的东西。我有一个执行以下操作的 makefile:
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确实已将脚本链接到各个运行级别 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.执行的 chkconfig 将其添加到必要的运行级别
尝试使用您可能需要
首先
Try adding it to the necessary run-levels using
chkconfig
you might need to do
first
您需要各个 /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
它可能与您尝试启动它的顺序有关。如果您需要在脚本运行之前启动其他服务,您应该尝试将其按执行顺序进一步向下推。
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.