1753663 Members
5899 Online
108798 Solutions
New Discussion юеВ

NTP and Cron

 
SOLVED
Go to solution

NTP and Cron

Is there anything magic that NTP (xntpd) does when it resets time backwards? Could it not cause a cron job to kick in twice ? For instance at 12:00:00 cron kicks of a job "A", and at 12:00:01 xntpd sets the time back 2.0 seconds.

When you change the system time with "date" the system warns you - I'm assuming for that very reason.

14 REPLIES 14
Sanjay_6
Honored Contributor

Re: NTP and Cron

Hi Elliot,

I guess what you say is correct. Cron may repeat the sdame job, if the time resets backward.

Regds
harry d brown jr
Honored Contributor

Re: NTP and Cron

As long as ntp is not "stepping" (doing an immediate time change), then NO, the same cron will not start twice. You would need to add the "-x" option to xntpd.

man pages of xntpd:

The good news is that NTP can be forced to never make a STEP, but instead SLEW the clock to drive the offset to zero. This is accomplished with the -x option on the command line. This effectively removes the middle operating regime. You won't get millisecond (or microsecond) precision with this method, but you probably can't get that over a WAN anyway.

It is important to note that SLEWING is a cover-up for a more fundamental problem (poor connection to the timesource), and it does not solve this problem. SLEWING is not recommended by HP because it causes reduced accuracy and stability, and it leads to anamolous behavior that can be quite confusing.

live free or die
harry

Live Free or Die
John Payne_2
Honored Contributor

Re: NTP and Cron

NTP is a very basic protocal. It does not stop any services or anything. If the time gets changed back 30 minutes, you have the same problem. It just changes the time.

Are you running a driftfile? The driftfile will tell you the last correction and the timestamp. Then next time it happens, you can look at the driftfile and see that the time changed overlapping the cron job's time.

Format is an entry like this:

driftfile /etc/ntp.drift

Add a the ntp.drift file with an initial entry of '1' in the file...

John
Spoon!!!!
Craig Rants
Honored Contributor

Re: NTP and Cron

Elliot,
I am sure that it would kick off the job twice.
You may want to update your system time more often if you clock is fast and an update has to move the time back in big chunks.

C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Bernie Vande Griend
Respected Contributor

Re: NTP and Cron

It is definitely possible for this to occur, unless the slewing option is used that Harry mentioned.

Because of that, we do not run xntpd, but instead use ntpdate to sync the time immediately. We do this at boot time and also have a cron job that does it twice a day. That way we can choose a time where setting the clock back or forward a few minutes does not have an impact.
I think it depends on how time sensitive your application and cron jobs are and the impact of them running more than once if the time was set back.
Ye who thinks he has a lot to say, probably shouldn't.
Patrick Wallek
Honored Contributor

Re: NTP and Cron

I suppose it is possible for that to happen.

But, if you are running xntpd and the clock on your server is functioning fairly normally, xntpd should never have adjust the time that much.

I have been running xntpd on production servers for at least 2 years and I have never had anything like that happen.
James R. Ferguson
Acclaimed Contributor

Re: NTP and Cron

Hi Elliott:

Several comments.

First, 'xntpd' will adjust a server's time if the difference between it and its source time is greater than 1000 seconds. This prevents some measure of time insanity.

Second, time adjustments are made gradually in small increments. This too, lessens the kind of behavior about which you worry.

Thirdly, remember that the granularity of 'cron' jobs is one minute. This too, limits the periods of union for the behavior about which you worry.

Lastly, one a server's clock is synchronized, time is very stable. Afterall, that's the reason to run 'xntp' in the first place; to provide continuous, very small adjustments as necessary.

Regards!

...JRF...

Re: NTP and Cron

Harry D. Brown,

Even if the system "slews" a microsecond and doesn't "step", couldn't a cron job kick off twice ?

Re: NTP and Cron

James,

You mention in your second point that time adjustments are made gradually, are you referring to slewing like Harry. And where is this "-x" option in the manpages ?

The system that I was testing "stepped" the time back 2 seconds, something that I don't want to happen. I think "slewing" sounds like a better idea for me.