简体   繁体   中英

Service will not start on Linux Boot

Good afternoon,

I have a problem inserting a startup service using update-rc.d on Debian (on Raspberry Pi)

The command I am running to insert the service is:

sudo update-rc.d setdatetime defaults

The Service itself (file /etc/init.d/setdatetime) with chmod permissions set to 755 is shown below:

#!/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

I can run the service without a problem using

sudo /etc/init.d/setdatetime start

ls /etc/rc*.d lists the service as installed:

But the service does not run on boot! What am I missing???

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

It looks as if there's something wrong with your dependencies. You have to make sure that the syslog service has started before your setdatetime service.

Obviously if you start your service manually the computer has already finished booting so syslog is running therefore your service works.

You can also try to remove the dependency on syslog.

Even better: Since your service runs only once you can also put the appropriate command in /etc/rc.local just before the last line in that file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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