fixed up exit status for onnode
authorAndrew Tridgell <tridge@samba.org>
Sun, 13 Jul 2008 23:19:22 +0000 (09:19 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 13 Jul 2008 23:19:22 +0000 (09:19 +1000)
tools/onnode

index 1e7e24690fa2e6d72f7a28e98b356d0819ea9433..6d8ed17f042c9739e0704697013aa21f70af37a5 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # Run commands on CTDB nodes.
 
@@ -171,9 +171,12 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM
 # There's a small race here where the kill can fail if no processes
 # have been added to $pids and the script is interrupted.  However,
 # the part of the window where it matter is very small.
+retcode=0
 for n in $nodes ; do
     if $parallel ; then
        if $verbose ; then
+           # pipefail is a bashism - is there some way to do this with plain sh?
+           set -o pipefail 2>/dev/null
            ($SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 2>&1 | sed -e "s@^@[$n] @" )&
        else
            $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" &
@@ -184,8 +187,17 @@ for n in $nodes ; do
            echo >&2 ; echo ">> NODE: $n <<" >&2
        fi
 
-       $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command"
+       $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 
+       [ $? = 0 ] || retcode=$?
     fi
 done
 
-$parallel && wait
+$parallel && {
+    for p in $pids; do
+       wait $p
+       [ $? = 0 ] || retcode=$?
+    done
+}
+
+exit $retcode
+