/[adm]/puppet/modules/testvm/files/_vm
ViewVC logotype

Contents of /puppet/modules/testvm/files/_vm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 357 - (show annotations) (download)
Sun Nov 21 20:54:45 2010 UTC (13 years, 5 months ago) by boklm
File size: 899 byte(s)
add testvm module, used to run test VMs
1 #!/bin/sh
2
3 test -z $vmname && exit 1
4
5 vmdir="$HOME/VMs"
6 piddir="$HOME/PIDs"
7 logdir="$HOME/log"
8 vmfile="$vmdir/$vmname"
9 pidfile="$piddir/$vmname"
10 logfile="$logdir/$vmname"
11 qemucmd="qemu-kvm -nographic -pidfile $pidfile -hda $vmfile -net nic,vlan=0 -net user,vlan=0,hostfwd=tcp::$sshport-:22 $QEMUOPT"
12
13 function running()
14 {
15 test -f $pidfile || return 1
16 pid=`cat $pidfile`
17 test -d "/proc/$pid"
18 }
19
20 function stop()
21 {
22 test -f $pidfile || return 1
23 pid=`cat $pidfile`
24 kill "$pid" && rm -f "$pidfile"
25 }
26
27 function start()
28 {
29 running && echo "VM is already running" && return 1
30 nohup $qemucmd > $logfile 2>&1 &
31 }
32
33 case "$1" in
34 start)
35 start
36 ;;
37 stop)
38 stop
39 ;;
40 restart)
41 start
42 stop
43 ;;
44 status)
45 running
46 vmrunning=$?
47 test $vmrunning -eq 0 && echo "VM $vmname is running"
48 test $vmrunning -eq 0 || echo "VM $vmname is stopped"
49 ;;
50 ssh)
51 running && ssh -p $sshport localhost
52 ;;
53 esac

  ViewVC Help
Powered by ViewVC 1.1.30