From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 786151FF0B3 for ; Thu, 26 Nov 2026 14:43:55 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 561C12176D; Thu, 26 Nov 2026 14:43:03 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH manager 15/16] api: nodes: time: add endpoint to synchronize the clock immediately Date: Thu, 26 Nov 2026 14:40:12 +0100 Message-ID: <20261126134128.316681-16-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126134128.316681-1-j.theisen@proxmox.com> References: <20261126134128.316681-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795700529592 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.066 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 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: GLCCUTI3UXE6II2VKUOYKNN6BKWEMMP5 X-Message-ID-Hash: GLCCUTI3UXE6II2VKUOYKNN6BKWEMMP5 X-MailFrom: j.theisen@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: Allow triggering an immediate synchronization of the system clock via the active time synchronization service, and report whether that service supports it, so clients can decide whether to offer it. If the node is part of a cluster, a jump of the clock can severely disrupt services that rely on synchronized clocks across all nodes, such as Ceph. So the endpoint refuses to synchronize there unless the new 'force' parameter is set. The time endpoint also reports whether the node is part of a cluster, so clients can ask for an explicit acknowledgement before forcing the synchronization. Signed-off-by: Jonas Theisen --- Notes: This depends on the clock synchronization helpers in PVE::Systemd from pve-common. PVE/API2/Nodes.pm | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index 819114c5..dd5d0840 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -20,6 +20,7 @@ use PVE::APLInfo; use PVE::AccessControl; use PVE::Ceph::Releases; use PVE::Cluster qw(cfs_read_file); +use PVE::Corosync; use PVE::DataCenterConfig; use PVE::Exception qw(raise raise_perm_exc raise_param_exc); use PVE::Firewall; @@ -1756,6 +1757,18 @@ __PACKAGE__->register_method({ type => 'boolean', optional => 1, }, + 'ntp-sync-supported' => { + description => "Whether the active time synchronization service supports" + . " synchronizing the clock immediately, see 'time/sync'.", + type => 'boolean', + optional => 1, + }, + clustered => { + description => "Whether the node is part of a cluster, where jumps of the clock" + . " can disrupt the cluster, so 'time/sync' requires 'force'.", + type => 'boolean', + optional => 1, + }, 'ntp-synchronized' => { description => "Whether the system clock is synchronized, independent of the" . " time synchronization service in use. Not set if the status cannot be" @@ -1799,6 +1812,8 @@ __PACKAGE__->register_method({ if (my $service = PVE::Systemd::get_ntp_service()) { $res->{'ntp-service'} = $service; $res->{'ntp-pools-supported'} = PVE::Systemd::is_ntp_pools_supported($service); + $res->{'ntp-sync-supported'} = PVE::Systemd::is_ntp_sync_supported($service); + $res->{clustered} = PVE::Corosync::check_conf_exists(1) ? 1 : 0; if (my $sources = PVE::Systemd::get_ntp_servers()) { for my $type ('servers', 'pools') { my $addresses = $sources->{$type}; @@ -1892,6 +1907,50 @@ __PACKAGE__->register_method({ }, }); +__PACKAGE__->register_method({ + name => 'sync_time', + path => 'time/sync', + method => 'POST', + description => "Synchronize the system clock with the NTP servers immediately. Supported" + . " for chrony, which is triggered at runtime, and systemd-timesyncd, which is restarted." + . " Whether the clock is stepped or adjusted gradually depends on the configuration of" + . " the service, for chrony on its 'makestep' directive.", + permissions => { + check => ['perm', '/nodes/{node}', ['Sys.Modify']], + }, + proxyto => 'node', + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + force => { + description => "Synchronize even though the node is part of a cluster. Required" + . " there, as jumps of the clock can severely disrupt services that rely on" + . " synchronized clocks across all nodes, such as Ceph.", + type => 'boolean', + optional => 1, + default => 0, + }, + }, + }, + returns => { type => "null" }, + code => sub { + my ($param) = @_; + + raise_param_exc({ + force => "the node is part of a cluster, where a jump of the clock can severely" + . " disrupt services that rely on synchronized clocks, set 'force' to" + . " synchronize anyway", + }) + if !$param->{force} && PVE::Corosync::check_conf_exists(1); + + PVE::Systemd::sync_ntp(); + + return; + }, +}); + __PACKAGE__->register_method({ name => 'aplinfo', path => 'aplinfo', -- 2.47.3