Ubuntu – ntp service on linux, not running after reboot

ntpUbuntu

The time on my server has been synced properly for a few weeks now, then we rebooted the server last week, today it's 10 minutes off. I did "sudo ntpdate ntp.ubuntu.com" and got:

4 Oct 14:22:08 ntpdate[17734]: the NTP socket is in use, exiting

I'm guessing that means it's already running… but why wasn't it running when I rebooted my server?

update

/etc/ntp.conf

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
server ntp.ubuntu.com
server 0.north-america.pool.ntp.org
server 1.north-america.pool.ntp.org
server 2.north-america.pool.ntp.org
server 3.north-america.pool.ntp.org
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1

Best Answer

Are you sure ntpd wasn't running when the box rebooted? Check your syslog'ed boot logs and see whether it started when the box booted.

Also, remember that if the time is off by too much, ntpd will assume there's a possible problem with your time source, and will not change the time. By default, that happens if the time reported from the external time server is more than 1000 seconds off from the local time. There's a couple of things I've run into over the years (such as CMOS battery dying) that can cause the local machine time to skew greatly at a reboot.

Double check your /etc/ntp.conf config, make sure it's accurate (time servers are reachable, etc). Then try restarting ntpd, and watch the logs while you're doing it. See if everything looks good there. Then go back through your system logs and find all the ntpd related logs. Look for errors, problems, etc. Make sure it's starting on bootup.

In cases like this, logs are usually going to be your best source of information for troubleshooting.

If the time is off by more than 1000 seconds, and you need to reset it, you'll want to first stop ntpd, then run ntpdate to reset the time, then restart ntpd. The following commands will do it:

sudo /etc/init.d/ntp stop
sudo ntpdate 0.north-america.pool.ntp.org
sudo /etc/init.d/ntp start

If you are having problems where the time is skewing badly on every reboot, it may be worth scripting ntpdate to run before ntpd is started on each boot. That should help get the time reset to something manageable before ntpd handles it.