From d000b22d16b6b56cbcce510c229fe61b051e9ec3 Mon Sep 17 00:00:00 2001
From: Anthony Young <sleepsonthefloor@gmail.com>
Date: Mon, 19 Sep 2011 14:46:53 -0700
Subject: [PATCH] add checks to make sure that services are started

---
 stack.sh | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/stack.sh b/stack.sh
index 44665c40ae..28aa4b7161 100755
--- a/stack.sh
+++ b/stack.sh
@@ -408,10 +408,33 @@ function screen_it {
 screen -d -m -S nova -t nova
 sleep 1
 
-screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
-screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
-screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF"
-screen_it n-api "$NOVA_DIR/bin/nova-api"
+if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
+    screen_it g-reg "cd $GLANCE_DIR; bin/glance-registry --config-file=etc/glance-registry.conf"
+fi
+
+if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
+    screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
+    while ! wget -q -O- http://$GLANCE_HOSTPORT; do
+        echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
+        sleep 1
+    done
+fi
+
+if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
+    screen_it key "$KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF"
+    while ! wget -q -O- http://127.0.0.1:5000; do
+        echo "Waiting for keystone to start..."
+        sleep 1
+    done
+fi
+
+if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
+    screen_it n-api "$NOVA_DIR/bin/nova-api"
+    while ! wget -q -O- http://127.0.0.1:8774; do
+        echo "Waiting for nova-api to start..."
+        sleep 1
+    done
+fi
 # Launching nova-compute should be as simple as running ``nova-compute`` but 
 # have to do a little more than that in our script.  Since we add the group 
 # ``libvirtd`` to our user in this script, when nova-compute is run it is