cleanup qemu starter; hopefully the qemu instances could keep on running after the...
[tests.git] / system / template-qemu / qemu-start-node
index 8d8b079..9a9e923 100755 (executable)
@@ -1,51 +1,79 @@
 #!/bin/bash
+# $Id$
+
+# it does the following:
+# (*) close all file descriptors and redirect output to log.txt 
+#     this is because it is designed for use through ssh from a remote test master controller
+# (*) initialize a disk image if it does not exist yet
+# (*) starts a qemu instance 
 
 # cd in this command's directory
+COMMAND=$(basename $0)
 cd $(dirname $0)
 
-#Getting the env. as passed by the test framework
-# expected vars are MACADDR, NODE_ISO, HOSTNAME and TARGET_ARCH
+########## globals
+# 1 gigabyte ram
+RAM=1024
+DISK_SIZE=18G
+DISK_FORMAT=qcow2
+DISK_IMAGE=hdd-${DISK_FORMAT}-${DISK_SIZE}.img
+
+SCRIPT=qemu-ifup
+
+####### we want this script to be invokable through ssh without the ssh client to remain hanging
+# close stdin
+exec <&-
+# redirect stdout
+exec >> log.txt
+# redirect stderr on stdout
+exec 2>&1
+
+########## from the test environment
+# expected vars are MACADDR, NODE_ISO, HOSTNAME, IP and TARGET_ARCH
 CONFIG=qemu.conf
-if [ ! -e ${CONFIG} ];then
-    echo "File for node_iso version not found"
-    exit 1
-fi
+[ -f "$CONFIG" ] || { echo "Config file for qemu $CONFIG not found in $(pwd)" ; exit 1 ; }
 . $CONFIG
 
-# the launcher, depending on local/target archs
-archs="$(uname-i)+$(TARGET_ARCH)"
-case $archs in
-    i386+i386)         QEMU= qemu;;
-    i386+x86_64)       QEMU= qemu-system-x86_64;;
-    x86_64+i386)       QEMU= qemu;;
-    x86_64+x86_64)     QEMU= qemu-system-x86_64;;
+# the launcher, depending on target arch
+# make sure to check qemu-kill-node for consistency
+case $TARGET_ARCH in
+    i386)              QEMU=qemu;;
+    x86_64)            QEMU=qemu-system-x86_64;;
+    *)                 echo "Cannot handle TARGET_ARCH=$TARGET_ARCH"; exit 1 ;;
 esac
 
-QEMU=qemu
-HDA=hard_drive.img
-RAM=1024
+echo "Running $COMMAND in $(pwd)"
+echo "Starting at $(date)"
 
-SCRIPT=qemu-ifup
-TAP="tap,script=$SCRIPT"
-
-#Creating new HDA if needed only
-#using qcow2 disk image format which is essential to support VM snapshots
-if [ -f $HDA ] ; then
-    echo "Using $HDA"
+#Creating new DISK_IMAGE if needed only
+if [ -f $DISK_IMAGE ] ; then
+    echo "Using existing $DISK_IMAGE"
 else
-    echo "Creating hard disk (10G) for Qemu install under $HDA"
-    img=$(qemu-img create -f qcow2 $HDA 10G)
+    echo -n "Creating hard disk image (${DISK_SIZE}) as $DISK_IMAGE .. "
+    img=$(qemu-img create -f ${DISK_FORMAT} $DISK_IMAGE ${DISK_SIZE})
     if [ -z "$img" ];then
-       echo "Can't Create disk image..."
+       echo "Failed"
        exit 1
     fi
+    echo "Done"
 fi
 
-echo "New $HDA is created..."
-
 rm -f qemu.pid
 
 #Command for running the Qemu Emulator
-ARGS="-boot d  -net nic,macaddr=${MACADDR} -net $TAP, -cdrom ${NODE_ISO} -hda ${HDA} -m ${RAM} -nographic  -pidfile qemu.pid"
-echo "Running $QEMU $ARGS < /dev/null"
-exec $QEMU $ARGS < /dev/null
+# can't use -daemonize: qemu-ifup: could not launch network script
+ARGS=""
+# basics
+ARGS="$ARGS -m ${RAM}"
+ARGS="$ARGS -hda ${DISK_IMAGE}"
+ARGS="$ARGS -nographic"
+ARGS="$ARGS -pidfile qemu.pid"
+# boot from CD
+ARGS="$ARGS -boot d"
+ARGS="$ARGS -cdrom ${NODE_ISO}"
+# set mac address
+ARGS="$ARGS -net nic,macaddr=${MACADDR}"
+# set init script
+ARGS="$ARGS -net tap,script=${SCRIPT}"
+echo "Running $QEMU $ARGS"
+exec $QEMU $ARGS &