192 lines
6.1 KiB
Plaintext
Executable File
192 lines
6.1 KiB
Plaintext
Executable File
#
|
|
# Run xCAT post install
|
|
#
|
|
export MASTER_IP="#XCATVAR:XCATMASTER#"
|
|
export MASTER_IPS="#XCATVAR:XCATMASTER#"
|
|
export MASTER="#XCATVAR:XCATMASTER#"
|
|
export NODESTATUS="#XCATVAR:NODESTATUS#"
|
|
export INSTALLDIR=#TABLE:site:key=installdir:value#
|
|
export TFTPDIR=#TABLE:site:key=tftpdir:value#
|
|
if [ -z "$INSTALLDIR" ]; then
|
|
INSTALLDIR="/install"
|
|
fi
|
|
if [ -z "$TFTPDIR" ]; then
|
|
|
|
TFTPDIR="/tftpboot"
|
|
fi
|
|
|
|
cd /tmp
|
|
RAND=$(perl -e 'print int(rand(50)). "\n"')
|
|
sleep $RAND
|
|
for t in $(seq 1 20)
|
|
do
|
|
GOTIT=0
|
|
for i in $MASTER_IPS
|
|
do
|
|
wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -e robots=off -nH --cut-dirs=2 --reject "index.html*" --no-parent -t 0 -T 60 http://$i$INSTALLDIR/postscripts/ -P /xcatpost
|
|
if [ "$?" = "0" ]
|
|
then
|
|
|
|
rm -rf /xcatpost/mypostscript
|
|
export NODE=#TABLE:nodelist:THISNODE:node#
|
|
wget -N --waitretry=10 --random-wait -T 60 http://$i$TFTPDIR/mypostscripts/mypostscript.$NODE -P /xcatpost 2> /tmp/wget.log
|
|
mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript
|
|
|
|
if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the next bit
|
|
exit 1
|
|
fi
|
|
USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images
|
|
export USEOPENSSLFORXCAT
|
|
XCATSERVER=$i:3001
|
|
export XCATSERVER
|
|
|
|
# If mypostscript doesn't exist, we will get it through getpostscript.awk
|
|
if [ ! -x /xcatpost/mypostscript ]; then
|
|
|
|
chmod +x /xcatpost/*
|
|
/xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/</</g' -e 's/>/>/g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript
|
|
|
|
|
|
MYCONT=`grep MASTER /xcatpost/mypostscript`
|
|
MAX_RETRIES=10
|
|
RETRY=0
|
|
while [ -z "$MYCONT" ]; do
|
|
RETRY=$(($RETRY+1))
|
|
if [ $RETRY -eq $MAX_RETRIES ]
|
|
then
|
|
break
|
|
fi
|
|
|
|
let SLI=$RANDOM%10+10
|
|
sleep $SLI
|
|
/xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/</</g' -e 's/>/>/g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript
|
|
|
|
MYCONT=`grep MASTER /xcatpost/mypostscript`
|
|
done
|
|
|
|
fi
|
|
|
|
chmod +x /xcatpost/mypostscript
|
|
GOTIT=1
|
|
break
|
|
fi
|
|
done
|
|
if [ "$GOTIT" = "1" ]
|
|
then
|
|
#save the master to /opt/xcat/xcatinfo file
|
|
if [ ! -f /opt/xcat/xcatinfo ]; then
|
|
mkdir -p /opt/xcat
|
|
touch /opt/xcat/xcatinfo
|
|
fi
|
|
echo "XCATSERVER=$i" > /opt/xcat/xcatinfo
|
|
break
|
|
fi
|
|
RAND=$(perl -e 'print int(rand(5)). "\n"')
|
|
sleep $RAND
|
|
done
|
|
echo "INSTALLDIR=$INSTALLDIR" >> /opt/xcat/xcatinfo
|
|
|
|
#echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo
|
|
cd /xcatpost
|
|
#gunzip xcatpost.tar.gz
|
|
#tar -xvf xcatpost.tar
|
|
#/xcatpost/#TABLE:nodelist:THISNODE:node#
|
|
export PATH=$PATH:/xcatpost
|
|
|
|
# use the run_ps subroutine to run the postscripts
|
|
TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript`
|
|
echo "
|
|
# global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed
|
|
return_value=0
|
|
# subroutine used to run postscripts
|
|
run_ps () {
|
|
local ret_local=0
|
|
logdir=\"/var/log/xcat\"
|
|
mkdir -p \$logdir
|
|
logfile=\"/var/log/xcat/xcat.log\"
|
|
|
|
if [ -f \$1 ]; then
|
|
echo "\"\`date\` Running postscript: \$@\"" | tee -a \$logfile
|
|
#./\$@ 2>&1 1> /tmp/tmp4xcatlog
|
|
#cat /tmp/tmp4xcatlog | tee -a \$logfile
|
|
./\$@ 2>&1 | tee -a \$logfile
|
|
ret_local=\${PIPESTATUS[0]}
|
|
if [ \"\$ret_local\" -ne \"0\" ]; then
|
|
return_value=\$ret_local
|
|
fi
|
|
else
|
|
echo "\"\`date\` Postscript \$1 does NOT exist.\"" | tee -a \$logfile
|
|
return_value=-1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
# subroutine end
|
|
|
|
" > /xcatpost/mypostscript
|
|
echo "$TMP" >> /xcatpost/mypostscript
|
|
TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript`
|
|
echo "$TMP" > /xcatpost/mypostscript
|
|
|
|
|
|
#save the postboot scripts to /xcatpost/mypostscript.post
|
|
TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ d" /xcatpost/mypostscript`
|
|
echo "$TMP" > /xcatpost/mypostscript.post
|
|
chmod 755 /xcatpost/mypostscript.post
|
|
|
|
#create the post init
|
|
cat >/etc/init.d/xcatpostinit1 << 'EOF'
|
|
#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatpostinit1#
|
|
EOF
|
|
chmod 755 /etc/init.d/xcatpostinit1
|
|
ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc3.d/S84xcatpostinit1
|
|
ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc4.d/S84xcatpostinit1
|
|
ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc5.d/S84xcatpostinit1
|
|
mkdir -p /opt/xcat
|
|
cat >/opt/xcat/xcatinstallpost << 'EOF'
|
|
#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost#
|
|
if [ -f /xcatpost/mypostscript.post ]; then
|
|
RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2`
|
|
fi
|
|
if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then
|
|
chkconfig xcatpostinit1 off
|
|
fi
|
|
#echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo
|
|
EOF
|
|
chmod 755 /opt/xcat/xcatinstallpost
|
|
|
|
export OSVER=#TABLE:nodetype:THISNODE:os#
|
|
if [[ $OSVER == sles* ]]; then
|
|
if [[ $OSVER == sles10* ]];then
|
|
/sbin/insserv xcatpostinit1
|
|
else
|
|
/sbin/insserv -p /etc/init.d xcatpostinit1
|
|
fi
|
|
fi
|
|
#chkconfig --add xcatpostinit1
|
|
chkconfig xcatpostinit1 on
|
|
|
|
#create the dskls post
|
|
cat >/opt/xcat/xcatdsklspost << 'EOF'
|
|
#INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatdsklspost#
|
|
EOF
|
|
chmod 755 /opt/xcat/xcatdsklspost
|
|
|
|
#only run the prebooot scripts here
|
|
TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" /xcatpost/mypostscript`
|
|
echo "$TMP" > /xcatpost/mypostscript
|
|
|
|
export NODE=#TABLE:nodelist:THISNODE:node#
|
|
export ARCH=#TABLE:nodetype:THISNODE:arch#
|
|
addsiteyum
|
|
/xcatpost/mypostscript
|
|
sed -i 's/^serial/#serial/' /boot/grub/grub.conf
|
|
sed -i 's/^terminal/#terminal/' /boot/grub/grub.conf
|
|
|
|
#the following command should always be run to prevent infinite installation loops
|
|
updateflag.awk $MASTER 3002
|
|
|
|
cd /
|
|
#rm -Rf /xcatpost
|
|
#rm -f /xcatpost/mypostscript
|