Merge pull request #164 from cloudbuilders/xen_multi

Add script that demonstrates separation of head and compute roles for xen
diff --git a/stack.sh b/stack.sh
index 32b4539..6b3e09c 100755
--- a/stack.sh
+++ b/stack.sh
@@ -175,6 +175,9 @@
     HOST_IP=`LC_ALL=C /sbin/ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
 fi
 
+# Service startup timeout
+SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60}
+
 # Generic helper to configure passwords
 function read_password {
     set +o xtrace
@@ -926,7 +929,7 @@
 if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
     screen_it g-api "cd $GLANCE_DIR; bin/glance-api --config-file=etc/glance-api.conf"
     echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
-    if ! timeout 60 sh -c "while ! wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
+    if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
       echo "g-api did not start"
       exit 1
     fi
@@ -936,7 +939,7 @@
 if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
     screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone --config-file $KEYSTONE_CONF -d"
     echo "Waiting for keystone to start..."
-    if ! timeout 60 sh -c "while ! wget -q -O- http://127.0.0.1:5000; do sleep 1; done"; then
+    if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget -q -O- http://127.0.0.1:5000; do sleep 1; done"; then
       echo "keystone did not start"
       exit 1
     fi
@@ -946,7 +949,7 @@
 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
     screen_it n-api "cd $NOVA_DIR && $NOVA_DIR/bin/nova-api"
     echo "Waiting for nova-api to start..."
-    if ! timeout 60 sh -c "while ! wget -q -O- http://127.0.0.1:8774; do sleep 1; done"; then
+    if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget -q -O- http://127.0.0.1:8774; do sleep 1; done"; then
       echo "nova-api did not start"
       exit 1
     fi
diff --git a/tools/get_uec_image.sh b/tools/get_uec_image.sh
index cb59b9a..7b95aab 100755
--- a/tools/get_uec_image.sh
+++ b/tools/get_uec_image.sh
@@ -14,6 +14,9 @@
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
 TOP_DIR=`cd $TOOLS_DIR/..; pwd`
 
+# exit on error to stop unexpected errors
+set -o errexit
+
 usage() {
     echo "Usage: $0 - Prepare Ubuntu images"
     echo ""
@@ -44,6 +47,14 @@
     trap 2; kill -2 $$
 }
 
+# apt-get wrapper to just get arguments set correctly
+function apt_get() {
+    local sudo="sudo"
+    [ "$(id -u)" = "0" ] && sudo="env"
+    $sudo DEBIAN_FRONTEND=noninteractive apt-get \
+        --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
+}
+
 while getopts f:hmr: c; do
     case $c in
         f)  FORMAT=$OPTARG
@@ -107,7 +118,14 @@
                 ;;
 esac
 
-trap cleanup SIGHUP SIGINT SIGTERM
+trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT
+
+# Check for dependencies
+
+if [ ! -x "`which qemu-img`" -o ! -x "`which qemu-nbd`" ]; then
+    # Missing KVM?
+    apt_get install qemu-kvm
+fi
 
 # Prepare the base image