【问题标题】:Service will not start on Linux Boot服务不会在 Linux Boot 上启动
【发布时间】:2014-11-27 07:52:12
【问题描述】:

下午好,

我在 Debian(在 Raspberry Pi 上)使用 update-rc.d 插入启动服务时遇到问题

我正在运行的插入服务的命令是:

sudo update-rc.d setdatetime defaults

chmod 权限设置为 755 的服务本身(文件 /etc/init.d/setdatetime)如下所示:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          update
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       This service is used to set date and time
### END INIT INFO


case "$1" in
    start)
        echo "Setting date and time"
        sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
        ;;
    stop)
        ;;
    *)
        echo "Usage: /etc/init.d/setdatetime start|stop"
        exit 1
        ;;
esac

exit 0

我可以使用

毫无问题地运行该服务
sudo /etc/init.d/setdatetime start

ls /etc/rc*.d 列出已安装的服务:

但是服务在启动时没有运行!我错过了什么???

open@localhost ~ $ ls /etc/rc*.d
/etc/rc0.d:
K01alsa-utils    K01open-client   K01setdatetime   K05nfs-common  K09halt
K01fake-hwclock  K01open-iconfig  K01triggerhappy  K05rpcbind     README
K01ifplugd       K01open-update   K01urandom       K06hwclock.sh
K01lightdm       K01open-web      K02sendsigs      K06networking
K01mongod        K01plymouth      K03rsyslog       K07umountfs
K01mosquitto     K01samba         K04umountnfs.sh  K08umountroot

/etc/rc1.d:
K01alsa-utils    K01mosquitto     K01samba         K05rpcbind    S02single
K01fake-hwclock  K01open-client   K01setdatetime   README
K01ifplugd       K01open-iconfig  K01triggerhappy  S01bootlogs
K01lightdm       K01open-update   K03rsyslog       S01killprocs
K01mongod        K01open-web      K05nfs-common    S01motd

/etc/rc2.d:
K01lightdm     S01motd          S02dphys-swapfile   S02rsync
K05nfs-common  S01rsyslog       S02mosquitto        S02setdatetime
K05rpcbind     S01samba         S02ntp              S02ssh
README         S01sudo          S02open-client      S04plymouth
S01bootlogs    S01triggerhappy  S02open-iconfig     S04rc.local
S01ifplugd     S02cron          S02open-update      S04rmnologin
S01mongod      S02dbus          S02open-web

/etc/rc3.d:
K05nfs-common  S01rsyslog         S02mosquitto        S02setdatetime
K05rpcbind     S01samba           S02ntp              S02ssh
README         S01sudo            S02open-client      S03lightdm
S01bootlogs    S01triggerhappy    S02open-iconfig     S04plymouth
S01ifplugd     S02cron            S02open-update      S04rc.local
S01mongod      S02dbus            S02open-web         S04rmnologin
S01motd        S02dphys-swapfile  S02rsync

/etc/rc4.d:
K05nfs-common  S01rsyslog         S02mosquitto        S02setdatetime
K05rpcbind     S01samba           S02ntp              S02ssh
README         S01sudo            S02open-client      S03lightdm
S01bootlogs    S01triggerhappy    S02open-iconfig     S04plymouth
S01ifplugd     S02cron            S02open-update      S04rc.local
S01mongod      S02dbus            S02open-web         S04rmnologin
S01motd        S02dphys-swapfile  S02rsync

/etc/rc5.d:
K05nfs-common  S01rsyslog         S02mosquitto        S02setdatetime
K05rpcbind     S01samba           S02ntp              S02ssh
README         S01sudo            S02open-client      S03lightdm
S01bootlogs    S01triggerhappy    S02open-iconfig     S04plymouth
S01ifplugd     S02cron            S02open-update      S04rc.local
S01mongod      S02dbus            S02open-web         S04rmnologin
S01motd        S02dphys-swapfile  S02rsync

/etc/rc6.d:
K01alsa-utils    K01open-client      K01setdatetime   K05nfs-common  K09reboot
K01fake-hwclock  K01open-iconfig     K01triggerhappy  K05rpcbind     README
K01ifplugd       K01open-update      K01urandom       K06hwclock.sh
K01lightdm       K01open-web         K02sendsigs      K06networking
K01mongod        K01plymouth         K03rsyslog       K07umountfs
K01mosquitto     K01samba            K04umountnfs.sh  K08umountroot

/etc/rcS.d:
K05hwclock.sh        S05checkroot.sh            S11networking
K12rpcbind           S06checkroot-bootclean.sh  S12mountnfs.sh
K13nfs-common        S06kmod                    S13mountnfs-bootclean.sh
README               S06mtab.sh                 S14kbd
S01fake-hwclock      S07checkfs.sh              S15console-setup
S01hostname.sh       S08mountall.sh             S16alsa-utils
S01mountkernfs.sh    S09mountall-bootclean.sh   S16bootmisc.sh
S02udev              S10procps                  S16plymouth-log
S03keyboard-setup    S10udev-mtab               S16x11-common
S04mountdevsubfs.sh  S10urandom

【问题讨论】:

  • 您希望用户在启动期间运行该服务吗?该用户可以使用sudo 吗?您已经运行了ntp 服务,为什么还要使用它?
  • 您可能错过了chkconfig
  • 开机过程中控制台是否显示Setting date and time消息?

标签: linux bash service debian


【解决方案1】:

您的依赖项似乎有问题。 您必须确保 syslog 服务在您的 setdatetime 服务之前已启动。

显然,如果您手动启动服务,则计算机已经完成启动,因此系统日志正在运行,因此您的服务可以正常工作。

你也可以尝试去掉对syslog的依赖。

更好: 由于您的服务只运行一次,您还可以将相应的命令放入 /etc/rc.local 中,就在该文件的最后一行之前。

【讨论】:

    猜你喜欢
    • 2019-12-29
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-09
    • 2023-04-05
    相关资源
    最近更新 更多