From: Stefan Priebe Date: Wed, 22 Oct 2014 19:39:47 +0000 (+0200) Subject: VZDump: send an error email in case of lock failure X-Git-Url: https://git.proxmox.com/?p=pve-manager.git;a=commitdiff_plain;h=6ec9de4426d34fcceb59e6ecd707bb74c3e6b4dc VZDump: send an error email in case of lock failure Signed-off-by: Stefan Priebe --- diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm index dc0836b1..98b0b6d8 100644 --- a/PVE/API2/VZDump.pm +++ b/PVE/API2/VZDump.pm @@ -122,7 +122,13 @@ __PACKAGE__->register_method ({ die "interrupted by signal\n"; }; - $vzdump->getlock (); # only one process allowed + eval { + $vzdump->getlock(); # only one process allowed + }; + if ($@) { + $vzdump->sendmail([], 0, $@); + exit(-1); + } if (defined($param->{ionice})) { if ($param->{ionice} > 7) { diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm index 4a4d25cb..c39165da 100644 --- a/PVE/VZDump.pm +++ b/PVE/VZDump.pm @@ -243,8 +243,8 @@ sub find_add_exclude { } } -my $sendmail = sub { - my ($self, $tasklist, $totaltime) = @_; +sub sendmail { + my ($self, $tasklist, $totaltime, $err) = @_; my $opts = $self->{opts}; @@ -268,7 +268,8 @@ my $sendmail = sub { } } - my $stat = $ecount ? 'backup failed' : 'backup successful'; + my $stat = ($ecount || $err) ? 'backup failed' : 'backup successful'; + $stat .= ": $err" if $err; my $hostname = `hostname -f` || PVE::INotify::nodename(); chomp $hostname; @@ -596,7 +597,7 @@ sub getlock { if (!open (SERVER_FLCK, ">>$lockfile")) { debugmsg ('err', "can't open lock on file '$lockfile' - $!", undef, 1); - exit (-1); + die "can't open lock on file '$lockfile' - $!"; } if (flock (SERVER_FLCK, LOCK_EX|LOCK_NB)) { @@ -605,7 +606,7 @@ sub getlock { if (!$maxwait) { debugmsg ('err', "can't aquire lock '$lockfile' (wait = 0)", undef, 1); - exit (-1); + die "can't aquire lock '$lockfile' (wait = 0)"; } debugmsg('info', "trying to get global lock - waiting...", undef, 1); @@ -629,7 +630,7 @@ sub getlock { if ($err) { debugmsg ('err', "can't aquire lock '$lockfile' - $err", undef, 1); - exit (-1); + die "can't aquire lock '$lockfile' - $err"; } debugmsg('info', "got global lock", undef, 1); @@ -1068,7 +1069,7 @@ sub exec_backup { my $totaltime = time() - $starttime; - eval { $self->$sendmail ($tasklist, $totaltime); }; + eval { $self->sendmail ($tasklist, $totaltime); }; debugmsg ('err', $@) if $@; die $err if $err;