From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 66E981FF0AE for ; Tue, 29 Sep 2026 16:49:28 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 376AA2150F; Tue, 29 Sep 2026 16:49:28 +0200 (CEST) Message-ID: Date: Tue, 29 Sep 2026 16:49:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed From: Jonas Theisen To: pmg-devel@lists.proxmox.com References: <20260729160639.431458-1-j.theisen@proxmox.com> Content-Language: en-US In-Reply-To: <20260729160639.431458-1-j.theisen@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1790693363299 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.267 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 5ZS7TPVE76CAUD3ZFBNATYL4QGFNDXVW X-Message-ID-Hash: 5ZS7TPVE76CAUD3ZFBNATYL4QGFNDXVW X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 > --- > 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; > }