X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FDaemon.pm;h=55a03fca3eacbdc9d18c34de4fac50b366a0f8d6;hp=f81e589e3aca0433c25bf7a3e567fe9255463277;hb=0da5a3e43b1659431a6e0fa4e38583741d27dbbc;hpb=9db0800b69580b25d80ab2dd71e220651d4e399b diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm index f81e589..55a03fc 100644 --- a/src/PVE/Daemon.pm +++ b/src/PVE/Daemon.pm @@ -146,11 +146,7 @@ my $start_workers = sub { return if $self->{terminate}; - my $count = 0; - foreach my $cpid (keys %{$self->{workers}}) { - $count++; - } - + my $count = scalar keys %{$self->{workers}}; my $need = $self->{max_workers} - $count; return if $need <= 0; @@ -184,6 +180,13 @@ my $start_workers = sub { } }; +my $terminate_old_workers = sub { + my ($self) = @_; + + # if list is empty kill sends no signal, so no checks needed + kill 15, keys %{$self->{old_workers}}; +}; + my $terminate_server = sub { my ($self, $allow_open_children) = @_; @@ -198,20 +201,12 @@ my $terminate_server = sub { eval { $self->shutdown(); }; warn $@ if $@; - # we have workers - send TERM signal - - foreach my $cpid (keys %{$self->{workers}}) { - kill(15, $cpid); # TERM childs - } # if configured, leave children running on HUP - return if $allow_open_children && - $self->{leave_children_open_on_reload}; + return if $allow_open_children && $self->{leave_children_open_on_reload}; - # else, send TERM to old workers - foreach my $cpid (keys %{$self->{old_workers}}) { - kill(15, $cpid); # TERM childs - } + # else send TERM to all (old and current) child workers + kill 15, keys %{$self->@{'workers','old_workers'}}; # nicely shutdown childs (give them max 10 seconds to shut down) my $previous_alarm = alarm(10); @@ -290,11 +285,7 @@ sub setup { if ($restart && $self->{max_workers}) { if (my $wpids = $ENV{PVE_DAEMON_WORKER_PIDS}) { - foreach my $pid (split(':', $wpids)) { - if ($pid =~ m/^(\d+)$/) { - $self->{old_workers}->{$1} = 1; - } - } + $self->{old_workers}->{$_} = 1 foreach (split(':', $wpids)); } } @@ -395,13 +386,11 @@ my $server_run = sub { &$old_sig_chld(@_) if $old_sig_chld; }; - # catch worker finished during restart phase - &$finish_workers($self); - # now loop forever (until we receive terminate signal) for (;;) { &$start_workers($self); sleep(5); + &$terminate_old_workers($self); &$finish_workers($self); last if $self->{terminate}; } @@ -506,8 +495,7 @@ sub restart_daemon { } if ($self->{max_workers}) { - my @workers = keys %{$self->{workers}}; - push @workers, keys %{$self->{old_workers}}; + my @workers = keys %{$self->{workers}}, keys %{$self->{old_workers}}; $ENV{PVE_DAEMON_WORKER_PIDS} = join(':', @workers); } @@ -669,7 +657,7 @@ sub register_start_command { code => sub { my ($param) = @_; - if (&$init_ppid()) { + if (&$init_ppid() || $param->{debug}) { $self->start($param->{debug}); } else { PVE::Tools::run_command(['systemctl', 'start', $self->{name}]);