【问题标题】:Debian 8.11 init.d script won't run at startupDebian 8.11 init.d 脚本不会在启动时运行
【发布时间】:2019-02-08 01:34:13
【问题描述】:

我根据 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 仍然没有在启动时自动运行。

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

【问题讨论】:

    标签: startup init.d debian-jessie


    【解决方案1】:

    您可以在 debian 上查看名为骨架的文件,该文件位于目录 /etc/init.d/ 中,该文件旨在帮助人们开始使用自定义 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 维基:https://wiki.debian.org/LSBInitScripts/

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 2018-04-14
      • 2013-02-16
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多