]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds restart action
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 31 Dec 2017 15:52:09 +0000 (13:52 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 31 Dec 2017 15:52:09 +0000 (13:52 -0200)
kvmx

diff --git a/kvmx b/kvmx
index 7d8dbc2d4313b8943bc679faafd31e6bdefe4bef..3db48445e86ebddc0fe4e0244d28ae1414bd1c04 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -697,7 +697,28 @@ function kvmx_poweroff {
   fi
 
   kvmx_xephyr_stop
-  sleep 3
+
+  let poweroff_attempts="0"
+  echo -n "Waiting for machine to stop..."
+  while true; do
+    kvmx_running || break
+
+    echo -n "."
+    let poweroff_attempts++
+
+    if [ "$poweroff_attempts" == "20" ]; then
+      echo "$BASENAME: guest $VM is still running"
+      echo "$BASENAME: please consider to stop it using \"kvmx $VM stop\""
+      #kvmx_stop
+      exit 1
+    fi
+
+    sleep 3
+  done
+  echo " done."
+  #sleep 3
+  #echo ""
+
   kvmx_status
 }
 
@@ -1276,6 +1297,20 @@ function kvmx_run {
   kvmx_up $*
 }
 
+# Restart machine
+function kvmx_restart {
+  if ! kvmx_running; then
+    echo "Guest $VM was not running, so starting it anyway..."
+    kvmx_start
+  else
+    echo "Powering off guest $VM..."
+    kvmx_poweroff
+
+    echo "Starting guest $VM again..."
+    kvmx_start
+  fi
+}
+
 # Connect to the guest using VNC
 function kvmx_vnc {
   if ! kvmx_running; then