all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed
@ 2026-07-29 16:06 Jonas Theisen
  0 siblings, 0 replies; only message in thread
From: Jonas Theisen @ 2026-07-29 16:06 UTC (permalink / raw)
  To: pmg-devel

Replace sendmail-interface command newaliases
with postfix native postalias

Added update logic for postalias to only run if changes are present
since the overwrite every two minutes would trigger a log message
next time an email was received on a cluster node.
This is analogus to the already added run_postmap for other
postfix files,
see 78982d93 ("run_postmap: only run postmap if file was modified")

run_postmap could not be reused since it does not handle alias files

Reported by a forum user in https://forum.proxmox.com/threads/185048/

To test change /etc/aliases and run 'pmgcm sync' on cluster node.
aliases.db should be updated.
If unchanged aliases.db on cluster node should also stay unchanged
in contrast to the previous overwrite every two minutes.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PMG/Config.pm | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 5f95857..a03e79e 100644
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -1923,6 +1923,30 @@ sub rewrite_postfix_welcomelist {
     return $changes;
 }
 
+my sub run_postalias {
+    my ($filename) = @_;
+
+    # make sure the file exists (else postalias fails)
+    IO::File->new($filename, 'a', 0644);
+
+    my $mtime_src = (CORE::stat($filename))[9] // die "unable to read mtime of $filename\n";
+
+    my $mtime_dst = (CORE::stat("$filename.db"))[9] // 0;
+
+    # if not changed, do nothing
+    return if $mtime_src <= $mtime_dst;
+
+    eval {
+        PVE::Tools::run_command(
+            ['/usr/sbin/postalias', $filename],
+            errmsg => "unable to update postfix aliases $filename",
+        );
+    };
+    my $err = $@;
+
+    warn $err if $err;
+}
+
 # rewrite /etc/postfix/*
 sub rewrite_config_postfix {
     my ($self, $rulecache) = @_;
@@ -1950,8 +1974,8 @@ sub rewrite_config_postfix {
 
     $changes = 1 if $rulecache && rewrite_postfix_welcomelist($rulecache);
 
-    # make sure aliases.db is up to date
-    system('/usr/bin/newaliases');
+    # update aliases.db if necessary
+    run_postalias('/etc/aliases');
 
     return $changes;
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-30 14:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29 16:06 [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed Jonas Theisen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal