From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 3/3] pvescheduler: implement graceful reloading
Date: Thu, 18 Nov 2021 14:28:31 +0100 [thread overview]
Message-ID: <20211118132831.839774-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211118132831.839774-1-d.csapak@proxmox.com>
utilize PVE::Daemons 'hup' functionality to reload gracefully.
Leaves the children running (if any) and give them to the new instance
via ENV variables. After loading, check if they are still around
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
the only weird behaviour is that the re-exec can be up to one minute
after the reload, since we only get into the loop once a minute
we can shorten the loop cycle if we want though..
PVE/Service/pvescheduler.pm | 22 +++++++++++++++++++++-
services/pvescheduler.service | 1 +
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/PVE/Service/pvescheduler.pm b/PVE/Service/pvescheduler.pm
index 466cc599..700c96ec 100755
--- a/PVE/Service/pvescheduler.pm
+++ b/PVE/Service/pvescheduler.pm
@@ -24,19 +24,35 @@ my $finish_jobs = sub {
for my $type (@types) {
if (my $cpid = $self->{jobs}->{$type}) {
my $waitpid = waitpid($cpid, WNOHANG);
- if (defined($waitpid) && ($waitpid == $cpid)) {
+ if (defined($waitpid) && ($waitpid == $cpid) || $waitpid == -1) {
$self->{jobs}->{$type} = undef;
}
}
}
};
+sub hup {
+ my ($self) = @_;
+
+ for my $type (@types) {
+ my $pid = $self->{jobs}->{$type};
+ next if !defined($pid);
+ $ENV{"PVE_DAEMON_${type}_PID"} = $pid;
+ }
+}
+
sub run {
my ($self) = @_;
my $jobs = {};
$self->{jobs} = $jobs;
+ for my $type (@types) {
+ $self->{jobs}->{$type} = delete $ENV{"PVE_DAEMON_${type}_PID"};
+ # check if children finished in the meantime
+ $finish_jobs->($self);
+ }
+
my $old_sig_chld = $SIG{CHLD};
local $SIG{CHLD} = sub {
local ($@, $!, $?); # do not overwrite error vars
@@ -82,6 +98,8 @@ sub run {
for (my $count = 1000;;$count++) {
last if $self->{shutdown_request};
+ # we got a reload signal, return gracefully and leave the forks running
+ return if $self->{got_hup_signal};
$run_jobs->();
@@ -125,11 +143,13 @@ sub shutdown {
$daemon->register_start_command();
$daemon->register_stop_command();
+$daemon->register_restart_command(1);
$daemon->register_status_command();
our $cmddef = {
start => [ __PACKAGE__, 'start', []],
stop => [ __PACKAGE__, 'stop', []],
+ restart => [ __PACKAGE__, 'restart', []],
status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
};
diff --git a/services/pvescheduler.service b/services/pvescheduler.service
index 11769e80..e6f10832 100644
--- a/services/pvescheduler.service
+++ b/services/pvescheduler.service
@@ -8,6 +8,7 @@ After=pve-storage.target
[Service]
ExecStart=/usr/bin/pvescheduler start
ExecStop=/usr/bin/pvescheduler stop
+ExecReload=/usr/bin/pvescheduler restart
PIDFile=/var/run/pvescheduler.pid
KillMode=process
Type=forking
--
2.30.2
next prev parent reply other threads:[~2021-11-18 13:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 13:28 [pve-devel] [PATCH manager 1/3] pvescheduler: catch errors in forked childs Dominik Csapak
2021-11-18 13:28 ` [pve-devel] [PATCH manager 2/3] pvescheduler: reworking child pid tracking Dominik Csapak
2021-11-22 8:46 ` Fabian Ebner
2021-11-18 13:28 ` Dominik Csapak [this message]
2021-11-22 19:35 ` [pve-devel] applied-series: [PATCH manager 1/3] pvescheduler: catch errors in forked childs Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211118132831.839774-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox