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!
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):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):
Ubuntu 16.04 LTS I do not know about
chrony
, time serving is done withntpd
fromntp
package. So heresystemctl 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.chrony is the default for Ubuntu as of 18.04
A simple
will return with a error number notice and how many sources are active, how many are inactive. Easy to code something around it; like a script or even a service.
It also supports logging (default to syslog) by editing
/etc/crony/chrony.conf
.Each of the words after "log" will trigger its own log in `/var/log/crony/.
So that could also be used as a track&trace type of thing where you scan the log and trigger a mail on certain events or conditions.
While the first three seem to show that Chrony is working, the last command shows that there is still a problem:
$
chronyc activity
$
chronyc sources
$
chronyc sourcestats
$
timedatectl