Dominic Cleal's Blog

Tue Mar 9 14:42:34 GMT 2010

permalink Cron, local time and daylight savings (DST)

Like many others, I prefer servers to run in UTC rather than the local time zone. Particularly with the Java services we run, I find that some logs always remain in UTC, while others observe the daylight savings (DST) of the local time zone (probably due to the multitude of logging APIs).

Sticking with UTC makes everything unambiguous, but can cause problems when scheduling crons that are dependent on the local time. Rather than change systems to run in local time, cron jobs that are linked to local time are now scheduled an hour earlier and run a script that sleeps if the local time hasn't yet been reached.

A job that needs in run at 7am UK time is now scheduled for 6am via cron. In the summer while the UK's observing DST, the script can be run at 6am UTC ("spring forwards"). Once DST is over, a job scheduled at 6am UTC will need to wait an hour before starting so it's 7am UK time and 7am UTC.

This is fairly trivial in shell script, see my cron_tz.sh. Once I'd written this, I discovered a Python version that does pretty much the same thing.

Now my crontab simply looks like this:

15 06 * * *   cron_tz.sh Europe/London 7 /my/command

Interestingly, on the same ServerFault question, SAnnukka mentions that Cfengine has a way of automating this with calendars. Could the same be done with Puppet? Perhaps a function that takes a time in a given time zone and converts it to UTC (or another TZ) that could then be used for a cron resource? If Puppet's being run regularly anyway, then the cron jobs would be quickly updated and kept to the correct time.

Archives


Comments for this entry are now closed.