diff --git a/perl-xCAT/xCAT/NTP/Backend.pm b/perl-xCAT/xCAT/NTP/Backend.pm index 71b5f868a..aac49081b 100644 --- a/perl-xCAT/xCAT/NTP/Backend.pm +++ b/perl-xCAT/xCAT/NTP/Backend.pm @@ -1,9 +1,8 @@ package xCAT::NTP::Backend; -# Selector for the NTP daemon xCAT configures on a node (chrony vs. ntpd), in the same spirit as -# xCAT::DHCP::Backend (ISC vs. Kea). makentp/setupntp support chronyd and ntpd only -- there is no -# systemd-timesyncd path (timesyncd is an SNTP client and cannot serve time to compute nodes), so an -# xCAT MN always needs chrony or ntpd. This module centralizes and unit-tests the choice. +# Selector for the NTP daemon xCAT configures (chrony vs. ntpd), in the same spirit as +# xCAT::DHCP::Backend. There is no timesyncd path: it is an SNTP client and cannot serve time to +# compute nodes, so an MN always needs chrony or ntpd. use strict; use warnings; @@ -33,8 +32,8 @@ sub normalize { # requested -- override (default: site.ntpbackend, else 'auto') # os_name/version -- OS identity (default: detected) # available -- optional { chrony => 0/1, ntpd => 0/1 } to bypass command detection (tests) -# check_available -- when true, downgrade chrony->ntpd (or ntpd->chrony) if the chosen one is -# absent but the other is present, and flag install=1 when neither is present. +# check_available -- when true, downgrade to whichever daemon is installed, and flag install=1 +# when neither is. sub choose { my ( $class, %args ) = @_; diff --git a/xCAT-test/unit/makentp_ntp_deps.t b/xCAT-test/unit/makentp_ntp_deps.t index 3716d852e..f4fbe4e29 100644 --- a/xCAT-test/unit/makentp_ntp_deps.t +++ b/xCAT-test/unit/makentp_ntp_deps.t @@ -6,14 +6,10 @@ use FindBin; use File::Temp qw(tempdir); use Test::More; -# setupntp configures a server-capable NTP daemon on the management node. On a stock Ubuntu MN -# three things went wrong: hwclock had moved to util-linux-extra and was absent, so the fatal -# executable check aborted the ENTIRE NTP setup including the clock step that does not use it; -# systemd-timesyncd was left running and kept disciplining the clock against the daemon being -# configured; and the xcat package did not pull in a daemon that can serve time at all. -# -# The first three are behaviours of the script, so run it. The last is a property of the -# packaging manifests, so read those. +# A stock Ubuntu MN broke three ways: a missing hwclock aborted the whole NTP setup, +# systemd-timesyncd kept fighting the daemon being configured, and the xcat package pulled in no +# daemon that can serve time. The first two are behaviours of the script, so run it; the third is +# a property of the packaging manifests, so read those. my $repo = "$FindBin::Bin/../.."; my $setupntp_path = "$repo/xCAT/postscripts/setupntp"; @@ -25,10 +21,9 @@ my @lines = <$fh>; close $fh; my $source = join '', @lines; -# setupntp forces its own PATH and refuses to run unless UID is 0, so its commands cannot be -# stubbed from outside and it cannot run as an ordinary user. Take the script's own helper -# functions and the section that configures the daemon, and drive them with shell functions -- -# which bash resolves ahead of PATH, and which `type` and `command -v` both report as present. +# setupntp forces its own PATH and exits unless UID is 0, so it cannot be stubbed from outside +# or run unprivileged. Drive its own helper functions with shell functions instead: bash resolves +# those ahead of PATH, and both `type` and `command -v` report them as present. my ($helpers) = $source =~ /\A(.*?)^\[ "\$\{UID\}" -eq "0" \]/ms; my ($body) = $source =~ /^(check_exec_or_exit cp cat logger grep\n.*?)^CHRONY_CONF=/ms; BAIL_OUT('could not take the helper functions from setupntp') unless $helpers; diff --git a/xCAT/postscripts/setupntp b/xCAT/postscripts/setupntp index 7de945790..2cc903ff3 100755 --- a/xCAT/postscripts/setupntp +++ b/xCAT/postscripts/setupntp @@ -146,9 +146,9 @@ unset MASTER unset NTPSERVERS check_exec_or_exit cp cat logger grep -# hwclock is NOT required: it only persists the (already chronyd-stepped) system clock to the RTC -# below, and it is optional -- on Ubuntu 24.04+ it moved to util-linux-extra, which is absent on -# minimal cloud images. Requiring it here aborted the whole NTP setup (and the clock step) on noble. +# hwclock is NOT required: it only persists the already-stepped clock to the RTC below, and on +# Ubuntu 24.04+ it moved to util-linux-extra, absent on minimal images. Requiring it here aborted +# the whole NTP setup, including the clock step that does not use it. check_exec_or_exit systemctl timedatectl systemctl stop ntp.service 2>/dev/null @@ -159,10 +159,8 @@ systemctl disable ntpd.service 2>/dev/null systemctl disable ntp-wait.service 2>/dev/null systemctl disable ntpdate.service 2>/dev/null -# systemd-timesyncd is an SNTP client that also disciplines the system clock. It is part of systemd -# (not a "time-daemon" package), so it coexists with chrony/ntpd at the package level but must be -# stopped or it fights the NTP daemon we are configuring. This is the default time-sync stack on -# Ubuntu, where it must yield to chrony (timesyncd cannot serve time to compute nodes). +# systemd-timesyncd ships as part of systemd rather than a time-daemon package, so nothing +# displaces it and it keeps disciplining the clock against the daemon being configured. systemctl stop systemd-timesyncd.service 2>/dev/null systemctl disable systemd-timesyncd.service 2>/dev/null