[pmg-devel] [PATCH pmg-api 11/12] add /etc/pmg/dkim to cluster-sync

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


The clustersync already uses rsync to sync most files (there are excludes
for '*.db', '*~', and the certificates of the node) from the master's
'/etc/pmg' directory to all nodes. Moving files from the syncdir to the node's
actual '/etc/pmg' happen only for explicitly listed files.

This patch factors out the moving of '/etc/pmg/templates' into a generic
directory-sync sub and adds 'templates' and 'dkim' to the directories that
should get moved to '/etc/pmg' on the node.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Cluster.pm | 67 +++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 27 deletions(-)

diff --git a/src/PMG/Cluster.pm b/src/PMG/Cluster.pm
index 3f055a0..897a73e 100644
--- a/src/PMG/Cluster.pm
+++ b/src/PMG/Cluster.pm
@@ -279,6 +279,38 @@ my $cond_commit_synced_file = sub {
     return 1;
 };
 
+my $cond_commit_synced_dir = sub {
+    my ($dirname, $dstdir) = @_;
+
+    $dstdir = "$cfgdir/$dirname" if !defined($dstdir);
+    my $srcdir = "$syncdir/$dirname";
+
+    if (-d $srcdir) {
+	mkdir $dstdir;
+	my $names_hash = {};
+	foreach my $fn (<$srcdir/*>) {
+	    next if $fn !~ m|^($srcdir/(.*))$|;
+	    $fn = $1; # untaint;
+	    my $name = $2;
+	    $names_hash->{$name} = 1;
+	    my $target = "$dstdir/$name";
+	    if (-f $fn) {
+		$cond_commit_synced_file->("$dirname/$name", $target);
+	    } elsif (-l $fn) {
+		warn "update $target failed - $!\n" if !rename($fn, $target);
+	    }
+	}
+	# remove vanished files
+	foreach my $fn (<$dstdir/*>) {
+	    next if $fn !~ m|^($dstdir/(.*))$|;
+	    $fn = $1; # untaint;
+	    my $name = $2;
+	    next if $names_hash->{$name};
+	    warn "unlink $fn failed - $!\n" if !unlink($fn);
+	}
+    }
+};
+
 my $rsync_command = sub {
     my ($host_key_alias, @args) = @_;
 
@@ -404,6 +436,14 @@ sub sync_config_from_master {
 	$cond_commit_synced_file->($filename);
     }
 
+    my $dirs = [
+	'templates',
+	'dkim',
+    ];
+
+    foreach my $dir (@$dirs) {
+	$cond_commit_synced_dir->($dir);
+    }
 
     my $force_restart = {};
 
@@ -413,33 +453,6 @@ sub sync_config_from_master {
 
     $cond_commit_synced_file->('pmg.conf');
 
-    # sync user templates files/symlinks (not recursive)
-    my $srcdir = "$syncdir/templates";
-    if (-d $srcdir) {
-	my $dstdir = "$cfgdir/templates";
-	mkdir $dstdir;
-	my $names_hash = {};
-	foreach my $fn (<$srcdir/*>) {
-	    next if $fn !~ m|^($srcdir/(.*))$|;
-	    $fn = $1; # untaint;
-	    my $name = $2;
-	    $names_hash->{$name} = 1;
-	    my $target = "$dstdir/$name";
-	    if (-f $fn) {
-		$cond_commit_synced_file->("templates/$name", $target);
-	    } elsif (-l $fn) {
-		warn "update $target failed - $!\n" if !rename($fn, $target);
-	    }
-	}
-	# remove vanished files
-	foreach my $fn (<$dstdir/*>) {
-	    next if $fn !~ m|^($dstdir/(.*))$|;
-	    $fn = $1; # untaint;
-	    my $name = $2;
-	    next if $names_hash->{$name};
-	    warn "unlink $fn failed - $!\n" if !unlink($fn);
-	}
-    }
 }
 
 sub sync_ruledb_from_master {
-- 
2.20.1




More information about the pmg-devel mailing list