[pmg-devel] [PATCH pmg-api 03/12] add reload method to PMG::Config

Stoiko Ivanov s.ivanov at proxmox.com
Mon Oct 7 21:28:47 CEST 2019


Synchronization of the configuration (including pmg.conf) inside a cluster
happens via rsync to /etc/pmg/master and a rename of the files if changed.
This bypasses the reading of the current configuraitons and thus does not
schedule a reload for pmg-smtp-filter if one of the config-option affecting it
changes on the master.

By adding a 'reload' sub to PMG::Config, which keeps the old 'current' hash
of a config-object changes can be tracked and pmg-smtp-filter reloaded.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/API2/Cluster.pm      |  3 ++-
 src/PMG/CLI/pmgcm.pm         |  4 ++--
 src/PMG/Config.pm            | 13 +++++++++++++
 src/PMG/Service/pmgmirror.pm |  4 +++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/PMG/API2/Cluster.pm b/src/PMG/API2/Cluster.pm
index ceda100..101d780 100644
--- a/src/PMG/API2/Cluster.pm
+++ b/src/PMG/API2/Cluster.pm
@@ -61,11 +61,12 @@ sub cluster_join {
 
 	PMG::MailQueue::create_spooldirs($cid);
 
+	my $cfg = PMG::Config->new();
 	PMG::Cluster::sync_config_from_master($cinfo->{master}->{name}, $cinfo->{master}->{ip});
 
 	PMG::DBTools::init_nodedb($cinfo);
 
-	my $cfg = PMG::Config->new();
+	$cfg->reload();
 	my $ruledb = PMG::RuleDB->new();
 	my $rulecache = PMG::RuleCache->new($ruledb);
 
diff --git a/src/PMG/CLI/pmgcm.pm b/src/PMG/CLI/pmgcm.pm
index c41c24d..f2b202b 100644
--- a/src/PMG/CLI/pmgcm.pm
+++ b/src/PMG/CLI/pmgcm.pm
@@ -249,10 +249,10 @@ __PACKAGE__->register_method({
 
 	print STDERR "syncing master configuration from '${master_ip}'\n";
 
-	PMG::Cluster::sync_config_from_master($master_name, $master_ip);
-
 	my $cfg = PMG::Config->new();
+	PMG::Cluster::sync_config_from_master($master_name, $master_ip);
 
+	$cfg->reload();
 	$cfg->rewrite_config(undef, 1);
 
 	return undef;
diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index f94688c..a9a2822 100755
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -755,6 +755,19 @@ sub new {
     return bless $cfg, $class;
 }
 
+# keeps the current property of self, but reads the config anew
+sub reload {
+    my ($self) = @_;
+
+    my $class = ref($self);
+    my $cfg = PVE::INotify::read_file("pmg.conf");
+    foreach my $key (keys %$cfg) {
+	$self->{$key} = $cfg->{$key};
+    }
+
+    return undef;
+}
+
 sub write {
     my ($self) = @_;
 
diff --git a/src/PMG/Service/pmgmirror.pm b/src/PMG/Service/pmgmirror.pm
index 339bf7b..7a9eb5a 100644
--- a/src/PMG/Service/pmgmirror.pm
+++ b/src/PMG/Service/pmgmirror.pm
@@ -96,6 +96,8 @@ sub cluster_sync {
     my $master_ip = $cinfo->{master}->{ip};
     my $master_name = $cinfo->{master}->{name};
 
+    # read the config before the sync to notice changes
+    my $cfg = PMG::Config->new();
     if ($role ne 'master') {
 	PMG::Cluster::sync_config_from_master($master_name, $master_ip);
     }
@@ -142,7 +144,7 @@ sub cluster_sync {
 	$sync_node->($cinfo->{master});
 
 	# rewrite config after sync from master
-	my $cfg = PMG::Config->new();
+	$cfg->reload();
 	my $ruledb = PMG::RuleDB->new($dbh);
 	my $rulecache = PMG::RuleCache->new($ruledb);
 	$cfg->rewrite_config($rulecache, 1);
-- 
2.20.1




More information about the pmg-devel mailing list