====== daemon-startup-watchdog.sh ====== This is a simple script is a bit of a hack best called from /etc/rc.local on a Raspberry Pi (or other Debian based distro) during startup. It works around the fact that the Pi does not have an on-board real-time clock and ensures that network services come up after the network stack is stable. #!/bin/bash # # daemon-startup-watchdog.sh - a script to work around Raspberry Pi limits # # Copyright (c) 2015 Gabriel M. O'Brien # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # until fping -qc 3 8.8.8.8 > /dev/null 2>&1; do echo "Waiting for network..." done # set time from NTP server to work around lack of RTC on Pi ntpservers=`grep '^server' /etc/ntp.conf | awk '{ print $2 }'` echo "Forcing restart of ntp and setting RTC time" service ntp stop # check all servers in config until one returns valid data for s in $ntpservers; do ntpdate -s $s [ "$?" -eq "0" ] && break done service ntp start # restart other daemons for daemon in isc-dhcp-server bind9; do echo "Forcing restart of $daemon" service $daemon restart done