The ntpdate program was deprecated years ago. I am trying to transition old code from ntpdate to standalone ntpd. The goal is to rely on the ntp service (run with -g) to discipline the clock, but to allow a scripted forced time sync if the clock is significantly wrong (due, perhaps, to prolonged but temporary inability of the ntp daemon to access the time servers) and the daemon is unable to fix it.
service ntp stop
ntpd -gq
service ntp start
We are currently using ntpdate for that purpose, with no issues. We expect "ntpd -gq" to synch the time regardless of the size of time discrepancy -- but it does not work in ub14.04.4 LTS. It reports a time slew of 0 seconds, and exits without error.
The exact same approach works as expected in ub10.04 LTS.
The us of sntp is not an option in the scope of our application. I don't know what to do, other than go back to ntpdate.
Helpful advice will be appreciated IMMENSELY. Thank you.
What follows is information about my ub14 and ub10 systems, and logs of my little test, which can be summarized in two simple steps:
- Push the time back an hour or so.
- Try to fix it with ntpd -gq.
(Sorry if TMI. Better too much than not enough, right?)
`#======================`
`# UB14 VERSION DETAILS`
`#======================`
`root@goncharova14:~# lsb_release -d ; uname -a`
`Description: Ubuntu 14.04.4 LTS`
`Linux goncharova14 4.2.0-27-generic #32~14.04.1-Ubuntu SMP Fri Jan 22 15:32:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux`
`#--------------------`
`# NTP QUERY of PEERS`
`#--------------------`
`root@goncharova14:~# ntpq -p`
` remote refid st t when poll reach delay offset jitter`
`==============================================================================`
` golem.canonical 193.79.237.14 2 u 2 64 7 81.242 3459840 2446479`
`*LOCAL(0) .LOCL. 13 l 3 64 7 0.000 0.000 0.000`
`grep -v -e ^$ -e ^# /etc/ntp.conf /etc/default/ntp`
`#---------------------------`
`# NTP.CONF and NTP DEFAULTS`
`#---------------------------`
`/etc/ntp.conf:`
`server ntp.ubuntu.com prefer`
`server 127.127.1.0`
`fudge 127.127.1.0 stratum 13`
`driftfile /var/lib/ntp/ntp.drift`
`statistics loopstats peerstats clockstats`
`filegen loopstats file loopstats type day enable`
`filegen peerstats file peerstats type day enable`
`filegen clockstats file clockstats type day enable`
`restrict -4 default kod notrap nomodify nopeer noquery`
`restrict -6 default kod notrap nomodify nopeer noquery`
`restrict 127.0.0.1`
`restrict ::1`
`/etc/default/ntp:`
`NTPD_OPTS='-g'`
`#---------------------------------`
`# PUSH THE TIME BACK && TEST SYNC`
`#---------------------------------`
`root@goncharova14:~# date; date 02272000`
`Mon Feb 27 20:57:39 EST 2017`
`Mon Feb 27 20:00:00 EST 2017`
`root@goncharova14:~# service ntp stop && (ntpd -gq ; echo "Status: $?"; date ; echo '---SYSLOG---' ; tail -n 15 /var/log/syslog; echo '---endLOG---' ; date)`
` * Stopping NTP server ntpd [ OK ]`
`ntpd: time slew +0.000000s`
`Status: 0`
`Mon Feb 27 20:08:44 EST 2017`
`---SYSLOG---`
`Feb 27 20:07:51 goncharova14 ntpd[574]: peers refreshed`
`Feb 27 20:07:51 goncharova14 ntpd[574]: Listening on routing socket on fd #22 for interface updates`
`Feb 27 20:07:53 goncharova14 ntpd[574]: ntpd: time slew +0.000000 s`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: ntpd [email protected] Thu Feb 11 18:30:40 UTC 2016 (1)`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: proto: precision = 0.160 usec`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen and drop on 1 v6wildcard :: UDP 123`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 2 lo 127.0.0.1 UDP 123`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 3 eth0 10.160.74.140 UDP 123`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 4 lo ::1 UDP 123`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 5 eth0 fe80::a00:27ff:fecd:8c80 UDP 123`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: peers refreshed`
`Feb 27 20:08:42 goncharova14 ntpd[1566]: Listening on routing socket on fd #22 for interface updates`
`Feb 27 20:08:44 goncharova14 ntpd[1566]: ntpd: time slew +0.000000 s`
`---endLOG---`
`Mon Feb 27 20:08:44 EST 2017`
`#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++`
`# THE SAME APPROACH WORKS AS EXPECTED IN UB10. Commands are identical. Conf files are identical. +`
`#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++`
`#======================`
`# UB10 VERSION DETAILS`
`#======================`
`root@goncharova10:~# lsb_release -d ; uname -a ; echo`
`Description: Ubuntu 10.04 LTS`
`Linux goncharova10 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux`
`#--------------------`
`# NTP QUERY of PEERS`
`#--------------------`
`root@goncharova10:~# ntpq -p ; echo`
` remote refid st t when poll reach delay offset jitter`
`==============================================================================`
`*chilipepper.can 17.253.34.125 2 u 238 512 377 78.643 -2.038 1.020`
` LOCAL(0) .LOCL. 13 l 22 64 377 0.000 0.000 0.001`
`#---------------------------`
`# NTP.CONF and NTP DEFAULTS`
`#---------------------------`
`root@goncharova10:~# grep -v -e ^$ -e ^# /etc/ntp.conf /etc/default/ntp`
`/etc/ntp.conf:`
`server ntp.ubuntu.com prefer`
`server 127.127.1.0`
`fudge 127.127.1.0 stratum 13`
`driftfile /var/lib/ntp/ntp.drift`
`statistics loopstats peerstats clockstats`
`filegen loopstats file loopstats type day enable`
`filegen peerstats file peerstats type day enable`
`filegen clockstats file clockstats type day enable`
`restrict -4 default kod notrap nomodify nopeer noquery`
`restrict -6 default kod notrap nomodify nopeer noquery`
`restrict 127.0.0.1`
`restrict ::1`
`/etc/default/ntp:`
`NTPD_OPTS='-g'`
`#---------------------------------`
`# PUSH THE TIME BACK && TEST SYNC`
`#---------------------------------`
`root@goncharova10:~# date; date 02272000`
`Mon Feb 27 21:10:03 EST 2017`
`Mon Feb 27 20:00:00 EST 2017`
`root@goncharova10:~# service ntp stop && (ntpd -gq ; echo "Status: $?"; date ; echo '---SYSLOG---' ; tail -n 15 /var/log/syslog; echo '---endLOG---' ; date)`
` * Stopping NTP server ntpd [ OK ]`
`ntpd: time set +4203.430466s`
`Status: 0`
`Mon Feb 27 21:10:12 EST 2017`
`---SYSLOG---`
`Feb 27 20:00:00 goncharova10 ntpd[25264]: ntpd exiting on signal 15`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: ntpd [email protected] Sat Dec 20 11:53:03 UTC 2014 (1)`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: precision = 1.000 usec`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #0 wildcard, 0.0.0.0#123 Disabled`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #1 wildcard, ::#123 Disabled`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #2 lo, 127.0.0.1#123 Enabled`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #3 eth0, 10.160.74.40#123 Enabled`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #4 lo, ::1#123 Enabled`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #5 eth0, fe80::20c:29ff:feeb:5b07#123 Enabled`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: kernel time sync status 2040`
`Feb 27 20:00:00 goncharova10 ntpd[31309]: frequency initialized -14.511 PPM from /var/lib/ntp/ntp.drift`
`Feb 27 21:10:12 goncharova10 ntpd[31309]: synchronized to 91.189.89.198, stratum 2`
`Feb 27 21:10:12 goncharova10 ntpd[31309]: time reset +4203.430466 s`
`---endLOG---`
`Mon Feb 27 21:10:12 EST 2017`