Sync network time before starting DHCP service
Hi all,
I'm writing an application that runs on a Raspberry Pi (Arch), which has no realtime clock. I'm having an issue using the Pi as a DHCP server. On boot, the Pi always thinks it's February 1, 2017. Shortly thereafter, the systemd-timesyncd daemon starts, and it sets the clock to the last time it knew about before its last shutdown. So, if I had the machine powered down for the weekend, the system clock would be a couple days behind. Not long after that, systemd-timesyncd syncs to an NTP server to actually set the system clock.
The problem is that the Pi's DHCP server can start independently of these things, and if it creates a DHCP lease when the Pi's time is behind by a few days (or all the way back to February) and then the time gets updated, the DHCP leases all expire.
In order to fix this, I've added an override to the DHCP systemd unit such that it starts AFTER time-sync.target. Upon doing this, I found out that systemd-timesyncd considers itself "started" after restoring the time from the last shutdown. In other words, if the Pi boots up after a weekend, it may still start systemd-timesyncd, set the time to two days ago, start DHCP, issue a DHCP lease, do an NTP sync, and then all the leases expire immediately.
What I want is to wait for the sync to an NTP server to actually occur after booting, and then start the DHCP server after that. Is anyone aware of a way to do this, or at the very least, a hacky way to make it work?
Thanks!
|