mirror of
https://git.proxmox.com/git/pve-access-control
synced 2025-07-27 18:36:59 +00:00
implement a way to abort workers
This commit is contained in:
parent
f6f2d51fa9
commit
b9e47e5738
@ -334,8 +334,7 @@ sub active_workers {
|
|||||||
my $check_task = sub {
|
my $check_task = sub {
|
||||||
my ($task) = @_;
|
my ($task) = @_;
|
||||||
|
|
||||||
my $pstart = PVE::ProcFSTools::read_proc_starttime($task->{pid});
|
if (PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart})) {
|
||||||
if ($pstart && ($pstart == $task->{pstart})) {
|
|
||||||
push @$tlist, $task;
|
push @$tlist, $task;
|
||||||
} else {
|
} else {
|
||||||
delete $task->{pid};
|
delete $task->{pid};
|
||||||
@ -427,6 +426,42 @@ sub active_workers {
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $kill_process_group = sub {
|
||||||
|
my ($pid, $pstart) = @_;
|
||||||
|
|
||||||
|
# send kill to process group (negative pid)
|
||||||
|
my $kpid = -$pid;
|
||||||
|
|
||||||
|
# always send signal to all pgrp members
|
||||||
|
kill(15, $kpid); # send TERM signal
|
||||||
|
|
||||||
|
# give max 5 seconds to shut down
|
||||||
|
for (my $i = 0; $i < 5; $i++) {
|
||||||
|
return if !PVE::ProcFSTools::check_process_running($pid, $pstart);
|
||||||
|
sleep (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
# to be sure
|
||||||
|
kill(9, $kpid);
|
||||||
|
};
|
||||||
|
|
||||||
|
sub check_worker {
|
||||||
|
my ($upid, $killit) = @_;
|
||||||
|
|
||||||
|
my $task = PVE::Tools::upid_decode($upid);
|
||||||
|
|
||||||
|
my $running = PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart});
|
||||||
|
|
||||||
|
return 0 if !$running;
|
||||||
|
|
||||||
|
if ($killit) {
|
||||||
|
&$kill_process_group($task->{pid});
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
# start long running workers
|
# start long running workers
|
||||||
# STDIN is redirected to /dev/null
|
# STDIN is redirected to /dev/null
|
||||||
# STDOUT,STDERR are redirected to the filename returned by upid_decode
|
# STDOUT,STDERR are redirected to the filename returned by upid_decode
|
||||||
@ -527,7 +562,7 @@ sub fork_worker {
|
|||||||
POSIX::write($psync[1], $msg, length ($msg));
|
POSIX::write($psync[1], $msg, length ($msg));
|
||||||
POSIX::close($psync[1]);
|
POSIX::close($psync[1]);
|
||||||
POSIX::_exit(1);
|
POSIX::_exit(1);
|
||||||
kill('KILL', $$);
|
kill(-9, $$);
|
||||||
}
|
}
|
||||||
|
|
||||||
# sync with parent (signal that we are ready)
|
# sync with parent (signal that we are ready)
|
||||||
@ -555,7 +590,7 @@ sub fork_worker {
|
|||||||
print STDERR "TASK OK\n";
|
print STDERR "TASK OK\n";
|
||||||
POSIX::_exit(0);
|
POSIX::_exit(0);
|
||||||
}
|
}
|
||||||
kill('KILL', $$);
|
kill(-9, $$);
|
||||||
}
|
}
|
||||||
|
|
||||||
# parent
|
# parent
|
||||||
@ -598,7 +633,7 @@ sub fork_worker {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
POSIX::close($csync[1]);
|
POSIX::close($csync[1]);
|
||||||
kill (9, $cpid); # make sure it gets killed
|
kill(-9, $cpid); # make sure it gets killed
|
||||||
die $err;
|
die $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,12 +689,10 @@ sub fork_worker {
|
|||||||
if ($outfh) {
|
if ($outfh) {
|
||||||
print $outfh "TASK ERROR: $err\n";
|
print $outfh "TASK ERROR: $err\n";
|
||||||
}
|
}
|
||||||
kill (-15, $cpid);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
kill (-9, $cpid); # make sure it gets killed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&$kill_process_group($cpid, $pstart); # make sure it gets killed
|
||||||
|
|
||||||
close($outfh);
|
close($outfh);
|
||||||
|
|
||||||
waitpid($cpid, 0);
|
waitpid($cpid, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user