OpenVZ Forum


Home » General » Support » Clock in container is always 2 hours ahead
Clock in container is always 2 hours ahead [message #46742] Thu, 07 June 2012 18:19 Go to next message
Ikke is currently offline  Ikke
Messages: 1
Registered: June 2012
Junior Member
I've recently got a VPS with OpenVZ. However, no matter what I do in the container the clock is 2 hours ahead. I simply put my /etc/localtime to point to the local timezone (CEST) but my clock is then 2 hours ahead.

If I type date --utc I also get a value for UTC which is two hours ahead.

Finally I made a a small program:

Quote:

#include <sys/time.h>
#include <stdio.h>

int main(void) {
struct timezone tz;
gettimeofday(NULL, &tz);
printf("%d\n", tz.tz_minuteswest);
return 0;
}


It prints '-120' to indicate that the system clock is 120 minutes ahead of UTC... yet the problem is: it isn't! settimeofday doesn't work in the container. So I'm somewhat stuck.

The question now is, how is this handled in OpenVZ? Does this value come from the HW node? In that case my hoster has its settings wrong (?). Or can you actually set this offset somehow in a container without any time setting capabilities?
Re: Clock in container is always 2 hours ahead [message #46752 is a reply to message #46742] Sat, 09 June 2012 00:47 Go to previous message
mustardman is currently offline  mustardman
Messages: 91
Registered: October 2009
Member
Ikke wrote on Thu, 07 June 2012 14:19
I've recently got a VPS with OpenVZ. However, no matter what I do in the container the clock is 2 hours ahead. I simply put my /etc/localtime to point to the local timezone (CEST) but my clock is then 2 hours ahead.

If I type date --utc I also get a value for UTC which is two hours ahead.

Finally I made a a small program:

Quote:

#include <sys/time.h>
#include <stdio.h>

int main(void) {
struct timezone tz;
gettimeofday(NULL, &tz);
printf("%d\n", tz.tz_minuteswest);
return 0;
}


It prints '-120' to indicate that the system clock is 120 minutes ahead of UTC... yet the problem is: it isn't! settimeofday doesn't work in the container. So I'm somewhat stuck.

The question now is, how is this handled in OpenVZ? Does this value come from the HW node? In that case my hoster has its settings wrong (?). Or can you actually set this offset somehow in a container without any time setting capabilities?


Containers get all their clock info from the Node. So you cannot change the time on a VPS and ntp is useless. You can only change the timezone. So if your node time is wrong your VPS time will be wrong.

To set VPS timezone first get your timezone here:
http://www.php.net/manual/en/timezones.php

Then set it with this command as root changing the relevant part for your particular timezone:
ln -sf /usr/share/zoneinfo/America/Vancouver /etc/localtime

If it's still wrong after you do that then your node time is wrong. If you have root access to the node set it as follows:

yum install ntp
chkconfig ntpd on
service ntpd start


Using this link.
http://www.linuxsa.org.au/tips/time.html

First set system time:
date 060818002012

then set hardware clock (so time is still correct after reboot):
/sbin/hwclock --systohc



[Updated on: Sat, 09 June 2012 00:58]

Report message to a moderator

Previous Topic: CPUUNITS / CPULIMIT
Next Topic: ploop yum update problem
Goto Forum:
  


Current Time: Sat Jul 27 22:35:27 GMT 2024

Total time taken to generate the page: 0.02690 seconds