繁体   English   中英

服务将无法在Linux启动时启动

[英]Service will not start on Linux Boot

下午好,

我在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

看来您的依存关系有问题。 您必须确保在setdatetime服务之前已启动syslog服务。

显然,如果您手动启动服务,则计算机已经完成了启动,因此syslog正在运行,因此您的服务正常运行。

您也可以尝试删除对syslog的依赖性。

甚至更好:由于服务仅运行一次,因此您也可以在文件的最后一行之前将适当的命令放在/etc/rc.local中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM