[pmg-devel] [PATCH api] Use timedatectl for timezone handling

Stefan Mayr stefan at mayr-stefan.de
Wed Dec 31 11:41:06 CET 2025


Usage of /etc/timezone is deprecated. The tzdata maintainers recommend
switching to timedatectl.

Almost the same patch was sent to pve-devel to fix #7175. Transfering
this change to PMG should allow us to remove handling /etc/timezone in
the INotify module from
pve-common.

I hope we got all perl dependencies. From a quick peek someone has to do
the same for the rust code parts.

Suggested-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
Suggested-by: Maximiliano Sandroval <m.sandoval at proxmox.com>
Signed-off-by: Stefan Mayr <stefan at mayr-stefan.de>
---
 src/PMG/API2/Nodes.pm | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/PMG/API2/Nodes.pm b/src/PMG/API2/Nodes.pm
index 3479d64..d95657b 100644
--- a/src/PMG/API2/Nodes.pm
+++ b/src/PMG/API2/Nodes.pm
@@ -659,10 +659,15 @@ __PACKAGE__->register_method({
     code => sub {
         my ($param) = @_;
 
+        my $timezone;
         my $ctime = time();
         my $ltime = timegm_nocheck(localtime($ctime));
+        PVE::Tools::run_command(
+            ['timedatectl', 'show', '--property=Timezone', '--value'],
+            outfunc => sub { $timezone //= shift },
+        );
         my $res = {
-            timezone => PVE::INotify::read_file('timezone'),
+            timezone => $timezone,
             time => time(),
             localtime => $ltime,
         };
@@ -693,7 +698,7 @@ __PACKAGE__->register_method({
     code => sub {
         my ($param) = @_;
 
-        PVE::INotify::write_file('timezone', $param->{timezone});
+        PVE::Tools::run_command(['timedatectl', 'set-timezone', $param->{timezone}]);
 
         return undef;
     },
-- 
2.34.1




More information about the pmg-devel mailing list