Debian 8.11 init.d脚本无法在启动时运行

时间:2018-09-03 01:20:04

标签: startup init.d debian-jessie

我已根据this guide创建了以下init.d脚本,该脚本旨在在启动时启动this branch of MaNGOS

#!/bin/sh
### BEGIN INIT INFO
# Provides: mangosd
# Should-Start: console-screen dbus network-manager
# Required-Start: $all
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start mangosd at boot time
### END INIT INFO
#

set -e

/lib/lsb/init-functions

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin

SCRIPT="/usr/local/sbin/realmd.sh"
SCRIPT2="/usr/local/sbin/mangosd.sh"
PROGRAMNAME="realmd"
PROGRAMNAME2="mangosd"
case "$1" in
start)
     $SCRIPT
     $SCRIPT2
     ;;
stop)
     pkill $PROGRAMNAME
     pkill $PROGRAMNAME2
     ;;
esac

exit 0

我能够使用sudo /etc/init.d/mangosd start运行此脚本,这将使其按预期方式运行,并运行realmd.sh和mangosd.sh,如下所示。

realmd.sh:

 #!/bin/sh
 # /usr/local/sbin/realmd.sh

 /home/rebirth/MaNGOS/bin/realmd &

mangosd.sh:

 #!/bin/sh
 # /usr/local/sbin/mangosd.sh

 cd /home/rebirth/MaNGOS/bin
 ./mangosd &

所有三个文件具有相同的权限,如下所示:

 -rwxr-xr-x 1 root root 80 Sep  2 20:33 /usr/local/sbin/mangosd.sh

程序realmdmangosd将按预期运行。按照指南,我已经运行sudo insserv mangosd并验证了启动文件已创建:

 $ ls -la /etc/rc2.d/S04mangosd
 lrwxrwxrwx 1 root root 17 Sep  2 18:00 /etc/rc2.d/S04mangosd -> ../init.d/mangosd

我运行了sudo reboot,并且realmdmangosd都没有在启动时自动启动。此时,手动运行init.d脚本仍然可以按预期运行。

我查看了以下与该问题有关的帖子:

Init.d script to start Hudson doesn't run at boot on Ubuntu

debian init.d script not running after reboot

两者均未提供解决方案,但是后者确实提供了我没有尝试过的另一条命令sudo update-rc.d mangosd defaults。不幸的是,运行此命令并重新启动后,realmdmangosd在引导时仍未自动运行。

如果有人有任何建议,或者能够为我指出正确的方向,我将非常感谢。非常感谢你!

1 个答案:

答案 0 :(得分:0)

您可以在debian上的/etc/init.d/目录中检查一个名为skeleton的文件,该文件应该可以帮助人们开始使用定制的init.d服务。

此行不是必需的,您可以将其删除:

# Should-Start: console-screen dbus network-manager

替换:

 /lib/lsb/init-functions

使用

. /lib/lsb/init-functions

您也应该删除:

set -e

如果它不起作用,您可以尝试设置默认值required-start到此:

# Required-Start: $remote_fs $syslog

因此最终文件可以是:(未经测试)

#!/bin/sh
### BEGIN INIT INFO
# Provides: mangosd
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start mangosd at boot time
### END INIT INFO
#

. /lib/lsb/init-functions

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin

SCRIPT="/usr/local/sbin/realmd.sh"
SCRIPT2="/usr/local/sbin/mangosd.sh"
PROGRAMNAME="realmd"
PROGRAMNAME2="mangosd"
case "$1" in
start)
     $SCRIPT
     $SCRIPT2
     ;;
stop)
     pkill $PROGRAMNAME
     pkill $PROGRAMNAME2
     ;;
esac

exit 0

这些链接可以为您提供帮助:

Debian Wiki:https://wiki.debian.org/LSBInitScripts/

原始脚本示例:https://gist.github.com/gsf/6222405

另一个示例:https://gist.github.com/wallyqs/c96d56e735c74ee4cc1f

相关问题