Clock in container is always 2 hours ahead
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
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