]> git.proxmox.com Git - pve-zsync.git/commitdiff
remove cron entry if sync-job failed and move cron EVN setting
authorWolfgang Link <w.link@proxmox.com>
Tue, 19 May 2015 05:02:52 +0000 (07:02 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 19 May 2015 05:40:23 +0000 (07:40 +0200)
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 <w.link@proxmox.com>
Makefile
pve-zsync

index 5b4e16002b5870ebaf7a7c20df22cd4bdd12d64d..d5c6b8328d7d941f16e70e2c0466094de6c21566 100644 (file)
--- 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}/ <control.in >debian/DEBIAN/control
index 9d49730f2465041bec679dbc92bd71c09e461838..26b38c100fdeaf07d967261f39a6b10b3c5c6cb8 100644 (file)
--- 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}) {