Various fixes in lock handling

tags/virt-backup-0.2.21-1
Daniel Berteaud 6 years ago
parent 9639682ef4
commit cec440f702
  1. 20
      virt-backup

@ -234,12 +234,20 @@ print "\n" if ($opts{debug});
# Acquire an exclusive lock so we can ensure only one copy # Acquire an exclusive lock so we can ensure only one copy
# of virt-backup can run at a time # of virt-backup can run at a time
print "Trying to acquire an exclusive lock\n" if ($opts{debug});
my $locker = LockFile::Simple->make( my $locker = LockFile::Simple->make(
-max => 180, -max => 180,
-delay => 1 -delay => 1,
-autoclean => 1,
-ext => 'lck',
-hold => 60
); );
print "Trying to acquire an exclusive lock\n" if ($opts{debug}); my $glock = undef;
die "Can't acquire exclusive lock" unless $locker->lock($opts{lockdir} . '/virt-backup'); if ($opts{action} =~ m/^dump|convert|chunkmount$/){
print "Trying to acquire an exclusive lock\n" if ($opts{debug});
my $glock = $locker->lock($opts{lockdir} . '/virt-backup') || die "Can't acquire exclusive lock\n";
}
foreach our $vm (@vms){ foreach our $vm (@vms){
# Create a new object representing the VM # Create a new object representing the VM
@ -290,8 +298,10 @@ foreach our $vm (@vms){
} }
} }
print "Releasing exclusive lock\n" if ($opts{debug}); if ($glock){
$locker->unlock($opts{lockdir} . "/virt-backup"); print "Releasing exclusive lock\n" if ($opts{debug});
$glock->release;
}
exit 0; exit 0;
############################################################################ ############################################################################

Loading…
Cancel
Save