2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-07-29 09:09:38 +00:00

fix(packaging): make xcatd callers init-agnostic

This commit is contained in:
Vinícius Ferrão
2026-07-16 01:41:38 -03:00
parent ec751f07a5
commit d829be9e94
10 changed files with 115 additions and 21 deletions
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
;;
+2 -2
View File
@@ -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
+3 -1
View File
@@ -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
+2 -2
View File
@@ -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
+2 -3
View File
@@ -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;
}
+90
View File
@@ -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();
+5 -1
View File
@@ -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"
+5 -6
View File
@@ -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