If have a raspberry pi on Raspbian running a home automation server. That server depends upon accurate system time on the raspberry pi. When I have a power outage for a bit of time and then the power is restored, my raspberry pi restarts just fine, but it does not re-establish the proper time. It is configured to use external NTP servers to re-establish its time, but it does not do so properly in the specific case of a power outage. If I just unplug the raspberry pi and then plug it in again to restart it or if I power it down and then restart, it does establish proper system time from the external NTP servers.
My best guess (though this is just a guess) is that when power is restored after a power outage, internet connectivity is not immediately available when the Pi boots, though internet connectivity is just fine minutes later.
How can I make sure my raspberry Pi has the correct system time as soon as power and internet are restored? Note, this problem of inaccurate system time long after internet connectivity has been restored is not a short duration problem. I've seen it last for multiple days before I had to manually reboot the Raspberry Pi to fix it. As this is meant to be an unattended home automation server, I'm trying to fix the need for a manual reboot after power outage.
FYI, I'm not interested in adding a battery powered clock to the Raspberry Pi because I don't want this server to require battery maintenance (it's not in an easily located place and should run completely unattended). I just want it to pull the correct time from an external NTP server whenever internet service is restored. The internet connectivity for the Pi comes from hard-wired ethernet, not WiFi.
Edit: After reading more about ntpd, I'm not convinced that it actually does what I want if there is no network connectivity yet when it is started. Under some conditions, it seems like it may just exit if it finds the time too far off and in other circumstances, it may try to slowly drift the time to correct it which, after a 4 hour power outage, could take days to correct. Neither of those behaviors is desirable. I want a full time correction as soon as it first finds network connectivity and I want it to keep trying to reach its NTP server until the network is established and it can successfully reach it. Not sure whether it does all that. Maybe need an alternative?
FYI, my Raspberry Pi appears to be configured as such (default configuration for Raspbian):
/usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 102:104
-g configures it to accept any time offset upon first contact with the ntp server
-u specifies a user:group to switch to
-p writes the ntpd process to a specific file (so other apps can find it)