public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Jonas Theisen <j.theisen@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH widget-toolkit 10/16] node: time: add button to synchronize the clock immediately
Date: Thu, 26 Nov 2026 14:40:07 +0100	[thread overview]
Message-ID: <20261126134128.316681-11-j.theisen@proxmox.com> (raw)
In-Reply-To: <20261126134128.316681-1-j.theisen@proxmox.com>

Add a "Sync now" button to the time view, so admins can synchronize
the clock right away, for example after changing the NTP servers.

It asks for confirmation first, as the clock may jump or the service
may be restarted. If the API reports that the node is part of a
cluster, the confirmation warns about the consequences and the
synchronization can only be started after explicitly checking a box,
as clock jumps can severely disrupt services that rely on synchronized
clocks across all nodes, such as Ceph. Only then is the 'force'
parameter passed, which the API requires on cluster nodes.

The button is only shown if the API reports that the active time
synchronization service supports it, which also keeps it hidden for
products whose time API does not provide it.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/node/TimeView.js | 114 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 113 insertions(+), 1 deletion(-)

diff --git a/src/node/TimeView.js b/src/node/TimeView.js
index b2c4d68..0c08e31 100644
--- a/src/node/TimeView.js
+++ b/src/node/TimeView.js
@@ -55,6 +55,107 @@ Ext.define('Proxmox.node.TimeView', {
             handler: view_service_log,
         });
 
+        // the API refuses to synchronize a cluster node unless forced
+        let sync_now = (force) =>
+            Proxmox.Utils.API2Request({
+                url: `/nodes/${me.nodename}/time/sync`,
+                method: 'POST',
+                params: force ? { force: 1 } : {},
+                waitMsgTarget: me,
+                failure: (response) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
+                success: () => me.rstore.load(),
+            });
+
+        // Clock jumps can severely disrupt a cluster, so there the user has to explicitly
+        // acknowledge that before the synchronization can be started.
+        let confirm_sync = () => {
+            let clustered = !!me.rstore.getById('clustered')?.data.value;
+
+            let message = Ext.htmlEncode(
+                gettext(
+                    'Synchronize the system clock now? Depending on the configuration of the time synchronization service, the clock may jump instead of being adjusted gradually.',
+                ),
+            );
+            if (clustered) {
+                message +=
+                    '<br><br>' +
+                    Ext.htmlEncode(
+                        gettext(
+                            'This node is part of a cluster. Jumps of the system clock can severely disrupt services that rely on synchronized clocks across all nodes, such as Ceph.',
+                        ),
+                    );
+            }
+
+            let win = Ext.create('Ext.window.Window', {
+                title: gettext('Confirm'),
+                modal: true,
+                width: 450,
+                bodyPadding: 10,
+                buttonAlign: 'center',
+                layout: 'hbox',
+                items: [
+                    {
+                        xtype: 'component',
+                        cls: [
+                            Ext.baseCSSPrefix + 'message-box-icon',
+                            Ext.baseCSSPrefix + 'dlg-icon',
+                            Ext.baseCSSPrefix +
+                                (clustered ? 'message-box-warning' : 'message-box-question'),
+                        ],
+                    },
+                    {
+                        xtype: 'container',
+                        flex: 1,
+                        layout: {
+                            type: 'vbox',
+                            align: 'stretch',
+                        },
+                        items: [
+                            {
+                                xtype: 'component',
+                                html: message,
+                            },
+                            {
+                                xtype: 'checkbox',
+                                hidden: !clustered,
+                                margin: '10 0 0 0',
+                                boxLabel: gettext(
+                                    'I understand that a clock jump can disrupt the cluster.',
+                                ),
+                                listeners: {
+                                    change: (_checkbox, checked) =>
+                                        win.down('#confirmButton').setDisabled(!checked),
+                                },
+                            },
+                        ],
+                    },
+                ],
+                buttons: [
+                    {
+                        itemId: 'confirmButton',
+                        text: gettext('Sync now'),
+                        disabled: clustered,
+                        handler: () => {
+                            win.close();
+                            sync_now(clustered);
+                        },
+                    },
+                    {
+                        text: gettext('Cancel'),
+                        handler: () => win.close(),
+                    },
+                ],
+            });
+            win.show();
+        };
+
+        // only shown if the API reports that the NTP service supports it
+        let sync_btn = new Ext.Button({
+            text: gettext('Sync now'),
+            hidden: true,
+            handler: confirm_sync,
+        });
+
         let rows = {
             timezone: {
                 header: gettext('Time zone'),
@@ -93,6 +194,13 @@ Ext.define('Proxmox.node.TimeView', {
             'ntp-pools': {
                 visible: false,
             },
+            // the reader drops keys without a row, keep them in the store for the sync button
+            'ntp-sync-supported': {
+                visible: false,
+            },
+            clustered: {
+                visible: false,
+            },
             'ntp-synchronized': {
                 header: gettext('Clock synchronized'),
                 renderer: Proxmox.Utils.format_boolean,
@@ -113,6 +221,7 @@ Ext.define('Proxmox.node.TimeView', {
                     text: gettext('Edit'),
                     handler: run_editor,
                 },
+                sync_btn,
                 syslog_btn,
             ],
             listeners: {
@@ -128,7 +237,10 @@ Ext.define('Proxmox.node.TimeView', {
             }),
         );
 
-        me.mon(me.rstore, 'load', () => syslog_btn.setVisible(!!get_ntp_service()));
+        me.mon(me.rstore, 'load', () => {
+            syslog_btn.setVisible(!!get_ntp_service());
+            sync_btn.setVisible(!!me.rstore.getById('ntp-sync-supported')?.data.value);
+        });
 
         me.on('activate', me.rstore.startUpdate);
         me.on('deactivate', me.rstore.stopUpdate);
-- 
2.47.3





  parent reply	other threads:[~2026-11-26 13:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:39 [PATCH common/manager/widget-toolkit 00/16] partially fix #3809: configure and monitor NTP in the node time panel Jonas Theisen
2026-11-26 13:39 ` [PATCH common 01/16] systemd: add helpers to get and set NTP servers Jonas Theisen
2026-11-26 13:39 ` [PATCH common 02/16] systemd: add helper to query clock synchronization status Jonas Theisen
2026-11-26 13:40 ` [PATCH common 03/16] systemd: add helpers to synchronize the clock immediately Jonas Theisen
2026-11-26 13:40 ` [PATCH common 04/16] systemd: add helper to list the current NTP sources Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 05/16] node: time: do not open the editor for the server time row Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 06/16] partially fix #3809: node: time: show and edit NTP servers if supported Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 07/16] node: time: show clock synchronization status Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 08/16] window: add reusable service log window Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 09/16] node: time: add button to open the NTP service log Jonas Theisen
2026-11-26 13:40 ` Jonas Theisen [this message]
2026-11-26 13:40 ` [PATCH widget-toolkit 11/16] node: time: add window listing the current NTP sources Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 12/16] partially fix #3809: api: nodes: time: allow configuring NTP servers Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 13/16] api: nodes: time: report clock synchronization status Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 14/16] ui: node: time: use journal for the NTP service log Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 15/16] api: nodes: time: add endpoint to synchronize the clock immediately Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 16/16] api: nodes: time: add endpoint to list the current NTP sources Jonas Theisen

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=20261126134128.316681-11-j.theisen@proxmox.com \
    --to=j.theisen@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal