xenapi: Enhance devstack progress monitoring

Fixes bug 1091299

XenServer - devstack install monitors a log file by tailing it, to see,
if the devstack installation is finished. In some cases this script does
not detect, that the startup script is finished, and just waiting,
causing build failures with timeouts. With this change, the
install_os_domU script monitors, if the run.sh script is still running,
thus guaranteed to exit as soon as run.sh is done.

Change-Id: I24a7a46e93ce26be024096828c7954bc694af2b2
diff --git a/tools/xen/install_os_domU.sh b/tools/xen/install_os_domU.sh
index c78c6f2..e270e59 100755
--- a/tools/xen/install_os_domU.sh
+++ b/tools/xen/install_os_domU.sh
@@ -376,35 +376,22 @@
         sleep 10
     done
 
-    # output the run.sh.log
-    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no stack@$DOMU_IP 'tail -f run.sh.log' &
-    TAIL_PID=$!
-
-    function kill_tail() {
-        kill -9 $TAIL_PID
-        exit 1
-    }
-    # Let Ctrl-c kill tail and exit
-    trap kill_tail SIGINT
-
-    # ensure we kill off the tail if we exit the script early
-    # for other reasons
-    add_on_exit "kill -9 $TAIL_PID || true"
-
-    # wait silently until stack.sh has finished
-    set +o xtrace
-    while ! ssh_no_check -q stack@$DOMU_IP "tail run.sh.log | grep -q 'stack.sh completed in'"; do
+    set +x
+    echo -n "Waiting for startup script to finish"
+    while [ `ssh_no_check -q stack@$DOMU_IP pgrep -c run.sh` -ge 1 ]
+    do
         sleep 10
+        echo -n "."
     done
-    set -o xtrace
+    echo "done!"
+    set -x
 
-    # kill the tail process now stack.sh has finished
-    kill -9 $TAIL_PID
+    # output the run.sh.log
+    ssh_no_check -q stack@$DOMU_IP 'cat run.sh.log'
 
-    # check for a failure
-    if ssh_no_check -q stack@$DOMU_IP "grep -q 'stack.sh failed' run.sh.log"; then
-        exit 1
-    fi
+    # Fail if the expected text is not found
+    ssh_no_check -q stack@$DOMU_IP 'cat run.sh.log' | grep -q 'stack.sh completed in'
+
     echo "################################################################################"
     echo ""
     echo "All Finished!"