I have a few Linux devices (without TOY chips, so they completely rely on ntp) which may boot without access to Internet (the link to the switch is up). The ntp
service will start but obviously no peers will be contacted. I then end up with an ntp
service which is running but not synchronizing with any peers (ntpq -p
gives an .INIT.
status)
The problem is that this does change when connection to Internet is established.
If the connection is available at boot time then everything works fine. Idem if I manually issue a service ntp restart
(ntp
connects to the peers and time is correctly synchronized).
Shouldn't ntp try to reconnect at regular intervals?
- if yes: is this something I am expected to configure (I did not see anything in the config)
- if not: what would be a good way to handle the service restart, or service start delay (I could assume that connectivity to Internet will be back n minutes after bootup)
Note: It looks like from the docs that the maximum pool time (which I understand is the max time ntp will try to connect to peers before giving up?) is 1024 seconds = 17 minutes, which is way more than the time needed to establish Internet access (about 2 to 5 minutes, worst case)
You might have been bitten by an edge case for ntpd:
IIRC ntpd versions < 4.2.4p3 removed any servers from it's synchronization list that couldn't be reached at some point. This is of course quite bad in this case, as ntpd might very well 'exhaust' the list of its peers before gaining internet connectivity.
One could/can set the
dynamic
option for these servers inntp.conf
to work around this issue.With newer versions, this shouldn't be necessary anymore (also, the dynamic option was retired at some point, which caused minor gripes for some people with ntp's complaining all of a sudden).
So, you can either upgrade your ntpd, or set the option.
As a third option, you can create a proper dependency in your init system; making ntpd to rely on an established internet connection (not just network). The upshot would be that you can reuse this with other services as well.
Debian OpenNTPD packaging automatically restarts it if an interface comes up. This is common.
Also, you will (usually) need to sync one-shot before starting xntpd anyway, so I suggest this is the way to go.