]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Check guest PID, use a logfile for spice and nohup for kvm invocation
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 10 Mar 2017 16:21:27 +0000 (13:21 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 10 Mar 2017 16:21:27 +0000 (13:21 -0300)
kvmx

diff --git a/kvmx b/kvmx
index fae1279b4a169964e8a12b72b41f711a330a22b7..7efb47cbfb763b4340d714f514d8d9bcc6129d78 100755 (executable)
--- 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