From 3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187 Mon Sep 17 00:00:00 2001 From: Nicolas Vigier Date: Sun, 21 Nov 2010 20:54:45 +0000 Subject: add testvm module, used to run test VMs --- modules/testvm/files/_vm | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 modules/testvm/files/_vm (limited to 'modules/testvm/files/_vm') diff --git a/modules/testvm/files/_vm b/modules/testvm/files/_vm new file mode 100644 index 00000000..a3482596 --- /dev/null +++ b/modules/testvm/files/_vm @@ -0,0 +1,53 @@ +#!/bin/sh + +test -z $vmname && exit 1 + +vmdir="$HOME/VMs" +piddir="$HOME/PIDs" +logdir="$HOME/log" +vmfile="$vmdir/$vmname" +pidfile="$piddir/$vmname" +logfile="$logdir/$vmname" +qemucmd="qemu-kvm -nographic -pidfile $pidfile -hda $vmfile -net nic,vlan=0 -net user,vlan=0,hostfwd=tcp::$sshport-:22 $QEMUOPT" + +function running() +{ + test -f $pidfile || return 1 + pid=`cat $pidfile` + test -d "/proc/$pid" +} + +function stop() +{ + test -f $pidfile || return 1 + pid=`cat $pidfile` + kill "$pid" && rm -f "$pidfile" +} + +function start() +{ + running && echo "VM is already running" && return 1 + nohup $qemucmd > $logfile 2>&1 & +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + start + stop + ;; + status) + running + vmrunning=$? + test $vmrunning -eq 0 && echo "VM $vmname is running" + test $vmrunning -eq 0 || echo "VM $vmname is stopped" + ;; + ssh) + running && ssh -p $sshport localhost + ;; +esac -- cgit v1.2.1