wait4amd2die.in revision 256281
117680Spst#!/bin/sh
239297Sfenner# wait for amd to die on local host before returning from program.
317680Spst# Usage: wait4amd2die [delay [count]]
417680Spst# If not specified, delay=5 seconds and count=6 (total 30 seconds)
517680Spst# If at end of total delay amd is till up, return 1; else return 0.
617680Spst#
717680Spst# Package:	am-utils-6.x
817680Spst# Author:	Erez Zadok <ezk@cs.columbia.edu>
917680Spst
1017680Spst#set -x
1117680Spst
1217680Spst# set path
1317680Spstprefix=@prefix@
1417680Spstexec_prefix=@exec_prefix@
1517680SpstPATH=@sbindir@:@bindir@:/usr/bin:/bin:${PATH}
1617680Spstexport PATH
1717680Spst
1817680Spst# how long to wait?
1917680Spstif test -n "$1"
2017680Spstthen
2117680Spst	delay=$1
22313537Sglebiuselse
23313537Sglebius	delay=3
2456893Sfennerfi
2556893Sfenner# how many times to delay
2656893Sfennerif test -n "$2"
2756893Sfennerthen
28313537Sglebius	count=$2
2917680Spstelse
3017680Spst	count=10
3117680Spstfi
32313537Sglebius
33127668Sbmsi=1
3417680Spstmaxcount=`expr $count + 1`
35276788Sdelphijwhile [ $i != $maxcount ]; do
36276788Sdelphij	# run amq
37276788Sdelphij	@sbindir@/amq > /dev/null 2>&1
38276788Sdelphij	if [ $? != 0 ]
39276788Sdelphij	then
40276788Sdelphij		# amq failed to run (because amd is dead)
41276788Sdelphij		echo "wait4amd2die: amd is down!"
42276788Sdelphij		exit 0
43276788Sdelphij	fi
44276788Sdelphij	echo "wait4amd2die: delay $delay sec ($i of $count)..."
45276788Sdelphij	sleep $delay
46276788Sdelphij	i=`expr $i + 1`
47276788Sdelphijdone
48276788Sdelphijecho "wait4amd2die: amd is still up..."
49276788Sdelphijexit 1
50276788Sdelphij