Are there any commands I can use to ensure that the NTP service is running and is also responsive?

Are there any commands I can use to ensure that the NTP service is running and is also responsive?

What I am planning to do it have some monitory & remediation scrip to ensure that a couple of services are running and are responsive and especially NTP. And if the service is not running or is not responsive then have it restart the service or check again, and if it still fails for 3 times send an alert email.

Thanks in Advance!


Solution 1:

The answer is version specific, you can use official Ubuntu Server documentation for references.

Ubuntu 14.04 LTS

In 14.04 LTS official documentation recommends to use ntp / ntpdate (see page 49 of Ubuntu 14.04 LTS Server Guide):

Ubuntu uses ntpdate and ntpd.

So expected command would be service ntp status or similar.

Ubuntu 16.04 LTS

In 16.04 LTS official documentation says different (see page. 54 of 16.04 LTS server guide):

Starting with Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp

Ubuntu 16.04 LTS I do not know about chrony, time serving is done with ntpd from ntp package. So here systemctl status ntp.service may be used to check server status.

Ubuntu 18.04 LTS

In 18.04 LTS as Rinzwind already answered chrony is used (see page. 56 of 18.04 LTS server guide).

I expect that systemctl restart chrony.service may be used for status check.