2013-08-16 10:58:10 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
# This routine when called, contacts xcatd. It will return to the caller when xcatd is
|
|
|
|
# ready to process the request
|
|
|
|
# It is called by xcatdsklspost before calling getpostscripts.awk
|
|
|
|
# it is called by remoteshell before calling getcredentials.awk
|
2013-10-21 15:27:35 +00:00
|
|
|
# For example xcatflowrequest <ip address of master> 3001
|
|
|
|
# Returns
|
|
|
|
# 0 = good
|
|
|
|
# 1 = ping/nmap to ip address of master failed (TBD)
|
|
|
|
# 2 = xcatd never gave goahead
|
2013-08-16 10:58:10 +00:00
|
|
|
#
|
2013-10-21 15:27:35 +00:00
|
|
|
|
|
|
|
# Here we will test to see if nmap is available
|
|
|
|
# if available we will use it to see if the daemon is available
|
|
|
|
# If not available we will use ping to the ip address
|
|
|
|
# If nmap or ping fail then
|
|
|
|
# we will return with exit 1
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2013-10-02 13:12:29 +00:00
|
|
|
# check bash version, if < 4 then cannot use autodetect of next FD
|
|
|
|
bashversion=$BASH_VERSION
|
|
|
|
bashversionnum=`echo $bashversion | cut -d. -f1`
|
2013-10-21 15:27:35 +00:00
|
|
|
|
|
|
|
# cleanup before exiting
|
|
|
|
cleanup()
|
|
|
|
{
|
|
|
|
sleeper=$(cat /tmp/sleeperpid.$parpid)
|
|
|
|
sleeper=$(ps -ef|awk "\$3==$sleeper"|awk '{print $2}')
|
|
|
|
rm /tmp/goahead.$parpid
|
|
|
|
rm /tmp/sleeperpid.$parpid
|
|
|
|
rm /tmp/killme.$parpid
|
|
|
|
if [[ $bashversionnum > 3 ]]; then
|
|
|
|
exec {REMOTEFD}>&-
|
|
|
|
else
|
|
|
|
exec 50>&-
|
|
|
|
fi
|
|
|
|
kill -TERM $sleeper
|
|
|
|
}
|
|
|
|
|
2013-10-02 13:12:29 +00:00
|
|
|
if [[ $bashversionnum > 3 ]]; then
|
|
|
|
exec {REMOTEFD}<>/dev/udp/$1/$2
|
|
|
|
else
|
|
|
|
exec 50<>/dev/udp/$1/$2
|
|
|
|
echo "resourcerequest: xcatd" >&50
|
|
|
|
REMOTEFD=50
|
|
|
|
fi
|
|
|
|
echo "resourcerequest: xcatd" >&$REMOTEFD
|
2013-08-16 10:58:10 +00:00
|
|
|
parpid=$$
|
|
|
|
touch /tmp/goahead.$parpid
|
|
|
|
touch /tmp/killme.$parpid
|
|
|
|
exec 2> /dev/null
|
2013-10-21 15:27:35 +00:00
|
|
|
RETRY=0
|
|
|
|
MAX_RETRIES=50
|
2013-08-16 10:58:10 +00:00
|
|
|
while ! grep 'resourcerequest: ok' /tmp/goahead.$parpid > /dev/null; do
|
|
|
|
(
|
2013-10-02 13:12:29 +00:00
|
|
|
echo "resourcerequest: xcatd" >&$REMOTEFD
|
|
|
|
if [[ $bashversionnum > 3 ]]; then
|
|
|
|
exec {LOCALFD}<>/proc/self/stat
|
|
|
|
else
|
|
|
|
exec 51<>/proc/self/stat
|
|
|
|
LOCALFD=51
|
|
|
|
fi
|
|
|
|
read mystat<&$LOCALFD
|
2013-08-16 10:58:10 +00:00
|
|
|
mypid=$(echo $mystat|cut -d " " -f 4)
|
|
|
|
(sleep $(((RANDOM%60)+120)).$((RANDOM%50)); if [ -f /tmp/killme.$parpid ]; then kill -TERM $mypid; fi) &
|
|
|
|
echo $! > /tmp/sleeperpid.$parpid
|
2013-10-02 13:12:29 +00:00
|
|
|
exec awk '{print $0 > "/tmp/goahead.'$parpid'";exit}' <&$REMOTEFD
|
|
|
|
exec {LOCALFD}>&-
|
2013-10-21 15:27:35 +00:00
|
|
|
)
|
|
|
|
# limit retries, if we reach the max error out
|
|
|
|
RETRY=$(($RETRY+1))
|
|
|
|
if [ $RETRY -eq $MAX_RETRIES ]
|
|
|
|
then
|
|
|
|
cleanup
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2013-08-16 10:58:10 +00:00
|
|
|
done
|
2013-10-21 15:27:35 +00:00
|
|
|
cleanup
|
|
|
|
exit 0
|