[pmg-devel] [PATCH pmg-api 4/4] certs: reload postfix to activate new certificate

Stoiko Ivanov s.ivanov at proxmox.com
Thu Mar 18 16:14:49 CET 2021


the current logic for reloading postfix only does so if the tls config
parameter changes (after rewriting the config files).
this does not cover the case where a certificate is replaced in a
setup, which already has tls enabled (config stays the same, so
postfix does not get reloaded)

the issue is mostly cosmetic, since postfix does eventually fork off
new smtpd instances, which read the files from disk, but it's
inconvenient, when trying out the new acme integration, and then
running a ssl-check on your PMG from external just to see that the
certificate was not updated.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
best viewed with `git show -w`
 src/PMG/API2/Certificates.pm | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/PMG/API2/Certificates.pm b/src/PMG/API2/Certificates.pm
index 1a6c434..1a7ded6 100644
--- a/src/PMG/API2/Certificates.pm
+++ b/src/PMG/API2/Certificates.pm
@@ -69,16 +69,14 @@ my sub set_smtp : prototype($$) {
 
     my $code = sub {
 	my $cfg = PMG::Config->new();
-	if (!$cfg->get('mail', 'tls') == !$on) {
-	    return;
+	if (!$cfg->get('mail', 'tls') != !$on) {
+	    print "Rewriting postfix config\n";
+	    $cfg->set('mail', 'tls', $on);
+	    $cfg->write();
+	    my $changed = $cfg->rewrite_config_postfix();
 	}
 
-	print "Rewriting postfix config\n";
-	$cfg->set('mail', 'tls', $on);
-	$cfg->write();
-	my $changed = $cfg->rewrite_config_postfix();
-
-	if ($changed && $reload) {
+	if ($reload) {
 	    print "Reloading postfix\n";
 	    PMG::Utils::service_cmd('postfix', 'reload');
 	}
-- 
2.20.1





More information about the pmg-devel mailing list