[pmg-devel] [PATCH pmg-api v2 1/3] implement force_restart for cluster sync

Dominik Csapak d.csapak at proxmox.com
Thu Nov 14 12:18:52 CET 2019


the 'force_restart' hash was unused, but it is actually necessary to
restart the pmg-smtp-filter if the custom.cf has changed

use it for saving the daemon name that needs to be restarted, this
way we can reuse it in the future to force restart other daemons
or for different reasons if we need to

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PMG/CLI/pmgcm.pm         | 9 ++++++++-
 src/PMG/Cluster.pm           | 3 ++-
 src/PMG/Service/pmgmirror.pm | 7 ++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/PMG/CLI/pmgcm.pm b/src/PMG/CLI/pmgcm.pm
index c41c24d..59bdb06 100644
--- a/src/PMG/CLI/pmgcm.pm
+++ b/src/PMG/CLI/pmgcm.pm
@@ -249,12 +249,19 @@ __PACKAGE__->register_method({
 
 	print STDERR "syncing master configuration from '${master_ip}'\n";
 
-	PMG::Cluster::sync_config_from_master($master_name, $master_ip);
+	my $restart = PMG::Cluster::sync_config_from_master($master_name, $master_ip);
 
 	my $cfg = PMG::Config->new();
 
 	$cfg->rewrite_config(undef, 1);
 
+	if (scalar(keys %$restart)) {
+	    print "please restart the following daemons:\n";
+	    for my $service (sort keys %$restart) {
+		print "$service\n"
+	    }
+	}
+
 	return undef;
     }});
 
diff --git a/src/PMG/Cluster.pm b/src/PMG/Cluster.pm
index fe802ba..0980c68 100644
--- a/src/PMG/Cluster.pm
+++ b/src/PMG/Cluster.pm
@@ -422,11 +422,12 @@ sub sync_config_from_master {
     my $force_restart = {};
 
     if ($cond_commit_synced_file->($sa_custom_cf, "${sa_conf_dir}/${sa_custom_cf}")) {
-	$force_restart->{spam} = 1;
+	$force_restart->{'pmg-smtp-filter'} = 1;
     }
 
     $cond_commit_synced_file->('pmg.conf');
 
+    return $force_restart;
 }
 
 sub sync_ruledb_from_master {
diff --git a/src/PMG/Service/pmgmirror.pm b/src/PMG/Service/pmgmirror.pm
index 339bf7b..2655b90 100644
--- a/src/PMG/Service/pmgmirror.pm
+++ b/src/PMG/Service/pmgmirror.pm
@@ -18,6 +18,7 @@ use PMG::RuleDB;
 use PMG::Cluster;
 use PMG::ClusterConfig;
 use PMG::Statistic;
+use PMG::Utils;
 
 use base qw(PVE::Daemon);
 
@@ -96,8 +97,9 @@ sub cluster_sync {
     my $master_ip = $cinfo->{master}->{ip};
     my $master_name = $cinfo->{master}->{name};
 
+    my $force_restart = {};
     if ($role ne 'master') {
-	PMG::Cluster::sync_config_from_master($master_name, $master_ip);
+	$force_restart = PMG::Cluster::sync_config_from_master($master_name, $master_ip);
     }
 
     my $csynctime = tv_interval($start_time);
@@ -164,6 +166,9 @@ sub cluster_sync {
 			   "(files %.2f, database %.2f, config %.2f))",
 			   $errcount, $cptime, $rsynctime, $dbtime, $csynctime));
 
+    foreach my $service (keys %$force_restart) {
+	PMG::Utils::service_cmd($service, 'restart');
+    }
 }
 
 sub run {
-- 
2.20.1




More information about the pmg-devel mailing list