NTP not syncing, only syncs on service restart

27,464

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.

Share:
27,464

Related videos on Youtube

Michael Barrett
Author by

Michael Barrett

Updated on September 18, 2022

Comments

  • Michael Barrett
    Michael Barrett almost 2 years

    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?

    • adaptr
      adaptr over 12 years
      What does the log say ?
    • Michael Barrett
      Michael Barrett over 12 years
      Hi im not sure where it logs too? ive not set a logfile in my ntpd.conf
    • adaptr
      adaptr over 12 years
      Just add logfile /var/log/ntp.log to ntp.conf and restart ntpd.
    • Michael Barrett
      Michael Barrett over 12 years
      it turns out i did have logging turned on. i have added the logfile contents for the last few days to the original post
    • stew
      stew over 12 years
      can you tell from /var/log/syslog what else is happening around those times you are getting "ntpd exiting on signal 15"? is the machine rebooting/halting?
    • Michael Barrett
      Michael Barrett over 12 years
      i have added the output of /var/log/syslog at one of the events to the original post
    • Arpith
      Arpith over 11 years
      Could you add the contents of /etc/ntp.conf file here?
    • eskatos
      eskatos almost 9 years
      Very same issue here, any idea?
  • James O'Gorman
    James O'Gorman over 12 years
    I wasn't quite sure based on your question whether it was actually syncing before (as the offset in your ntpq output was very far off). I would still recommend you start ntpd with -g and then see if it continues to die.
  • Michael Barrett
    Michael Barrett over 12 years
    hey when i look at the process list it looks like is already started with the -g flag: /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 109:116
  • 3bdalla
    3bdalla about 6 years
    Seems like this did it. I fixed the 2 hours time drift and up until now, no signal 15 log found.
  • U. Windl
    U. Windl over 2 years
    @MichaelBarrett Some "ntp" services actually are two-step: First sync the time quick and dirty, and then run ntpd. Maybe that's why the initial run fixes the offset.