NTP not syncing, only syncs on service restart

My ubuntu 11.10 server has been sitting there quite happily for the last 3 - 4 months, then suddenly the time started going out of sync by one hour. I'm not sure why, nothing has changed re the configuration of the server, i read it can be down to system resource useage.

Anyway to counteract this Ive seen a lot of people recommend installing NTP and the NTP daemon (ntpd) so that the time will be synced automatically. i have installed NTPD and it seems to work for a day, then suddenly stops working.

after around a day when i do

ntpq -q

to list the peers connected, i get the error

ntpq: read: Connection refused

if i then try and restart the service

sudo service ntp restart

i get the following message

* Stopping NTP server ntpd                                                  
start-stop-daemon: warning: failed to kill 26915: No such process                                                                      
* Starting NTP server ntpd 

once i have done this within about 5 mins the time is synced again. If i restart the service again i do not get the above message i just get

 * Stopping NTP server ntpd                                             
 * Starting NTP server ntpd 

and if i try ntpq -p again i get

         remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 noc.be.it2go.eu 193.190.230.66   2 u   43   64    3   10.819  -353184   0.183
 panoramix.linoc 193.67.79.202    2 u   41   64    3   24.647  -353186   0.178
 nsb.lds.net.ua  160.45.10.8      2 u   39   64    3   68.545  -353186   0.001
 europium.canoni 193.79.237.14    2 u   38   64    3    1.222  -353186   0.096

its almost like restarting the service kicks it in to action, yet around a day later i will have to do the same thing all over again as the time will have stopped syncing.

here is what is in the logfile

13 Feb 11:18:38 ntpd[27108]: ntpd exiting on signal 15
14 Feb 11:44:30 ntpd[1872]: ntpd exiting on signal 15
15 Feb 10:16:25 ntpd[26869]: ntpd exiting on signal 15
16 Feb 05:26:41 ntpd[26915]: 158.37.91.134 interface xxx.xxx.xxx.xxx -> xxx.xxx.xxx.xxx
16 Feb 05:51:41 ntpd[26915]: 158.37.91.134 interface xxx.xxx.xxx.xxx -> xxx.xxx.xxx.xxx
16 Feb 10:14:30 ntpd[23793]: ntpd exiting on signal 15

in the log file above, at 13 Feb 11:18:38 the following is what appears in /var/log/syslog

Feb 13 11:18:40 serverx ntpd[29251]: ntpd [email protected] Fri Jun 17 06:06:35 UTC 2011 (1)
Feb 13 11:18:40 serverx ntpd[29252]: proto: precision = 0.118 usec
Feb 13 11:18:40 serverx ntpd[29252]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
Feb 13 11:18:40 serverx ntpd[29252]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen and drop on 1 v6wildcard :: UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 2 lo 127.0.0.1 UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 3 eth0 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 4 eth0:1 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 5 eth0:2 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 6 eth0:3 xx.xxx.xxx.xxxUDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 7 eth0:4 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 8 eth0:5 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 9 eth0:6 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 10 eth0:7 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 11 eth0:8 xx.xxx.xxx.xxx UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 12 eth0 fe80::250:56ff:fea1:41 UDP 123
Feb 13 11:18:40 serverx ntpd[29252]: Listen normally on 13 lo ::1 UDP 123

xxx.xxx.xxx.xxx = ip address

any ideas why this is happening?


Solution 1:

I suspect your clock is too far out for ntpd to be able to drift it back to the correct time. NTP only works if the clock is within +/- 5 mins of the correct time.

Start it with the -g flag to force an ntpdate-style one-off correction. I'm not very familiar with Ubuntu but I suspect there is a defaults/config file for ntpd in /etc somewhere where you can add this flag.