How to update date/time without shutting down the NTP daemon

ntpntpd

I would like to have a one-liner for updating the date via NTP getting the NTP-servers from the /etc/ntp.conf file. Especially because a manual command does not always work, because of firewall rules, not all servers in /etc/ntpd.conf being reachable.

service ntpd stop, ntpdate ntp1host, service ntpd start 

This would be the normal way to go. Is there a command that will allow me to force-update time via NTP without shutting down the daemon?

Best Answer

This is a really, really bad idea. Let me (try to) explain.

The ntp daemon expects to control the system clock. When it starts it will jump the clock if permitted, so that the time approximates that offered by its remote time servers. Thereafter, it regularly compares local time generated by the system clock to that offered remotely, and tweaks the local clock faster or slower to keep it synchronised.

There are two levels of synchronisation:

  1. Keeping the clock accurate when compared to remote time servers
  2. Ensuring that over longer time periods the local clock can be sufficiently disciplined that even without Internet connectivity it will continue to keep approximately accurate time

If you jump the clock, or introduce a new slew by setting the clock (whether with ntpdate or manually) it will upset the long-term calculations for #2 and can potentially cause the clock to be disciplined so badly that it will lose or gain visibly significant time compared to reality. If this happens then the only real solution is to shut down ntp, delete the reference adjustment file, and hard reboot the server. Really.

If you really still want to proceed, you could try this:

ntpdate -u $(awk '$1=="server" {print $2}' /etc/ntp.conf)

But I do not recommend it under any circumstances while ntp is still running.

Related Question