Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Background:

First off I must say that I am not very knowledgeable when it comes to linux, but I played with it enough over the past year to be semi-comfortable with it. I am renting a dedicated web server which is running centos with xen virtualization that has centos installed on the vm. I do not have access to the parent server, I can only manipulate the vm, of which I have full control. Everything is setup exactly as I want it except for the time/timezone. I am running a php/mysql website and I need the timezone to be set to UTC or GMT because I am doing calculations in the website to figure out proper time/timezone based on a users selected city.

What I know:

  • I am able to properly set the timezone by using the following command:

    sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
    
  • Once this command is run, I can use the 'date' command and it will show me the proper date/time/timezone. At this time if I look at the time in a php script, it will not be the right date/time/timezone. It took me quite a while to figure out that to get php to see the timezone change, I had to reboot the whole server, and only then will the timezone be set properly on my website (I believe at one point I tried only resetting the apache service and that didn't help).

  • I am not sure if there is some sort of trigger whether time based or not, but sometime after a week or so, the timezone is reset to whatever I specify in my whm install under "Server Configuration" > "Server Time". This reset happens seemingly automatically and without warning. I just notice that the time on my website is off by hours and the timezone is not UTC any longer. Unfortunately utc or gmt timezone are not valid options in the whm configuration even though I have read that they used to be at some point. What is interesting to me is that somehow the time and timezone are being reset and noticed by php without a reboot.

  • This may be a separate issue, but I will mention it in case it is pertinent. I notice that the time will slowly go out of sync, about 1 minute per day. I did setup ntp as the per instructions here. I can verify that the service is installed correctly and is running, but it does not seem to help to correctly sync the time. I do not want to focus too much on the time sync issue unless it is thought to be part of the main problem of the timezone being reset.

  • One more thing to mention which I believe may be a common side effect of running a virtual copy of linux is that I am unable to update the hardware clock using the following command:

    hwclock --systohc
    
  • The response I get back from this command is:

    "Cannot access the Hardware Clock via any known method.
    Use the --debug option to see the details of our search for an access method."
    
  • Also, /etc/sysconfig/clock always has UTC=true set. This doesn't seem to be affected by the timezone reset that happens.

My thoughts:

Although I am able to "fix" this issue by replacing the /etc/localtime file, I need to find a solution that does not require me to reboot my server. I am curious, but I do not necessarily need to find out exactly why my timezone is being reset, as long as I can find a solution that works for me. I spent too much time and energy on this problem already and I just want it fixed, even if it is some kind of hack.

I have a few ideas that I need help with, and I am hoping that those with more knowledge about these things can help me choose the best answer to this issue.

  1. Since I can verify that the timezone value in whm is what the timezone is being changed to, I am wondering what commands whm uses to set the timezone. How can I find out what directory whm is installed to on my server? Maybe it is not recommended but is it possible for me to view and even edit the source files for whm? What I would like to do is find the source for the whm timezone routine. Depending on how it works maybe I can just run the proper command(s) with the UTC timezone and maybe even edit the code to add UTC into the dropdown list. This way, even if the timezone is still being reset, it will just reset back to UTC and it will not affect me.
  2. Since I need to replace the /etc/localtime file to fix this issue every time, it seems feasible that somehow this file is being replaced automatically without my input. A quick and dirty solution might be to chmod the /etc/localtime file somehow so that whatever script is trying to replace this file will be denied? I haven't tried this yet, but I would like to know thoughts on this. This doesn't explain how the time/timezone is properly reflected in php without a reboot (unless a reboot IS actually happening at this same time and I am not privy to it? - Where can I check logs to figure this out?)
  3. This may be going out of the scope of this site, but the last thing I can think of is to somehow set php and mysql time/date/timezone to something else other than the local computer time. I experimented with this a bit earlier but somehow I still wasn't getting the right time that I wanted even though UTC was selected.

Thanks to all who take the time to read and respond to this massive question!

share|improve this question
    
Have you experimented with setting the TZ environment variable? Example... export TZ="US/Pacific" –  Eirik Toft Mar 29 '13 at 21:11
    
I ran across that in my reading earlier but I didn't experiment much with it before. I just set the command: "TZ='UTC'; export TZ" (without quotes) in my $HOME/.bash_profile file and did a reboot. Everything seems to be working ok so far. I would love if this was the solution! –  Joseph Mar 29 '13 at 23:31
    
> Although I am able to "fix" this issue by replacing the /etc/localtime file, I need to find a solution that does not require me to reboot my server. Err... You do not need to reboot the server when you adjust the /etc/localtime file. –  user2369651 Jul 31 '13 at 9:38

2 Answers 2

Use the TZ variable as seen in comments from above.

share|improve this answer
    
Thanks again Eirik! Unfortunately this didn't solve my issue. The timezone eventually is reset back to what I have specified in my WHM timezone setup, which does not include an option for UTC time. I would still love to find a proper answer to this, but for now I can work around it by referencing the date/time from mysql and use UTC_TIMESTAMP() which will calculate UTC time no matter what timezone I'm in. The other time issue I am focusing on can be found here: serverfault.com/questions/507121/… –  Joseph May 12 '13 at 19:20

I discovered that when I ran yum update and tzdata was a package waiting to be updated, it would reset my current time zone to UTC, when I wanted a different time zone for my server.

You also have some dumb options that may work. (please don't downvote, I know they're shameful)

You also could cron this to make sure it's set every minute.

* * * * * ln -sf /usr/share/zoneinfo/UTC /etc/localtime

In my ~/.bashrc file, you could throw in the line for

ln -sf /usr/share/zoneinfo/UTC /etc/localtime

so everytime you login, it will update the time correctly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.