Unix, Timezones and Java
It happened recently that we wrote a web application for one of our customers, and it turned out that the timestamps in the logs and the database timestamps were 6 hours before the host's time, as returned by the 'date' command.
In HP-UX, the configuration file that defines the timezone is /etc/TIMEZONE, but it was correctly set to the CEST timezone.
We went back from the production environment to the development environment, compared the configurations, and they were equal.
But in the development environment the logs were fine.
Mmmh.
Okay, I wrote a simple program that System.outs the result of new Date() and the value of the system property 'user.timezone'. Running it in the production box yielded the CEST timezone.
Strange.
The problem shows only because it's a web app ?
Quickly converted the simple program in a simple JSP. Copied in production and invoking it yielded 6 hours before CEST.
Did the same in the development environment: both cases showed the CEST time.
Sgrunt.
We try hard to pay a lot of attention to have a development environment that is as close as possible to the production environment: OS configuration, JVM configuration, DB configuration. Exactly to avoid this kind of problems.
It turned out that in production Tomcat was launched using
su - tomcat -c "startup.sh"
and for some strange HP-UX machinery, the /etc/TIMEZONE file was not read, while in development Tomcat was launched via the normal startup.sh.
Small details, that's where evil is.
In HP-UX, the configuration file that defines the timezone is /etc/TIMEZONE, but it was correctly set to the CEST timezone.
We went back from the production environment to the development environment, compared the configurations, and they were equal.
But in the development environment the logs were fine.
Mmmh.
Okay, I wrote a simple program that System.outs the result of new Date() and the value of the system property 'user.timezone'. Running it in the production box yielded the CEST timezone.
Strange.
The problem shows only because it's a web app ?
Quickly converted the simple program in a simple JSP. Copied in production and invoking it yielded 6 hours before CEST.
Did the same in the development environment: both cases showed the CEST time.
Sgrunt.
We try hard to pay a lot of attention to have a development environment that is as close as possible to the production environment: OS configuration, JVM configuration, DB configuration. Exactly to avoid this kind of problems.
It turned out that in production Tomcat was launched using
su - tomcat -c "startup.sh"
and for some strange HP-UX machinery, the /etc/TIMEZONE file was not read, while in development Tomcat was launched via the normal startup.sh.
Small details, that's where evil is.