User Guide - Changing the Timezone on your VPS


Applicable Plans: All General VPS plans

Changing the Time Zone

This User Guide explains how to change the default time zone of your VPS, as well as how to change the timezone for Tomcat, Java, JBoss, Mysql. and PostgreSQL.

By default, the physical servers where your Virtual Private Servers (VPS) are located are set to EST/EDT, which is GMT -5 or GMT -4, depending on the time of year. 
The VPSs get their time from the physical server. The physical servers use ntpd (network time protocol daemon) to sync to a time server on the eApps network, which in turn syncs to a Stratum One time server located at the Georgia Institute of Technology.

NOTE – All of the following must be done from the command line of the VPS while logged in via SSH as the root user. Please see our SSH User Guide for more information if necessary. The ability to edit files in a Linux text editor such as vi is required to make the timezone changes for Tomcat, JBoss, Java, MySQL and PostgreSQL. If this is not something you are able to do, please contact eApps support for assistance.

Changing the time zone for the VPS

Due to the way the Virtuozzo software works, you cannot run ntpd on your VPS. However, you can change the localtime setting to reflect the actual time where you are located.

The timezone files are located in /usr/share/zoneinfo. There are several hundred choices available. Once you have found the correct timezone file for your location, follow these steps:


Check the current date so that you can verify that your change worked. In this example the timezone is being changed from EDT to PDT, which are three hours apart. You will need to substitute your specific timezone.
[root@example]# cd /etc
[root@example etc]# date
Tue Jun  9 10:47:55 EDT 2009


Backup the current localtime file
[root@example etc]# mv localtime{,.bck}


Link the timezone file you wish to use to localtime
[root@example etc]# ln -s /usr/share/zoneinfo/US/Pacific /etc/localtime


Check the date again to verify the change
[root@example etc]# date
Tue Jun  9 07:51:02 PDT 2009

Now the VPS reports the new timezone of PDT.

Changing the timezone for Tomcat , JBoss or Java

By default, Tomcat ,JBoss and Java use GMT, no matter what timezone the VPS is set to. If you need to change the timezone for Tomcat, JBoss, or Java you will need to modify either /etc/tomcatX/tomcat.conf or /etc/jbossX/jboss.conf (where X in the version of Tomcat or JBoss you are using), or add a file to /etc/profile.d for Java.

To change the timezone, you will first need to determine what timezone you are in. This URL has a list of cities and timezones in the format used by Tomcat, JBoss or Java. Use the TZ column for the value.  If your city is not listed here, choose a city that is in the same timezone - http://en.wikipedia.org/wiki/List_of_zoneinfo_time_zones

Changing the timezone for Tomcat

For Tomcat, add a line to the Java Additional Parameters section of the tomcat.conf file. This file is located in the /etc/tomcatX directory, where X is the version of Tomcat you have installed.

In this example, the line is: wrapper.java.additional.6=-Duser.timezone=Country/City
Please remember to substitute your actual Country/City value.

# Java Additional Parameters
wrapper.java.additional.1=-server
wrapper.java.additional.2=-Djava.endorsed.dirs=%TOMCAT_HOME%/common/endorsed
wrapper.java.additional.3=-Dcatalina.base=%TOMCAT_HOME%
wrapper.java.additional.4=-Dcatalina.home=%TOMCAT_HOME%
wrapper.java.additional.5=-Djava.io.tmpdir=%TOMCAT_HOME%/temp
wrapper.java.additional.6=-Duser.timezone=Country/City

Note that the line added has the next numerical value, in this case the number 6. This numerical order must be maintained. For example, if your last line in Additional Parameters is 7, then the line for the timezone has to be line 8, and so forth.


Once you have made these changes, restart Tomcat with the following command (where X is the version of Tomcat you have installed.
[root@example tomcatX]# service tomcatX restart
Stopping Tomcat Application Server...
Stopped Tomcat Application Server.
Starting Tomcat Application Server...
[root@example tomcatX]#

Tomcat should now be using the timezone you have set.

Changing the timezone for JBoss

For JBoss, the instructions are essentially the same as for Tomcat.. Add the same line for the timezone in the /etc/jbossX/jboss.conf file, as the last line in the Java Additional Parameters section. As with Tomcat, the line has to be next in the numerical order, and JBoss has to be restarted for the change to take effect. The same command that restarts Tomcat will restart JBoss, simply substitute ‘jbossX’ for ‘tomcatX’.

Changing the timezone for Java

To change the timezone for Java, you have to add a file in the /etc/profile.d directory called timezone.sh. This file will be run whenever the VPS is rebooted, or when a user logs in.

This information is for someone running a Java application from the command line, not for someone running JBoss or Tomcat.

[root@example ~]# cd /etc/profile.d
[root@example profile.d]# vi timezone.sh


Using a text editor (in this example the vi editor), create the timezone.sh file and add these lines, substituting your timezone Country/City as necessary:
# timezone initialization for Java
export TZ=Country/City

Save and exit the file. You will need to completely logout from the SSH session and the log back in and restart your Java application before it will see the new timezone information.

Changing the timezone for MySQL and PostgreSQL

By default, MySQL and PostgreSQL use the same timezone  that the VPS is set to. If for some reason this is not working as you expect, or if you need to change the timezone, it can be done. It is fairly uncommon to have to or want to change the timezone for MySQL or PostgreSQL. 

Changing the timezone for MySQL

Please read the official MySQL documentation for Server Time Zone Support. This is the official documentation on what is and is not supported for MySQL regarding to setting the timezone.

The timezone information has to go into a my.cnf file located in the /etc directory. By default, this file does not exist. If you have created one already for other reasons, you can simply add the following line to the file. If one doesn’t exist, you will need to create one. This is NOT the /root/.my.cnf file. Do not edit that file, only edit the /etc/my.cnf file.

[root@example ~]# cd /etc
[root@example etc]# vi my.cnf


Using a text editor (in this example the vi editor), edit or create the my.cnf file. If the file already exists, add only the timezone line to the [mysqld] section. If the my.cnf file does not exist, add both lines.
[mysqld]
default-time-zone=timezone


For the timezone, you can use any timezone variable name accepted in the MySQL Server Time Zone link above.
Once you have made the change, restart the MySQL database for the changes to take effect.
[root@example etc]# service mysqld restart
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]
[root@example etc]#


Changing the timezone for PostgreSQL

Please read the official PostgreSQL documentation for information on setting the timezone. Section 8.5.3 Time Zones is the relevant section, and the list of accepted timezones is found here.

[root@example ~]# cd /var/lib/pgsql/data/
[root@example data]# vi postgresql.conf


Using a text editor (in this example the vi editor), edit the postgresql.conf file. Find the line for the timezone setting (in this example it is line 426, yours may vary), uncomment the line, and add the correct timezone.
timezone = timezone                  # actually, defaults to TZ environment


Once you have done that, restart the PostgreSQL database for the changes to take effect.
[root@example data]# service postgresql restart
Stopping postgresql service:                               [  OK  ]
Starting postgresql service:                               [  OK  ]
[root@example data]#




Comments

Please login to comment