mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-27 11:44:45 +00:00
Daemon: also terminate old_workers on stop
This commit is contained in:
parent
8826037040
commit
f3a33995cd
@ -191,26 +191,34 @@ my $terminate_server = sub {
|
|||||||
eval { $self->shutdown(); };
|
eval { $self->shutdown(); };
|
||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
|
|
||||||
# we have workers - terminate them
|
# we have workers - send TERM signal
|
||||||
|
|
||||||
foreach my $cpid (keys %{$self->{workers}}) {
|
foreach my $cpid (keys %{$self->{workers}}) {
|
||||||
kill(15, $cpid); # TERM childs
|
kill(15, $cpid); # TERM childs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# if configured, leave children running on HUP
|
||||||
return if $self->{got_hup_signal} &&
|
return if $self->{got_hup_signal} &&
|
||||||
$self->{leave_children_open_on_reload};
|
$self->{leave_children_open_on_reload};
|
||||||
|
|
||||||
|
# else, send TERM to old workers
|
||||||
|
foreach my $cpid (keys %{$self->{old_workers}}) {
|
||||||
|
kill(15, $cpid); # TERM childs
|
||||||
|
}
|
||||||
|
|
||||||
# nicely shutdown childs (give them max 10 seconds to shut down)
|
# nicely shutdown childs (give them max 10 seconds to shut down)
|
||||||
my $previous_alarm = alarm(10);
|
my $previous_alarm = alarm(10);
|
||||||
eval {
|
eval {
|
||||||
local $SIG{ALRM} = sub { die "timeout\n" };
|
local $SIG{ALRM} = sub { die "timeout\n" };
|
||||||
|
|
||||||
while ((my $pid = waitpid (-1, 0)) > 0) {
|
while ((my $pid = waitpid (-1, 0)) > 0) {
|
||||||
if (defined($self->{workers}->{$pid})) {
|
foreach my $id (qw(workers old_workers)) {
|
||||||
delete($self->{workers}->{$pid});
|
if (defined($self->{$id}->{$pid})) {
|
||||||
|
delete($self->{$id}->{$pid});
|
||||||
syslog('info', "worker $pid finished");
|
syslog('info', "worker $pid finished");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
alarm(0); # avoid race condition
|
alarm(0); # avoid race condition
|
||||||
};
|
};
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
@ -219,16 +227,18 @@ my $terminate_server = sub {
|
|||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
syslog('err', "error stopping workers (will kill them now) - $err");
|
syslog('err', "error stopping workers (will kill them now) - $err");
|
||||||
foreach my $cpid (keys %{$self->{workers}}) {
|
foreach my $id (qw(workers old_workers)) {
|
||||||
|
foreach my $cpid (keys %{$self->{$id}}) {
|
||||||
# KILL childs still alive!
|
# KILL childs still alive!
|
||||||
if (kill (0, $cpid)) {
|
if (kill (0, $cpid)) {
|
||||||
delete($self->{workers}->{$cpid});
|
delete($self->{$id}->{$cpid});
|
||||||
syslog("err", "kill worker $cpid");
|
syslog("err", "kill worker $cpid");
|
||||||
kill(9, $cpid);
|
kill(9, $cpid);
|
||||||
# fixme: waitpid?
|
# fixme: waitpid?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
my $server_run = sub {
|
my $server_run = sub {
|
||||||
|
Loading…
Reference in New Issue
Block a user