diff options
author | Martin Schwenke <martin@meltin.net> | 2011-08-31 13:32:19 +1000 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2011-08-31 13:32:19 +1000 |
commit | 169334e4d874ab0a975e25edc584f3ede9fb3dbd (patch) | |
tree | 131b62230ca689265630b1bedf2b5fff8c25732e /vircmd | |
parent | 67a587bcbe776c5fa2f74dcda78b1e0bfe6007f4 (diff) | |
download | autocluster-169334e4d874ab0a975e25edc584f3ede9fb3dbd.tar.gz autocluster-169334e4d874ab0a975e25edc584f3ede9fb3dbd.tar.xz autocluster-169334e4d874ab0a975e25edc584f3ede9fb3dbd.zip |
vircmd - add -w/--wait argument with optional timeout.
This is only defined for start and shutdown. The latter is possibly
the most meaningful one...
Signed-off-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'vircmd')
-rwxr-xr-x | vircmd | 56 |
1 files changed, 53 insertions, 3 deletions
@@ -8,8 +8,9 @@ usage () cat >&2 <<EOF Usage: vircmd [OPTION] ... <COMMAND> options: - -x enable script debugging - -n don't include the TSM node (if any) + -x enable script debugging + -n don't include the TSM node (if any) + -w, --wait [timeout] for start/shutdown wait for desired state change commands: start CLUSTERNAME @@ -31,18 +32,21 @@ EOF ############################ # parse command line options -temp=$(getopt -n "$prog" -o "xn" -l help -- "$@") +temp=$(getopt -n "$prog" -o "xnw::" -l help -l wait:: -- "$@") [ $? != 0 ] && usage eval set -- "$temp" no_tsm=0 +wait=false +timeout="" while true ; do case "$1" in -x) set -x; shift ;; -n) no_tsm=1; shift ;; + -w|--wait) wait=true ; timeout="$2" ; shift 2 ;; --) shift ; break ;; -h|--help|*) usage ;; # Shouldn't happen, so this is reasonable. esac @@ -57,6 +61,14 @@ cmd="$1" cluster="$2" count=0 +if $wait ; then + case "$cmd" in + start) desired_state="running" ;; + shutdown) desired_state="shut off" ;; + *) echo "waiting not supported with \"$cmd\"" ; echo ; usage ;; + esac +fi + export VIRSH_DEFAULT_CONNECT_URI=qemu:///system get_nodes () @@ -116,4 +128,42 @@ for i in $nodes ; do [ $ret = 0 ] || rc=$ret done +# Now comes the waiting... but we don't wait if there was an error. +if [ $rc -ne 0 ] || ! $wait ; then + exit $rc +fi + +count=0 +while : ; do + if [ -n "$timeout" ] && [ $count -ge "$timeout" ] ; then + echo "Timed out after ${timeout}s waiting for nodes to enter state \"${desired_state}\":" + echo + fmt='%-20s %s\n' + printf "$fmt" "Domain" "State" + printf "$fmt" "------" "-----" + for i in $nodes ; do + state=$(virsh dominfo "$i" | sed -nr -e 's@^State:[[:space:]]+@@p') + printf "$fmt" "$i" "$state" + done + exit 62 # ETIME + fi + + pat="^State:[[:space:]]+${desired_state}\$" + all_good=true + for i in $nodes ; do + # Often "vircmd dominfo" returns 1 and prints rubbish like this: + # error: operation failed: could not query memory balloon allocation + # so we take pains to avoid this cluttering the output... + if virsh_out=$(virsh dominfo "$i" 2>&1) ; then + if ! echo "$virsh_out" | grep -E -q "$pat" ; then + all_good=false + fi + fi + done + $all_good && exit 0 + + sleep 1 + count=$(($count + 1)) +done + exit $rc |