From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id A382E1FF0C1 for ; Fri, 18 Sep 2026 16:43:23 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0029C215EC; Fri, 18 Sep 2026 16:43:07 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager 10/10] pvescheduler: run cluster change hooks from a listener child Date: Fri, 18 Sep 2026 16:41:52 +0200 Message-ID: <20260918144152.575163-11-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918144152.575163-1-h.laimer@proxmox.com> References: <20260918144152.575163-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1789742533860 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.478 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust RCVD_IN_MSPIKE_H2 0.001 Average reputation (+2) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SLSZRKCOY2VK32676G33F2CWK7W75Q5B X-Message-ID-Hash: SLSZRKCOY2VK32676G33F2CWK7W75Q5B X-MailFrom: h.laimer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On HUP the listener is stopped rather than handed over, so the reloaded daemon runs the newly loaded hook modules. It is recorded under a separate marker, which frees the hook slot for its replacement to start immediately and still has the new daemon reap it, since reaping now covers every recorded job type rather than a fixed list. The listener keeps its position under /run, so the one started after a reload resumes where the stopped one left off. Around a reload the stopped listener may still be ending its runs while the new one starts, and both may hold a connection and record a position for that moment, which is safe since a recorded position only ever stands for completed runs. Signed-off-by: Hannes Laimer --- PVE/Service/pvescheduler.pm | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/PVE/Service/pvescheduler.pm b/PVE/Service/pvescheduler.pm index f7271fc0..7c773829 100755 --- a/PVE/Service/pvescheduler.pm +++ b/PVE/Service/pvescheduler.pm @@ -5,6 +5,8 @@ use warnings; use POSIX qw(WNOHANG); +use PVE::Cluster::Hooks; +use PVE::HookRunner; use PVE::Jobs; use PVE::SafeSyslog; @@ -17,8 +19,6 @@ my $cmdline = [$0, @ARGV]; my %daemon_options = (stop_wait_time => 180, max_workers => 0); my $daemon = __PACKAGE__->new('pvescheduler', $cmdline, %daemon_options); -my @JOB_TYPES = qw(replication jobs); - my sub running_job_pids : prototype($) { my ($self) = @_; my $pids = [map { keys $_->%* } values $self->{jobs}->%*]; @@ -27,7 +27,7 @@ my sub running_job_pids : prototype($) { my sub finish_jobs : prototype($) { my ($self) = @_; - for my $type (@JOB_TYPES) { + for my $type (keys $self->{jobs}->%*) { for my $cpid (keys $self->{jobs}->{$type}->%*) { if (my $waitpid = waitpid($cpid, WNOHANG)) { delete $self->{jobs}->{$type}->{$cpid} if $waitpid == $cpid || $waitpid == -1; @@ -40,8 +40,14 @@ sub hup { my ($self) = @_; my $old_workers = ""; - for my $type (@JOB_TYPES) { + for my $type (sort keys $self->{jobs}->%*) { my $worker = $self->{jobs}->{$type} // next; + # stopped rather than handed over, so the reload runs the new hook code + if ($type eq 'hooks') { + kill 'TERM', keys $worker->%*; + $old_workers .= "stopped:$_;" for keys $worker->%*; + next; + } $old_workers .= "$type:$_;" for keys $worker->%*; } $ENV{"PVE_DAEMON_WORKER_PIDS"} = $old_workers; @@ -118,6 +124,18 @@ sub run { }, ); + # only run while a hook is registered, unlike the other job types + if (scalar(PVE::Cluster::Hooks->hooks()->@*)) { + $fork->( + 'hooks', + sub { + PVE::HookRunner->new( + state => '/run/pvescheduler/hooks.seq', + )->run(); + }, + ); + } + $first_run = 0; }; -- 2.47.3