3 Answers
3

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:

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.

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.
–
Jure1873Oct 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?
–
WebnetOct 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 CashellOct 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?
–
WebnetOct 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 CashellOct 5 '10 at 19:47