From d829be9e94c1cf8ccbc51ac2a7cc275d60c84a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 16 Jul 2026 01:41:38 -0300 Subject: [PATCH] fix(packaging): make xcatd callers init-agnostic --- perl-xCAT/debian/postrm | 4 +- perl-xCAT/perl-xCAT.spec | 4 +- xCAT-OpenStack/debian/postinst | 4 +- xCAT-OpenStack/xCAT-OpenStack.spec | 4 +- xCAT-UI/xCAT-UI.spec | 4 +- xCAT-rmc/debian/postinst | 4 +- xCAT-server/lib/xcat/plugins/imgport.pm | 5 +- xCAT-test/unit/xcatd_restart_callers.t | 90 +++++++++++++++++++++++++ xCATsn/debian/postinst | 6 +- xCATsn/xCATsn.spec | 11 ++- 10 files changed, 115 insertions(+), 21 deletions(-) create mode 100644 xCAT-test/unit/xcatd_restart_callers.t diff --git a/perl-xCAT/debian/postrm b/perl-xCAT/debian/postrm index e9d178f89..6b983d64c 100644 --- a/perl-xCAT/debian/postrm +++ b/perl-xCAT/debian/postrm @@ -21,9 +21,9 @@ set -e case "$1" in upgrade) - if [ -x /etc/init.d/xcatd ] && [ -f "/proc/cmdline" ]; then + if [ -x /opt/xcat/sbin/restartxcatd ] && [ -f "/proc/cmdline" ]; then . /etc/profile.d/xcat.sh - /etc/init.d/xcatd reload + XCATROOT=/opt/xcat /opt/xcat/sbin/restartxcatd -r fi ;; purge|remove|failed-upgrade|abort-install|abort-upgrade|disappear) diff --git a/perl-xCAT/perl-xCAT.spec b/perl-xCAT/perl-xCAT.spec index 59aa744c2..aad2d042e 100644 --- a/perl-xCAT/perl-xCAT.spec +++ b/perl-xCAT/perl-xCAT.spec @@ -136,8 +136,8 @@ fi %post %ifos linux -if [ "$1" -gt 1 ]; then #Ugrade only, restart daemon and migrate settings - if [ -x /etc/init.d/xcatd ] && [ -f "/proc/cmdline" ]; then +if [ "$1" -gt 1 ]; then #Upgrade only; load the xCAT environment when the server is installed. + if [ -x $RPM_INSTALL_PREFIX0/sbin/xcatd ] && [ -f "/proc/cmdline" ]; then . /etc/profile.d/xcat.sh fi fi diff --git a/xCAT-OpenStack/debian/postinst b/xCAT-OpenStack/debian/postinst index 3e90d7ca7..8f9d4056e 100644 --- a/xCAT-OpenStack/debian/postinst +++ b/xCAT-OpenStack/debian/postinst @@ -21,8 +21,8 @@ set -e case "$1" in configure) if [ -f "/proc/cmdline" ];then - if [ -f "/opt/xcat/sbin/xcatd" ];then - /etc/init.d/xcatd reload + if [ -x /opt/xcat/sbin/restartxcatd ];then + XCATROOT=/opt/xcat /opt/xcat/sbin/restartxcatd -r fi fi ;; diff --git a/xCAT-OpenStack/xCAT-OpenStack.spec b/xCAT-OpenStack/xCAT-OpenStack.spec index a502b20d5..398bfdd09 100644 --- a/xCAT-OpenStack/xCAT-OpenStack.spec +++ b/xCAT-OpenStack/xCAT-OpenStack.spec @@ -87,8 +87,8 @@ rm -rf $RPM_BUILD_ROOT %post %ifos linux if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image - if [ -f $RPM_INSTALL_PREFIX0/sbin/xcatd ]; then - /etc/init.d/xcatd restart + if [ -x $RPM_INSTALL_PREFIX0/sbin/restartxcatd ]; then + XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/restartxcatd fi fi %endif diff --git a/xCAT-UI/xCAT-UI.spec b/xCAT-UI/xCAT-UI.spec index a39fb564c..4a3e980c9 100644 --- a/xCAT-UI/xCAT-UI.spec +++ b/xCAT-UI/xCAT-UI.spec @@ -184,7 +184,9 @@ ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT%{prefix}/bin/webportal if [ "$1" = 1 ] || [ "$1" = 2 ] # Install or upgrade then # Restart xCAT - /etc/init.d/xcatd restart + if [ -x $RPM_INSTALL_PREFIX0/sbin/restartxcatd ]; then + XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/restartxcatd + fi # Copy php.ini file into /opt/xcat/ui and turn off output_buffering if [ -e "/etc/redhat-release" ]; then diff --git a/xCAT-rmc/debian/postinst b/xCAT-rmc/debian/postinst index 01078ef32..3d40f8920 100644 --- a/xCAT-rmc/debian/postinst +++ b/xCAT-rmc/debian/postinst @@ -58,8 +58,8 @@ case "$1" in if [[ `uname -s` = "Linux" ]] ; then if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image - if [ -f /opt/xcat/sbin/xcatd ]; then - /etc/init.d/xcatd reload + if [ -x /opt/xcat/sbin/restartxcatd ]; then + XCATROOT=/opt/xcat /opt/xcat/sbin/restartxcatd -r fi fi else diff --git a/xCAT-server/lib/xcat/plugins/imgport.pm b/xCAT-server/lib/xcat/plugins/imgport.pm index 620d7cf49..cf8b9cdd8 100644 --- a/xCAT-server/lib/xcat/plugins/imgport.pm +++ b/xCAT-server/lib/xcat/plugins/imgport.pm @@ -1990,8 +1990,8 @@ sub make_files { } if ($hasplugin) { - # Issue xcatd reload to load the new plugins - system("/etc/init.d/xcatd restart"); + # Fast restart xcatd to load the new plugins without dropping this request + system("$::XCATROOT/sbin/restartxcatd"); $hasplugin = 0; } @@ -2230,4 +2230,3 @@ sub moveExtra { } return 1; } - diff --git a/xCAT-test/unit/xcatd_restart_callers.t b/xCAT-test/unit/xcatd_restart_callers.t new file mode 100644 index 000000000..2cfdf73f5 --- /dev/null +++ b/xCAT-test/unit/xcatd_restart_callers.t @@ -0,0 +1,90 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Spec; +use FindBin; +use Test::More; + +my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); + +sub read_file { + my ($path) = @_; + open( my $fh, '<', $path ) or die "Unable to read $path: $!"; + my $contents = do { local $/; <$fh> }; + close($fh); + return $contents; +} + +my $unit = read_file( + File::Spec->catfile( $repo_root, 'xCAT-server', 'etc', 'init.d', 'xcatd.service' ) +); +unlike( $unit, qr{/etc/init\.d/xcatd}, + 'the native systemd unit does not invoke the legacy script' ); +like( $unit, qr{^ExecStart=.*?/usr/sbin/xcatd}m, + 'the native systemd unit starts xcatd directly' ); + +my $imgport = read_file( + File::Spec->catfile( $repo_root, 'xCAT-server', 'lib', 'xcat', 'plugins', 'imgport.pm' ) +); +like( $imgport, qr{system\("\$::XCATROOT/sbin/restartxcatd"\)}, + 'imgport preserves the xcatd fast-restart path' ); +unlike( $imgport, qr{xCAT::Utils->restartservice\("xcatd"\)}, + 'imgport does not replace a fast restart with a full service restart' ); +unlike( $imgport, qr{system\("/etc/init\.d/xcatd}, + 'imgport no longer hard-codes the legacy init path' ); + +my %reload_callers = ( + 'xCAT-OpenStack Debian scriptlet' => 'xCAT-OpenStack/debian/postinst', + 'xCAT-rmc Debian scriptlet' => 'xCAT-rmc/debian/postinst', + 'perl-xCAT Debian scriptlet' => 'perl-xCAT/debian/postrm', +); + +foreach my $name ( sort keys %reload_callers ) { + my $caller = read_file( + File::Spec->catfile( $repo_root, split( '/', $reload_callers{$name} ) ) + ); + like( $caller, qr{/sbin/restartxcatd -r}, + "$name preserves xcatd fast-reload semantics" ); + unlike( $caller, qr{systemctl restart xcatd|/etc/init\.d/xcatd}, + "$name does not perform a full restart or require the legacy init path" ); +} + +my %restart_callers = ( + 'xCAT-OpenStack RPM scriptlet' => 'xCAT-OpenStack/xCAT-OpenStack.spec', + 'xCAT-UI RPM scriptlet' => 'xCAT-UI/xCAT-UI.spec', +); + +foreach my $name ( sort keys %restart_callers ) { + my $caller = read_file( + File::Spec->catfile( $repo_root, split( '/', $restart_callers{$name} ) ) + ); + like( $caller, qr{/sbin/restartxcatd}, + "$name preserves xcatd fast-restart semantics" ); + unlike( $caller, qr{systemctl restart xcatd|/etc/init\.d/xcatd}, + "$name does not perform a full restart or require the legacy init path" ); +} + +my $xcatsn_deb = read_file( + File::Spec->catfile( $repo_root, 'xCATsn', 'debian', 'postinst' ) +); +like( $xcatsn_deb, + qr{systemctl start xcatd\.service.*?elif \[ -x /etc/init\.d/xcatd \]}s, + 'xCATsn Debian starts xcatd under the native service manager' ); + +my $xcatsn_spec = read_file( + File::Spec->catfile( $repo_root, 'xCATsn', 'xCATsn.spec' ) +); +like( $xcatsn_spec, + qr{systemctl restart xcatd\.service.*?elif \[ -x /etc/init\.d/xcatd \]}s, + 'xCATsn RPM retains its existing service-node restart with a legacy fallback' ); + +my $perl_xcat_spec = read_file( + File::Spec->catfile( $repo_root, 'perl-xCAT', 'perl-xCAT.spec' ) +); +unlike( $perl_xcat_spec, qr{/etc/init\.d/xcatd}, + 'perl-xCAT upgrade logic no longer assumes the legacy init path exists' ); +like( $perl_xcat_spec, qr{\$RPM_INSTALL_PREFIX0/sbin/xcatd}, + 'perl-xCAT detects the installed server independently of its init system' ); + +done_testing(); diff --git a/xCATsn/debian/postinst b/xCATsn/debian/postinst index 08f9629fa..c7056f716 100644 --- a/xCATsn/debian/postinst +++ b/xCATsn/debian/postinst @@ -57,7 +57,11 @@ case "$1" in update-rc.d $apachedaemon enable if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image - XCATROOT=/opt/xcat /etc/init.d/xcatd start + if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then + systemctl start xcatd.service + elif [ -x /etc/init.d/xcatd ]; then + XCATROOT=/opt/xcat /etc/init.d/xcatd start + fi /etc/init.d/$apachedaemon reload fi echo "xCATsn is now installed" diff --git a/xCATsn/xCATsn.spec b/xCATsn/xCATsn.spec index b184bc02e..df175b7a0 100644 --- a/xCATsn/xCATsn.spec +++ b/xCATsn/xCATsn.spec @@ -224,12 +224,11 @@ if [ -e "/etc/redhat-release" ]; then else # SuSE apachedaemon='apache2' fi -# start xcatd on linux +# enable and reload the web server on linux [ -e "/etc/init.d/$apachedaemon" ] && chkconfig $apachedaemon on [ -e "/usr/lib/systemd/system/$apacheserviceunit" ] && systemctl enable $apacheserviceunit # prevent running it during install into chroot image if [ -f "/proc/cmdline" ] && [ "x$(stat -c '%i %d' /)" == "x$(stat -c '%i %d' /proc/1/root/. 2>/dev/null)" ]; then - XCATROOT=$RPM_INSTALL_PREFIX0 /etc/init.d/xcatd restart [ -e "/etc/init.d/$apachedaemon" ] && /etc/init.d/$apachedaemon reload [ -e "/usr/lib/systemd/system/$apacheserviceunit" ] && systemctl reload $apacheserviceunit fi @@ -266,10 +265,10 @@ fi # running system (skip the genimage/diskless chroot, where there is no systemd), and start via # systemctl: on EL10 the SysV path (/etc/init.d/xcatd) cannot start xcatd. if [ -f "/proc/cmdline" ] && [ "x$(stat -c '%i %d' /)" == "x$(stat -c '%i %d' /proc/1/root/. 2>/dev/null)" ]; then - if command -v systemctl >/dev/null 2>&1; then - systemctl restart xcatd - else - service xcatd restart + if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then + systemctl restart xcatd.service + elif [ -x /etc/init.d/xcatd ]; then + XCATROOT=$RPM_INSTALL_PREFIX0 /etc/init.d/xcatd restart fi fi %endif