I've worked out a solution that doesn't need any other libraries or scripts.
Scripts in the directory, /etc/network/if-up.d/
will be execute when a network interface is brought up. Here is a reference.
Therefore this ensures that my NTP script gets executed once the system has configured DHCP client and thereby to the internet. This the correct behaviour that avoids the name resolution problems that I ran into.
I've put together this simple script (and chmod +x
it!) It checks that the network method is dhcp, and subsquently initializes my NTP daemon process.
#! /bin/sh
# ntp time-sync manager python daemon starter script
set -e
# ... Some Stuff Omitted Here ...
if [ "$METHOD" = dhcp ]; then
echo -n "Starting $DESC..."
start-stop-daemon --start --verbose --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
echo "METHOD: $METHOD"
echo "IFACE: $IFACE"
fi
echo "Exiting if-up.d/ntp_manager"
exit 0
Here is a dump of what happens on the system. Please note the line: run-parts /etc/network/if-up.d
being executed right after an IP has been resolved.
Reconfiguring network interfaces eth0 with DHCP... cat: can't open '/var/run/udh
cpc.eth0.pid': No such file or directory
run-parts /etc/network/if-pre-up.d
ifconfig eth0 up
udhcpc -R -b -p /var/run/udhcpc.eth0.pid -i eth0
udhcpc (v1.13.2) started
Sending discover...
Sending discover...
Sending select for 192.168.1.145...
Lease of 192.168.1.145 obtained, lease time 86400
adding dns 192.168.1.1
run-parts /etc/network/if-up.d
Starting NTP Time Manager...Daemon PID 1059
Redirecting serivice startup output to /home/root/Connect/log/ntp_manager_daemon.log
METHOD: dhcp
IFACE: eth0
Exiting if-up.d/ntp_manager
Anyway, I thought that this is a adequately simple and robust solution to the problem. Hopefully it will help someone else in the future.