From 2e8fd72a9e9d41d11462c5acf0a73766260a4707 Mon Sep 17 00:00:00 2001 From: Wolfgang Link Date: Tue, 19 May 2015 07:02:52 +0200 Subject: [PATCH] remove cron entry if sync-job failed and move cron EVN setting If a Sync-job crash it should stop trying to sync until somebody checked it. moving the cron EVN to the code is necessary to prevent at updating that the file will be over written. rename delete_corn to delete_configs the function also deletes the config entry Signed-off-by: Wolfgang Link --- Makefile | 3 --- pve-zsync | 24 +++++++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5b4e160..d5c6b83 100644 --- a/Makefile +++ b/Makefile @@ -45,9 +45,6 @@ deb ${DEB}: rm -rf debian mkdir debian install -d debian/var/lib/pve-zsync - install -d debian/etc/cron.d/ - echo "SHELL=/bin/sh" >> debian/etc/cron.d/pve-zsync - echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> debian/etc/cron.d/pve-zsync make DESTDIR=${CURDIR}/debian install install -d -m 0755 debian/DEBIAN sed -e s/@@VERSION@@/${VERSION}/ -e s/@@PKGRELEASE@@/${PKGREL}/ -e s/@@ARCH@@/${ARCH}/ debian/DEBIAN/control diff --git a/pve-zsync b/pve-zsync index 9d49730..26b38c1 100644 --- a/pve-zsync +++ b/pve-zsync @@ -389,20 +389,20 @@ sub destroy { my $source = parse_target($param->{source}); - my $delete_cron = sub { + my $delete_configs = sub { my ($path, $name, $cfg) = @_; die "Source does not exist!\n" unless $cfg->{$path} ; die "Sync Name does not exist!\n" unless $cfg->{$path}->{$name}; - my $source .= $cfg->{$path}->{$name}->{source_ip} ? "$cfg->{$path}->{$name}->{source_ip}:" : ''; + my $source = $cfg->{$path}->{$name}->{source_ip} ? "$cfg->{$path}->{$name}->{source_ip}:" : ''; - $source .= $cfg->{$path}->{$name}->{source_pool}; + $source .= $cfg->{$path}->{$name}->{source_pool} if $cfg->{$path}->{$name}->{source_pool}; $source .= $cfg->{$path}->{$name}->{source_path} ? $cfg->{$path}->{$name}->{source_path} :''; my $dest = $cfg->{$path}->{$name}->{dest_ip} ? $cfg->{$path}->{$name}->{dest_ip} :""; - $dest .= $cfg->{$path}->{$name}->{dest_pool}; + $dest .= $cfg->{$path}->{$name}->{dest_pool} if $cfg->{$path}->{$name}->{dest_pool}; $dest .= $cfg->{$path}->{$name}->{dest_path} ? $cfg->{$path}->{$name}->{dest_path} :''; delete $cfg->{$path}->{$name}; @@ -418,14 +418,14 @@ sub destroy { if ($source->{vmid}) { my $path = $source->{vmid}; - &$delete_cron($path, $name, $cfg) + &$delete_configs($path, $name, $cfg) } else { my $path = $source->{pool}; $path .= $source->{path} if $source->{path}; - &$delete_cron($path, $name, $cfg); + &$delete_configs($path, $name, $cfg); } } @@ -471,6 +471,9 @@ sub sync { $conf_name = $source->{vmid} if $source->{vmid}; $cfg->{$conf_name}->{$name}->{status} = "error"; write_to_config($cfg); + my $source_target = $source->{ip} ? $source->{ip}.":" : ''; + $source_target .= $source->{vmid} ? $source->{vmid} : $source->{abs_path}; + cron_del($source_target, $dest->{abs_path}, $name); } die "$err\n"; } @@ -564,11 +567,18 @@ sub snapshot_add { sub cron_add { my ($vm) = @_; + my $text =""; + + unless(-e $CRONJOBS){ + $text .= 'SHELL=/bin/sh'."\n"; + $text .= 'PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'."\n "; + } + open(my $fh, '>>', "$CRONJOBS") or die "Could not open file: $!\n"; foreach my $name (keys%{$vm}){ - my $text = "*/$vm->{$name}->{interval} * * * * root "; + $text .= "*/$vm->{$name}->{interval} * * * * root "; $text .= "$PATH$PROGNAME sync"; $text .= " -source "; if ($vm->{$name}->{vmid}) { -- 2.39.2