[pmg-devel] [PATCH pmg-api v2 10/11] add /etc/pmg/dkim to cluster-sync
Stoiko Ivanov
s.ivanov at proxmox.com
Tue Oct 15 21:46:49 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 adds a second list of explicit directories and adds
'/etc/pmg/templates' and '/etc/pmg/dkim' to that list.
The syncing of all files inside this directory list is done via
`rsync -aq --delete-after`. This is a semantic change to the loop used
for the templates directory, in which only regular files and symlinks were
copied (rsync copies everything recursively).
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
src/PMG/Cluster.pm | 41 ++++++++++++++---------------------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/src/PMG/Cluster.pm b/src/PMG/Cluster.pm
index 3f055a0..fe802ba 100644
--- a/src/PMG/Cluster.pm
+++ b/src/PMG/Cluster.pm
@@ -404,6 +404,20 @@ sub sync_config_from_master {
$cond_commit_synced_file->($filename);
}
+ my $dirs = [
+ 'templates',
+ 'dkim',
+ ];
+
+ foreach my $dir (@$dirs) {
+ my $srcdir = "$syncdir/$dir";
+
+ if ( -d $srcdir ) {
+ my $cmd = ['rsync', '-aq', '--delete-after', "$srcdir/", "$cfgdir/$dir"];
+ PVE::Tools::run_command($cmd);
+ }
+
+ }
my $force_restart = {};
@@ -413,33 +427,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