Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
Can you post your ntp.conf (minus comments, try 'egrep -v '^#|^$' /etc/ntp.conf')? –  Christopher Cashell Oct 4 '10 at 18:38

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
If this is a virtual machine the same can happen and if it goes off by more than 1000 seconds it won't sync anymore. –  Jure1873 Oct 4 '10 at 18:49
    
How do I restart it? init.d doesn't appear to have control over that. And if it's off by 1000 seconds and isn't resyncing, how do you fix it? –  Webnet Oct 4 '10 at 18:54
    
It should be restartable from /etc/init.d. Run: 'sudo /etc/init.d/ntp restart'. Also, Jure1873 makes a good point, if this is a virtual machine guest, you may not be able to affect the time at all. In many cases, that can only be changed on the VM host. If the time is off, you'll want to stop ntpd, then run ntpdate, then start it again. I'll update the answer with that information, too. –  Christopher Cashell Oct 4 '10 at 19:05
    
Awesome, that got my time updated. How can I be sure that the time syncs correctly when the machine is booted up? –  Webnet Oct 5 '10 at 12:50
    
First, I would try to verify whether it's a definite problem. If your box is losing time on every reboot, it might be a symptom of a bigger issue. Then, there's two ways you can do this. The "better" way, and the "good enough" way. The "better" way would be to write an init script that run ntpdate, and configure it to run before ntpd. The "good enough" way would be to add a line to the /etc/init.d/ntp script, near the beginning, that runs ntpdate before starting ntpd. Adding a line like: ntpdate $(awk '/^server/ {print $2; exit}' /etc/ntp.conf) should do it. –  Christopher Cashell Oct 5 '10 at 19:47

It is possible that ntp is running, but it has given up on your os clock as too unreliable.

Use the command

ntpq -np

...to see what ntp thinks it is doing.

share|improve this answer

Virtual Machine? Timekeeping is quite difficult.

This document from VMWare was very helpful in my situation

http://www.vmware.com/files/pdf/Timekeeping-In-VirtualMachines.pdf

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.