my $lockfile = '/var/run/vzdump.lock';
+my $pidfile = '/var/run/vzdump.pid';
+
my $logdir = '/var/log/vzdump';
my @plugins = qw (PVE::VZDump::OpenVZ);
$res->{lockwait} = int($1);
} elsif ($line =~ m/stopwait:\s*(\d+)\s*$/) {
$res->{stopwait} = int($1);
+ } elsif ($line =~ m/stop:\s*(\d+)\s*$/) {
+ $res->{stop} = int($1);
} elsif ($line =~ m/size:\s*(\d+)\s*$/) {
$res->{size} = int($1);
} elsif ($line =~ m/maxfiles:\s*(\d+)\s*$/) {
sub getlock {
my ($self) = @_;
+ my $fh;
+
+ open($fh, "> $pidfile")
+ or die "cannot open $pidfile: $!";
+
+ print $fh $$, "\n",PVE::ProcFSTools::read_proc_starttime($$), "\n";
+
+ close $fh || warn "close $pidfile failed: $!";
+
my $maxwait = $self->{opts}->{lockwait} || $self->{lockwait};
if (!open (SERVER_FLCK, ">>$lockfile")) {
my $opts = $self->{opts};
+ if ($opts->{stop}) {
+ stop_all_backups($self);
+ return;
+ }
+
debugmsg ('info', "starting new backup job: $self->{cmdline}", undef, 1);
debugmsg ('info', "skip external VMs: " . join(', ', @{$self->{skiplist}}))
if scalar(@{$self->{skiplist}});
die $err if $err;
die "job errors\n" if $errcount;
+
+ unlink $pidfile;
}
my $confdesc = {
description => "Store resulting file to this storage.",
optional => 1,
}),
+ stop => {
+ type => 'boolean',
+ description => "Stop all current runnig backup jobs on this host.",
+ optional => 1,
+ default => 0,
+ },
size => {
type => 'integer',
description => "LVM snapshot size in MB.",
my ($param, $check_missing) = @_;
raise_param_exc({ all => "option conflicts with option 'vmid'"})
- if $param->{all} && $param->{vmid};
+ if ($param->{all} || $param->{stop}) && $param->{vmid};
raise_param_exc({ exclude => "option conflicts with option 'vmid'"})
if $param->{exclude} && $param->{vmid};
return if !$check_missing;
raise_param_exc({ vmid => "property is missing"})
- if !$param->{all} && !$param->{vmid};
+ if !($param->{all} || $param->{stop}) && !$param->{vmid};
+
+}
+
+sub stop_all_backups {
+ my($self) = @_;
+
+ return if ! -e $pidfile;
+
+ my @param = split(/\n/,PVE::Tools::file_get_contents($pidfile));
+ my $pid;
+ my $stime;
+
+ if ($param[0] =~ /^([-\@\w.]+)$/){
+ $pid = $1;
+ }
+ if ($param[1] =~/^([-\@\w.]+)$/){
+ $stime = $1;
+ }
+
+ if(PVE::ProcFSTools::check_process_running($pid, $stime) &&
+ PVE::ProcFSTools::read_proc_starttime($pid) == $stime){
+ print "toll";
+ kill(15,$pid);
+ }
+ unlink $pidfile;
}
sub command_line {