2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-21 07:08:12 +00:00

refactor(postscripts): share the early postinit disable policy

Embed one helper in the legacy and systemd postboot runners. Keep each
caller policy and disable the service before running postscripts.
This commit is contained in:
Vinícius Ferrão
2026-10-10 02:25:59 -03:00
parent 9ed42c0b26
commit a987cfbd10
4 changed files with 49 additions and 77 deletions
@@ -358,38 +358,10 @@ fi
mkdir -p /opt/xcat
cat >/opt/xcat/xcatinstallpost << 'EOF'
#!/bin/bash
# Disable the xcatpostinit1 service *before* running the postscripts (the
# INCLUDE at the end). If a postscript reboots the node, the service is
# already disabled, so the whole postscript set is not run again on reboot.
# The disable decision needs OSVER, RUNBOOTSCRIPTS and NODESTATUS, which the
# included script would otherwise set; read them up front (it re-reads them),
# and source xcatlib.sh so msgutil_r is available for the debug messages.
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/postinit.sh#
[ -f /xcatpost/xcatlib.sh ] && . /xcatpost/xcatlib.sh
if [ -f /xcatpost/mypostscript.post ]; then
OSVER=`grep '^OSVER=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g`
RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g`
fi
[ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z `
[ -z "$NODESTATUS" ] && NODESTATUS="1"
if [[ $OSVER == ubuntu* ]]; then
if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then
update-rc.d -f xcatpostinit1 remove
fi
if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then
msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost"
fi
else
if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then
chkconfig xcatpostinit1 off
if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then
msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 disabled" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost"
fi
fi
fi
# Disable the service before a postscript can reboot the node.
xcat_disable_postinit legacy
#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost#
@@ -356,30 +356,10 @@ chmod 0755 /opt/xcat/xcatpostinit1
mkdir -p /opt/xcat
cat >/opt/xcat/xcatinstallpost <<'EOF'
#!/bin/bash
# Disable the xcatpostinit1 service *before* running the postscripts (the
# INCLUDE at the end). If a postscript reboots the node, the service is
# already disabled, so the whole postscript set is not run again on reboot.
# The disable decision needs RUNBOOTSCRIPTS and NODESTATUS, which the included
# script would otherwise set; read them up front (it re-reads them), and source
# xcatlib.sh so msgutil_r is available for the debug message.
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/postinit.sh#
[ -f /xcatpost/xcatlib.sh ] && . /xcatpost/xcatlib.sh
if [ -f /xcatpost/mypostscript.post ]
then
RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post | cut -d= -f2 | sed s/\'//g`
fi
[ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript | awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z`
[ -z "$NODESTATUS" ] && NODESTATUS="1"
if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then
systemctl disable xcatpostinit1.service
case "$XCATDEBUGMODE" in
"1"|"2")
msgutil_r "$MASTER_IP" "debug" "systemctl disable xcatpostinit1.service" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost"
;;
esac
fi
# Disable the service before a postscript can reboot the node.
xcat_disable_postinit systemd
#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost#
@@ -356,30 +356,10 @@ chmod 0755 /opt/xcat/xcatpostinit1
mkdir -p /opt/xcat
cat >/opt/xcat/xcatinstallpost <<'EOF'
#!/bin/bash
# Disable the xcatpostinit1 service *before* running the postscripts (the
# INCLUDE at the end). If a postscript reboots the node, the service is
# already disabled, so the whole postscript set is not run again on reboot.
# The disable decision needs RUNBOOTSCRIPTS and NODESTATUS, which the included
# script would otherwise set; read them up front (it re-reads them), and source
# xcatlib.sh so msgutil_r is available for the debug message.
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/postinit.sh#
[ -f /xcatpost/xcatlib.sh ] && . /xcatpost/xcatlib.sh
if [ -f /xcatpost/mypostscript.post ]
then
RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post | cut -d= -f2 | sed s/\'//g`
fi
[ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript | awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z`
[ -z "$NODESTATUS" ] && NODESTATUS="1"
if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then
systemctl disable xcatpostinit1.service
case "$XCATDEBUGMODE" in
"1"|"2")
msgutil_r "$MASTER_IP" "debug" "systemctl disable xcatpostinit1.service" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost"
;;
esac
fi
# Disable the service before a postscript can reboot the node.
xcat_disable_postinit systemd
#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost#
@@ -0,0 +1,40 @@
xcat_disable_postinit()
{
if [ -f /xcatpost/mypostscript.post ]; then
if [ "$1" = legacy ]; then
OSVER=`grep '^OSVER=' /xcatpost/mypostscript.post | cut -d= -f2 | sed s/\'//g`
fi
RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z`
MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post | cut -d= -f2 | sed s/\'//g`
fi
[ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript | awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z`
[ -z "$NODESTATUS" ] && NODESTATUS="1"
case "$1:$OSVER" in
legacy:ubuntu*)
case "$RUNBOOTSCRIPTS" in
1|yes|y) ;;
*) update-rc.d -f xcatpostinit1 remove ;;
esac
case "$XCATDEBUGMODE" in
1|2) msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost" ;;
esac
;;
*)
case "$RUNBOOTSCRIPTS" in 1|yes|y) return 0 ;; esac
case "$NODESTATUS" in 1|yes|y) return 0 ;; esac
if [ "$1" = legacy ]; then
chkconfig xcatpostinit1 off
case "$XCATDEBUGMODE" in
1|2) msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 disabled" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost" ;;
esac
else
systemctl disable xcatpostinit1.service
case "$XCATDEBUGMODE" in
1|2) msgutil_r "$MASTER_IP" "debug" "systemctl disable xcatpostinit1.service" "/var/log/xcat/xcat.log" "xcat.xcatinstallpost" ;;
esac
fi
;;
esac
}