* [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed
@ 2026-07-29 16:06 Jonas Theisen
2026-09-29 14:49 ` Jonas Theisen
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread* Re: [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed
2026-07-29 16:06 [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed Jonas Theisen
@ 2026-09-29 14:49 ` Jonas Theisen
0 siblings, 0 replies; 2+ messages in thread
From: Jonas Theisen @ 2026-09-29 14:49 UTC (permalink / raw)
To: pmg-devel
Gentle ping
On 7/30/26 16:18, Jonas Theisen wrote:
> 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;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-29 14:49 UTC | newest]
Thread overview: 2+ messages (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
2026-09-29 14:49 ` Jonas Theisen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox