下午好
我在 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的依赖。
更好的是: 由于您的服务只运行一次,您还可以将适当的命令放在/etc/rc.local 文件最后一行之前。
关于linux - 服务不会在 Linux Boot 上启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27157485/