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
|
|
|
|
export XCATMASTER=`echo $XCATDEST | awk -F: '{print $1}'`
|
|
|
|
export XCATPORT=`echo $XCATDEST | awk -F: '{print $2}'`
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
if [ $DESTINY == "standby" ]; then
|
|
|
|
echo "Server notified us of standby condition, please check chain table".
|
|
|
|
echo "Retrying destiny in 15 seconds"
|
|
|
|
usleep 15000000 # 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"
|
2007-10-31 03:42:29 +00:00
|
|
|
usleep 300000
|
2007-10-26 22:44:33 +00:00
|
|
|
done
|
|
|
|
exec $0
|
|
|
|
fi
|
|
|
|
if [ $DESTINY == "shell" ]; then
|
|
|
|
echo "Server notified us to stay in shell state, stopping destiny requests"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
if [ $DESTINY == "discover" ]; then
|
|
|
|
echo "MAC discovery begins"
|
|
|
|
minixcatd.awk &
|
2007-10-31 03:42:29 +00:00
|
|
|
usleep 500000 #Mitigate occurrances of 'failed to notify node'
|
2007-10-26 22:44:33 +00:00
|
|
|
while [ ! -r /restart ]; do
|
|
|
|
ifconfig -a|grep HWaddr|grep -v sit|awk '{print $1 "|" $5}'
|
|
|
|
MTM="unknown"
|
|
|
|
SERIAL="unknown"
|
|
|
|
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>"
|
|
|
|
echo "<arch>"`uname -m`"</arch>"
|
|
|
|
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
|
2007-10-31 04:24:22 +00:00
|
|
|
cat /tmp/discout | udpcat.awk $XCATMASTER $XCATPORT & #can't figure out how to make a hung gawk behave..
|
|
|
|
if usleep 8000000 #Give the preferred method 5 seconds to complete before resorting
|
|
|
|
then
|
|
|
|
#if usleep succeeded, that means it wasn't killed and therefore, no answer yet
|
|
|
|
killall udpcat.awk #reap hung ones
|
|
|
|
cat /tmp/discout | udpcat.awk `cat /tmp/dhcpserver` $XCATPORT &
|
|
|
|
usleep 8000000
|
|
|
|
fi
|
|
|
|
killall udpcat.awk #reap hung ones
|
2007-10-26 22:44:33 +00:00
|
|
|
done
|
|
|
|
#Discovery complete, restart requested.
|
|
|
|
exec /bin/restart
|
|
|
|
fi
|
2007-10-31 14:55:43 +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
|
|
|
|
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
|
|
|
|
if [ $DESTINY == "install" -o $DESTINY == "netboot" ]; then
|
|
|
|
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}'`
|
|
|
|
wget http://$IMGSERVER/tftpboot/$KERNEL -O /tmp/kernel
|
|
|
|
wget http://$IMGSERVER/tftpboot/$INITRD -O /tmp/initrd
|
|
|
|
#START getting ready for kexec
|
|
|
|
for mod in `lsmod|awk '{print $1}'|grep -v Module`; do
|
|
|
|
rmmod $mod
|
|
|
|
done
|
|
|
|
kexec -f --append="$KCMD" --initrd=/tmp/initrd /tmp/kernel
|
|
|
|
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
|
|
|
|
if [ $DEST == "runimage" ]; then
|
|
|
|
mkdir /tmp/$TARG
|
|
|
|
cd /tmp/$TARG
|
|
|
|
wget $TARG
|
2007-10-31 03:42:29 +00:00
|
|
|
while ! nextdestiny ; do
|
2007-10-26 22:44:33 +00:00
|
|
|
echo "Retrying next destiny..."
|
|
|
|
done
|
|
|
|
tar zxvf $TARG
|
|
|
|
/tmp/$TARG/runme.sh
|
|
|
|
cd -
|
|
|
|
fi
|
|
|
|
done
|