2007-10-26 22:44:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
for parm in `cat /proc/cmdline`; do
|
|
|
|
key=`echo $parm|awk -F= '{print $1}'`
|
|
|
|
if [ "$key" == "xcatd" ]; then
|
|
|
|
XCATDEST=`echo $parm|awk -F= '{print $2}'`
|
|
|
|
fi
|
|
|
|
done
|
2008-04-09 20:22:46 +00:00
|
|
|
export XCATPORT=3001
|
|
|
|
if [ ! -z "$XCATDEST" ]; then
|
|
|
|
export XCATMASTER=`echo $XCATDEST | awk -F: '{print $1}'`
|
|
|
|
export XCATPORT=`echo $XCATDEST | awk -F: '{print $2}'`
|
|
|
|
fi
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
while :; do
|
|
|
|
DESTINY=`grep destiny /tmp/destiny | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
|
|
|
|
DEST=`echo $DESTINY|awk -F= '{print $1}'` #No bash, no tricks
|
|
|
|
TARG=`echo $DESTINY|awk -F= '{print $2}'` #No bash, no tricks
|
|
|
|
DESTINY=`echo $DESTINY|awk '{print $1}'` #No bash, no tricks
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DESTINY" == "standby" ]; then
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Server notified us of standby condition, please check chain table".
|
2008-04-09 20:22:46 +00:00
|
|
|
let STSLEEP=15+$RANDOM%15
|
|
|
|
echo "Retrying destiny in $STSLEEP seconds"
|
|
|
|
sleep $STSLEEP # something may be transiently wrong, check back in 15 seconds
|
2007-10-31 03:42:29 +00:00
|
|
|
while ! getdestiny; do
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Retrying destiny retrieval"
|
2008-04-09 20:22:46 +00:00
|
|
|
let RTSLEEP=$RANDOM%5
|
|
|
|
sleep $RTSLEEP
|
2007-10-26 22:44:33 +00:00
|
|
|
done
|
2008-02-01 14:13:31 +00:00
|
|
|
exec /bin/dodestiny
|
2007-10-26 22:44:33 +00:00
|
|
|
fi
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DESTINY" == "shell" ]; then
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Server notified us to stay in shell state, stopping destiny requests"
|
2008-01-29 21:22:34 +00:00
|
|
|
while :; do /bin/sh; done #exit
|
2007-10-26 22:44:33 +00:00
|
|
|
fi
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DESTINY" == "discover" ]; then
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "MAC discovery begins"
|
|
|
|
minixcatd.awk &
|
2008-04-09 20:22:46 +00:00
|
|
|
sleep 1 #Mitigate occurrances of 'failed to notify node'
|
2007-10-26 22:44:33 +00:00
|
|
|
while [ ! -r /restart ]; do
|
2008-04-09 20:22:46 +00:00
|
|
|
let myr=$RANDOM%10
|
|
|
|
sleep $myr #Stagger discovery requests from many nodes
|
2007-10-26 22:44:33 +00:00
|
|
|
ifconfig -a|grep HWaddr|grep -v sit|awk '{print $1 "|" $5}'
|
2008-03-05 22:04:51 +00:00
|
|
|
sleep 1
|
2007-10-26 22:44:33 +00:00
|
|
|
MTM="unknown"
|
|
|
|
SERIAL="unknown"
|
2008-04-09 20:22:46 +00:00
|
|
|
ARCH="unknown"
|
|
|
|
if uname -m | grep i686 > /dev/null || uname -m | grep x86_64 > /dev/null; then
|
|
|
|
if grep ^flags /proc/cpuinfo |head -n 1|grep " lm " > /dev/null; then
|
|
|
|
ARCH=x86_64
|
|
|
|
else
|
|
|
|
ARCH=x86
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
ARCH=`uname -m`
|
|
|
|
fi
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
if [ -x /bin/vpddecode ]; then
|
|
|
|
MTM=`(/bin/vpddecode|grep Type || echo "unknown unknown: unknown")|awk '{print $3}'`
|
|
|
|
SERIAL=`(/bin/vpddecode|grep "Box Serial" || echo "unknown unknown unknown: unknown")|awk '{print $4}'`
|
|
|
|
fi
|
|
|
|
if [ "$MTM" == "unknown" -a -x /bin/dmidecode ]; then #This gets a bit hackish... iDataplex
|
|
|
|
MTM=`dmidecode |grep -A4 "^System Information"|grep "Product Name"|awk -F'[' '{print $2}'|awk -F']' '{print $1}'`
|
|
|
|
SERIAL=`dmidecode |grep -A4 "^System Information"|grep "Serial Number"|awk -F: '{print $2}'`
|
|
|
|
fi
|
|
|
|
if [ -r /proc/device-tree/model ]; then
|
|
|
|
MTM=`cat /proc/device-tree/model |awk -F, '{print $2}'`
|
|
|
|
fi
|
|
|
|
(
|
|
|
|
echo "<xcatrequest>"
|
|
|
|
echo "<command>findme</command>"
|
2008-04-09 20:22:46 +00:00
|
|
|
echo "<arch>$ARCH</arch>"
|
2007-10-26 22:44:33 +00:00
|
|
|
for i in `ifconfig -a|grep HWaddr|grep -v sit|awk '{print $1 "|" $5}'`; do
|
|
|
|
IFACE=`echo $i|awk -F'|' '{print $1}'`
|
|
|
|
DRIVER=`ethtool -i $IFACE|grep ^driver|awk '{print $2}'`
|
2008-01-14 19:13:43 +00:00
|
|
|
ADDRESS=`ip address show dev $IFACE|grep 'inet '|awk '{print $2}'`
|
|
|
|
echo "<mac>$DRIVER|$i|$ADDRESS</mac>"
|
2007-10-26 22:44:33 +00:00
|
|
|
done
|
|
|
|
modprobe ipmi_devintf
|
|
|
|
if modprobe ipmi_si; then
|
|
|
|
echo "<mac>bmc|bmc|"`ipmitool lan print 1|grep ^MAC|awk '{print $4}'`"</mac>"
|
|
|
|
fi
|
|
|
|
rmmod ipmi_si
|
|
|
|
rmmod ipmi_devintf
|
|
|
|
if [ "$MTM" != "unknown" ]; then
|
|
|
|
echo "<mtm>$MTM</mtm>"
|
|
|
|
fi
|
|
|
|
if [ "$SERIAL" != "unknown" ]; then
|
|
|
|
echo "<serial>$SERIAL</serial>"
|
|
|
|
fi
|
2007-10-31 03:42:29 +00:00
|
|
|
echo "</xcatrequest>" ) > /tmp/discout
|
2008-04-09 20:22:46 +00:00
|
|
|
if [ ! -z "$XCATMASTER" ]; then
|
|
|
|
ping -c 1 $XCATMASTER
|
|
|
|
cat /tmp/discout | udpcat.awk $XCATMASTER $XCATPORT & #can't figure out how to make a hung gawk behave..
|
|
|
|
fi
|
|
|
|
if [ -z "$XCATMASTER" ] || sleep 8 > /dev/null 2>&1 #Give the preferred method 8 seconds to complete before resorting
|
2007-10-31 04:24:22 +00:00
|
|
|
then
|
2008-04-09 20:22:46 +00:00
|
|
|
#if sleep succeeded, that means it wasn't killed and therefore, no answer yet
|
|
|
|
killall udpcat.awk > /dev/null 2>&1 #reap hung ones
|
2008-03-21 20:00:07 +00:00
|
|
|
for nic in `ifconfig -a|grep HWaddr|grep -v sit|awk '{print $1}'`; do #also, bring down interfaces to make sure that we send from the 'right' nic
|
2008-04-09 20:22:46 +00:00
|
|
|
MYB=`ifconfig $nic|grep "Bcast"|awk '{print $3}'|awk -F: '{print $2}'`
|
2008-03-21 20:00:07 +00:00
|
|
|
for dnic in `ifconfig -a|grep HWaddr|grep -v sit|awk '{print $1}'|grep -v $nic`; do
|
2008-04-09 20:22:46 +00:00
|
|
|
OTB=`ifconfig $dnic|grep "Bcast"|awk '{print $3}'|awk -F: '{print $2}'`
|
|
|
|
if [ "$OTB" == "$MYB" ]; then # if broadcasts match, down the other nic
|
|
|
|
ifconfig $dnic down
|
|
|
|
fi
|
2008-03-21 20:00:07 +00:00
|
|
|
done
|
2008-04-09 20:22:46 +00:00
|
|
|
if [ ! -z "$XCATMASTER" ]; then
|
|
|
|
(ping -c 1 $XCATMASTER
|
|
|
|
cat /tmp/discout | udpcat.awk $XCATMASTER $XCATPORT ) & #can't figure out how to make a hung gawk behave..
|
|
|
|
fi
|
2008-03-21 20:00:07 +00:00
|
|
|
for dhcps in `cat /tmp/dhcpserver`; do
|
2008-04-09 20:22:46 +00:00
|
|
|
( ping -c 1 $dhcps
|
|
|
|
cat /tmp/discout | udpcat.awk $dhcps $XCATPORT )&
|
2008-03-21 20:00:07 +00:00
|
|
|
done
|
|
|
|
for dnic in `ifconfig -a|grep HWaddr|grep -v sit|awk '{print $1}'|grep -v $nic`; do
|
|
|
|
ifconfig $dnic up
|
|
|
|
done
|
2008-04-09 20:22:46 +00:00
|
|
|
if ! sleep 5 > /dev/null 2>&1; then break; fi # give management server a chance to get to minixcatd.awk
|
2008-03-21 20:00:07 +00:00
|
|
|
done
|
2007-10-31 04:24:22 +00:00
|
|
|
fi
|
2008-04-09 20:22:46 +00:00
|
|
|
killall udpcat.awk > /dev/null 2>&1 #reap hung ones
|
2007-10-26 22:44:33 +00:00
|
|
|
done
|
|
|
|
#Discovery complete, restart requested.
|
|
|
|
exec /bin/restart
|
|
|
|
fi
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DESTINY" == "reboot" -o "$DESTINY" == "boot" ]; then
|
2007-10-31 03:42:29 +00:00
|
|
|
while ! nextdestiny ; do
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Retrying next destiny..."
|
|
|
|
done
|
|
|
|
reboot -f
|
|
|
|
fi
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DEST" == "runcmd" ]; then
|
2007-10-31 03:42:29 +00:00
|
|
|
while ! nextdestiny ; do
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Retrying next destiny..."
|
|
|
|
done
|
|
|
|
$TARG
|
|
|
|
fi
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DESTINY" == "install" -o "$DESTINY" == "netboot" ]; then
|
2008-02-21 20:09:41 +00:00
|
|
|
reboot -f #If script is here, kexec failed, reboot in case it wasn't a linux kernel and let the boot loader handle it instead
|
2007-10-26 22:44:33 +00:00
|
|
|
IMGSERVER=`grep imgserver /tmp/destiny | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
|
|
|
|
INITRD=`grep initrd /tmp/destiny | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
|
|
|
|
KERNEL=`grep kernel /tmp/destiny | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
|
|
|
|
KCMD=`grep kcmdline /tmp/destiny | awk -F'>' '{print $2}'|awk -F'<' '{print $1}'`
|
2008-03-04 21:15:40 +00:00
|
|
|
ERROR=`wget http://$IMGSERVER/tftpboot/$KERNEL -O /tmp/kernel 2>&1`
|
|
|
|
while [ $? == 1 ] && echo $ERROR|grep -v 416; do
|
|
|
|
sleep 10
|
|
|
|
ERROR=`wget -c http://$IMGSERVER/tftpboot/$KERNEL -O /tmp/kernel 2>&1`
|
|
|
|
done
|
|
|
|
ERROR=`wget -c http://$IMGSERVER/tftpboot/$INITRD -O /tmp/initrd 2>&1`
|
|
|
|
while [ $? == 1 ] && echo $ERROR|grep -v 416; do
|
|
|
|
sleep 10
|
|
|
|
ERROR=`wget -c http://$IMGSERVER/tftpboot/$INITRD -O /tmp/initrd 2>&1`
|
|
|
|
done
|
2007-10-26 22:44:33 +00:00
|
|
|
#START getting ready for kexec
|
|
|
|
for mod in `lsmod|awk '{print $1}'|grep -v Module`; do
|
|
|
|
rmmod $mod
|
|
|
|
done
|
2008-02-21 20:09:41 +00:00
|
|
|
#kexec -f --append="$KCMD" --initrd=/tmp/initrd /tmp/kernel
|
2007-10-26 22:44:33 +00:00
|
|
|
reboot -f #If script is here, kexec failed, reboot in case it wasn't a linux kernel and let the boot loader handle it instead
|
|
|
|
fi
|
2008-02-26 18:39:27 +00:00
|
|
|
if [ "$DEST" == "runimage" ]; then
|
2008-02-27 16:34:37 +00:00
|
|
|
mkdir /tmp/`basename $TARG`
|
|
|
|
cd /tmp/`basename $TARG`
|
2008-03-04 21:15:40 +00:00
|
|
|
ERROR=`wget $TARG`
|
|
|
|
while [ $? == 1 ] && echo $ERROR|grep -v 416; do
|
|
|
|
sleep 10
|
|
|
|
ERROR=`wget -c $TARG 2>&1`
|
|
|
|
done
|
2007-10-31 03:42:29 +00:00
|
|
|
while ! nextdestiny ; do
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Retrying next destiny..."
|
|
|
|
done
|
2008-02-27 16:34:37 +00:00
|
|
|
tar zxvf `basename $TARG`
|
|
|
|
cd /tmp/`basename $TARG`
|
|
|
|
./runme.sh
|
2007-10-26 22:44:33 +00:00
|
|
|
cd -
|
|
|
|
fi
|
2008-04-09 20:22:46 +00:00
|
|
|
sleep 5 # something may be transiently wrong, check back in 5 seconds
|
2008-02-26 18:39:27 +00:00
|
|
|
getdestiny
|
|
|
|
if grep error /tmp/destiny; then
|
|
|
|
echo ERROR: see above
|
|
|
|
fi
|
2007-10-26 22:44:33 +00:00
|
|
|
done
|