Monday, April 28, 2014

Correcting incorrect time-offset on an Ubuntu server

Here is a quick post on a solution to an issue that affected my Ubuntu server. I noticed that me cron jobs were getting executed about a hour or two later than they were set to run at. Logging into the server and running the command "date" confirmed what I easily suspected: that the clock was off by 1h 45min.

Running the command:
$sudo ntpdate
to update the clock returned the error
ntpdate - no servers can be used, exiting.
So then I ran the command
$sudo ntpdate 0.uk.pool.ntp.org"
which returned the following:
28 Apr 14:28:40 ntpdate[23357]: step time server 109.123.121.128 offset 2311.837165 sec.
Great, I thought, problem solved. Unfortunately not. When I ran the command "date" again, the server was still off by an hour:
$date
Mon Apr 28 14:33:45 UTC 2014.
It was actually 15.33. Suspecting an issue with Daylight Savings Time (DST) was the issue, or to be more specific, that the server wasnt using it, I looked to enable it. A quick Google informed me that an Ubuntu installation gets its DST settings from knowledge of its physical location, and the time server that it is conencted to. I had already configured it to use a suitable time server with the command "$ sudo ntpdate 0.uk.pool.ntp.org", so I had to reconfigure its location from the terminal. To do this, run the following command:
$sudo dpkg-reconfigure tzdata
You will be presented with a terminal GUI. Select your locality. Then when completed, you will be greeted by the updated time: 
Current default time zone: 'Europe/Dublin'
Local time is now:      Mon Apr 28 15:33:45 IST 2014. Universal Time is now:  Mon Apr 28 14:33:45 UTC 2014.
Running "date" now confirms the corrected time:
$date
Mon Apr 28 15:33:56 IST 2014

Problem solved! 


1 comment:

  1. Ubuntu server 15 still doing exhibiting this behavior. This fix seems only temporary for me at least.

    ReplyDelete