diff options
author | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2011-02-10 22:11:16 -0500 |
---|---|---|
committer | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2011-02-10 23:59:30 -0500 |
commit | 71954d42fc35046243a3c0eee4f05e0195a91a95 (patch) | |
tree | beaa38553bb0e00fb504830e1db10c6aee843dca | |
parent | 38f77cfecab65505ea0e1aff1d7f7edd8434ab45 (diff) | |
download | kvm-manager-71954d42fc35046243a3c0eee4f05e0195a91a95.tar.gz kvm-manager-71954d42fc35046243a3c0eee4f05e0195a91a95.tar.bz2 |
control the guest if signals are sent to the parent shell
-rw-r--r-- | README | 4 | ||||
-rwxr-xr-x | kvm-manager | 26 |
2 files changed, 25 insertions, 5 deletions
@@ -18,13 +18,13 @@ Dependencies: runit : for system supervision uml-utilities : for tunctl for the tun/tap interface kvm : for the virtual machine emulator + socat : For communications with the monitor and console of guests screen : for the detached, logged serial console bridge-utils : for configuring a bridge device lvm2 : for creating the relevant block devices udev : for configuring the block devices with proper permissions fakeroot : for rebuilding the initramfs as a regular user in di-maker xorriso : for grub2 to make an iso in di-maker - socat : so users can talk to the kvm monitor of their VMs Recommendations: @@ -34,7 +34,7 @@ INSTALLATION * Install dependencies: - apt-get install runit uml-utilities kvm screen bridge-utils lvm2 udev + apt-get install runit uml-utilities kvm screen bridge-utils lvm2 udev socat If you want to be able to use di-maker, you'll also need: diff --git a/kvm-manager b/kvm-manager index b1f260c..be3db9f 100755 --- a/kvm-manager +++ b/kvm-manager @@ -58,8 +58,16 @@ up() { if [ -e "$LOGNAME" ] ; then chpst -u "$OWNER" mv "$LOGNAME" "$LOGNAME".$(date +%F_%T%z|tr : .) fi + + MONITORNAME="$OWNERHOME/vms/$VMNAME/monitor.socket" + + kvmsend() { + socat STDIO "UNIX:$MONITORNAME" <<EOF +$1 +EOF + } - exec chpst -u "$OWNER:$OWNERGROUP:kvm" \ + chpst -u "$OWNER:$OWNERGROUP:kvm" \ /usr/bin/kvm $KVMARGS \ -M "${MACHINE:-pc}" \ -enable-kvm \ @@ -68,14 +76,26 @@ up() { -name "$VMNAME" \ -m "$RAM" \ -boot "$BOOTCHOICE" \ - -chardev "socket,id=monitor,path=$OWNERHOME/vms/$VMNAME/monitor.socket,server,nowait" -mon chardev=monitor,mode=readline \ + -chardev "socket,id=monitor,path=$MONITORNAME,server,nowait" -mon chardev=monitor,mode=readline \ -rtc base=utc \ -usb \ -device virtio-balloon-pci,id=balloon0,bus=pci.0 \ -chardev "socket,id=serial0,path=$OWNERHOME/vms/$VMNAME/console.socket,server,nowait" -device isa-serial,chardev=serial0 \ -smp "${SMP:-1},maxcpus=${MAXCPUS:-8}" \ -device "virtio-net-pci,vlan=0,id=net0,mac=$MAC,bus=pci.0" \ - -net "tap,ifname=$TAP,script=no,downscript=no,vlan=0,name=hostnet0" + -net "tap,ifname=$TAP,script=no,downscript=no,vlan=0,name=hostnet0" & + + set +e + # handle regular signals + trap 'kvmsend system_reset; wait' HUP + trap 'kvmsend system_powerdown; wait' TERM + trap 'kvmsend cont; wait' CONT + # use SIGINT instead of SIGSTOP for freezing the guest because + # trapping SIGSTOP is undefined: + # http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_28 + trap 'kvmsend stop; wait' INT + + wait } |