Make "wakeup delay" configurable: WAKE_DELAY
[trigger-rcmd.git] / scripts / trigger-rcmd
index 97f4efafc9a75a29143de6b341916e087cbd03f0..c8f92ba68fc987a456a0f2bb9892d251222cade9 100755 (executable)
@@ -25,6 +25,8 @@ do_rcmd() {
        IFACE="eth0"
        CMD="uptime"
        TIMEOUT="180"
+       SSH_CHECKS="6"
+       WAKE_DELAY="10s"
 
        . "$cnf"
 
@@ -60,13 +62,20 @@ do_rcmd() {
                        echo "$NAME: failed to wake \"$SYSTEM\"!" >&2
                        return 4
                fi
-               sleep 3
+               sleep "$WAKE_DELAY"
                rsys_was_running=0
        else
                echo "$NAME: \"$SYSTEM\" is already alive, ok."
                rsys_was_running=1
        fi
 
+       for i in `seq 1 $SSH_CHECKS`; do
+               echo "$NAME: checking SSH connection ($i/$SSH_CHECKS) ..."
+               ssh -q "$SYSTEM" true >/dev/null 2>&1 && break
+               echo "$NAME: SSH on \"$SYSTEM\" not ready. Waiting ..."
+               sleep 10s
+       done
+
        echo "$NAME: calling \"$CMD\" on \"$SYSTEM\" ..."
        echo
 
@@ -80,7 +89,7 @@ do_rcmd() {
                rsys_users=`ssh -q "$SYSTEM" w | tail -n +3 | wc -l`
                if [ "$rsys_users" = "0" ]; then
                        echo "$NAME: power off \"$SYSTEM\" again ..."
-                       ssh -q "$SYSTEM" "sync; shutdown -hP +1"
+                       ssh -q "$SYSTEM" "sync; shutdown -hP +1" >/dev/null
                        if [ $? -ne 0 ]; then
                                echo "$NAME: failed to power off \"$SYSTEM\"!" >&2
                                return 5