From a2b527b6a0fe331e4a6bd2dcac019873babd1e9f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 10 Mar 2017 13:21:27 -0300 Subject: Check guest PID, use a logfile for spice and nohup for kvm invocation --- kvmx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kvmx b/kvmx index fae1279..7efb47c 100755 --- a/kvmx +++ b/kvmx @@ -31,7 +31,7 @@ KVMX_BASE="$DIRNAME" # Run spice client function kvmx_spice { # https://lists.freedesktop.org/archives/spice-devel/2013-September/014643.html - SPICE_NOGRAB=1 spicec --host localhost --port $PORT & + SPICE_NOGRAB=1 spicec --host localhost --port $PORT &> $SPICEFILE & #spicy -h localhost -p $PORT #remote-viewer spice://localhost:$PORT @@ -79,14 +79,15 @@ function kvmx_up { fi # Run virtual machine - kvm -m 2048 -name $VM -drive file=$image,if=virtio -vga qxl $shared \ + # See https://en.wikipedia.org/wiki/Nohup#Overcoming_hanging + nohup kvm -m 2048 -name $VM -drive file=$image,if=virtio -vga qxl $shared \ -spice port=$PORT,addr=127.0.0.1,disable-ticketing,streaming-video=off,jpeg-wan-compression=never,playback-compression=off,zlib-glz-wan-compression=never,image-compression=off \ -device virtio-serial-pci \ -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ -chardev spicevmc,id=spicechannel0,name=vdagent \ -smp 2 -soundhw ac97 -cpu host -balloon virtio \ -net nic,model=virtio \ - -net user,hostfwd=tcp:127.0.0.1:$SSH-:22$hostfwd &> $LOGFILE & + -net user,hostfwd=tcp:127.0.0.1:$SSH-:22$hostfwd &> $LOGFILE < /dev/null & PID="$!" @@ -142,6 +143,11 @@ function kvmx_running { fi PID="`cat $PIDFILE`" + + if [ -z "$PID" ]; then + return 1 + fi + ps $PID &> /dev/null return $? @@ -253,6 +259,7 @@ function kvmx_initialize { PORTFILE="$STATE_DIR/port" SSHFILE="$STATE_DIR/ssh" LOGFILE="$STATE_DIR/log" + SPICEFILE="$STATE_DIR/spice" mkdir -p $STATE_DIR if [ ! -e "$image" ] && [ "$ACTION" != "up" ] && [ "$ACTION" != "purge" ] && [ "$ACTION" != "destroy" ]; then -- cgit v1.2.3