11

On my Manjaro linux box, I have a file /etc/timezone which contains:

Asia/Bangkok

Another Manjaro forum user also has the same file. That thread on the whole contains some prior art on this question.

What's strange is that timedatectl status doesn't use this file to report Region/City. Here's the initial status:

$ timedatectl status                                          
                      Local time: Fri 2018-06-29 11:01:28 +07       
                  Universal time: Fri 2018-06-29 04:01:28 UTC    
                        RTC time: Fri 2018-06-29 04:01:28        
                       Time zone: Asia/Bangkok (+07, +0700)             
       System clock synchronized: no                          
systemd-timesyncd.service active: no                              
                 RTC in local TZ: no                            

Now I overwrite the /etc/localtime symlink with contents of the file it points to:

$ sudo ln -f "$(realpath /etc/localtime)" /etc/localtime          
$ timedatectl status                                           
                      Local time: Fri 2018-06-29 04:04:03 UTC
                  Universal time: Fri 2018-06-29 04:04:03 UTC
                        RTC time: Fri 2018-06-29 04:04:04
                       Time zone: n/a (UTC, +0000) 
       System clock synchronized: no                               
systemd-timesyncd.service active: no
                 RTC in local TZ: no  

Note the local time change to match UTC, and then/a timezone.

So, timedatectl doesn't read from /etc/timezone, and timedatectl set-timezone doesn't write to /etc/timezone also.

Besides that guess, my /etc/timezone is a mystery.

  1. What writes it?
  2. What reads it?
  3. What for?
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
  • 1
    This behaviour of `timedatectl` is not "strange". As Stephen Kitt told you in https://unix.stackexchange.com/a/451714/5132 , this is the _normal_ behaviour of `timedatectl`. [The behaviour on Debian](https://sources.debian.org/src/systemd/239-3/debian/patches/debian/Use-Debian-specific-config-files.patch/) is an exception, not the rule. – JdeBP Jun 29 '18 at 06:27
  • 2
    @JdeBP It's the presence of `/etc/timezone` that is strange because I'm not running Debian. – Tom Hale Jun 30 '18 at 06:24

1 Answers1

12

GNU libc (and thus any non-embedded Linux), reads /etc/localtime to determine the system's time zone (the default timezone if not overridden by the TZ environment variable or by an application-specific setting). *BSD does the same thing. Some embedded Linux systems do things differently.

/etc/localtime should be a symbolic link to a file under /usr/share/zoneinfo/. Normal applications don't mind, they only read the contents of the file, but system management utilities such as timedatectl care more because they can also change the setting, and they would do that by changing the target of the symbolic link.

Java does (or did?) things differently: it reads /etc/timezone, which contains a timezone name, which should be the path to a file relative to /usr/share/zoneinfo. I'm not aware of any other program that uses /etc/timezone, and I don't know why Sun chose to do things differently from the rest of the world.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 1
    Yes you do. You referenced it in your 2011 answer. Sun/Oracle chose to do things _the same_ as someone else. It just chose Debian/Ubuntu as that someone else, adopting the `/etc/timezone` mechanism in 2009. – JdeBP Jun 29 '18 at 06:42
  • @JdeBP Sun most definitely doesn't do the same thing as Debian. I've never found anything that uses `/etc/timezone` other than Java, and I've been a Debian user for close to two decades. – Gilles 'SO- stop being evil' Jun 29 '18 at 07:15
  • There are still a few packages in Debian which use `/etc/timezone` rather than `/etc/localtime`, *e.g.* `cron` or `cups`. See [this source search](https://codesearch.debian.net/search?q=%2Fetc%2Ftimezone) for the full list. Some upstream programs use it too — in some cases, in preference to `/etc/localtime` (*e.g.* FreeRDP), in other cases, as a fallback (*e.g.* Firefox, Chrome, GNOME). `/etc/localtime` in glibc dates back to some time in 1992, by which time the development of Java had already started. It could well be a case of cargo-culting of course. – Stephen Kitt Jun 29 '18 at 07:24
  • It might be interesting to look at what early JVMs did on platforms without symlinks... – Stephen Kitt Jun 29 '18 at 07:25
  • You need to read the very bug report that you yourself pointed to in 2011. There the statement that this behaviour comes to Java from Debian is, plain as day, dated 2009-08-07. And we also know that this is a Debianism from the fact that, as I and Stephen Kitt have already pointed out, `timedatectl` has been patched on Debian to include this Debianism, the patch itself also explaining that it is a Debianism as does [this manual](http://0pointer.de/public/systemd-man/timezone.html). A Debian user for two decades will know where to find Debian Bugs 803144, 726256, and 726996. – JdeBP Jun 29 '18 at 07:39
  • Note that on Solaris, `/etc/timezone` is not about setting the system timezone. On Solaris, that's set in `/etc/default/init` (which localtime opens and looks for a TZ=... line when `$TZ` is not set). `/etc/timezone` is only used as one of the source files for generating NIS maps. – Stéphane Chazelas Jun 29 '18 at 09:00
  • Thanks for the historical info. I'm running Manjaro (was tagged) a derivative of Arch (now tagged), so I'm still scratching my head as to what non-Debian file was doing there. – Tom Hale Jun 30 '18 at 06:27
  • 4
    Programs using glibc's time functions will automatically use `/etc/localtime`. But programs with their own timezone database, like Java, will need just the **name** of the system default timezone: this was not easily available in `/etc/localtime` as it historically might have been a *copy* of the appropriate file in `/usr/share/zoneinfo`, not a symlink to it. As a result, distribution makers stored the **name** of the system timezone into another location too: RedHat put it into `/etc/sysconfig/clock`, Debian in `/etc/timezone`. Now `/etc/localtime` can be out of sync with that other place... – telcoM Jun 30 '18 at 08:59
  • 1
    `/etc/timezone` can be used to be mounted in some docker containers such as php ones to give it timezone information. – noraj May 07 '21 at 08:13
  • imho php\php-fpm if have date.timezone in config file completely ignore host timezone. moreover if they dont have date.timezone in config file the ignore /etc/timezone and only use /etc/localtime – Alex Jun 20 '23 at 22:30