]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Feat: adds poweroff_pre_command, startup_rsync_to_guest and poweroff_rsync_from_guest
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 22 Aug 2020 13:57:12 +0000 (10:57 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 22 Aug 2020 13:57:12 +0000 (10:57 -0300)
kvmx
kvmxfile

diff --git a/kvmx b/kvmx
index 885ebecafed75829d8ff5d798a5346db36ddbebf..a3edb7cde31fa9ad87f6e85139979c71ceb1ea46 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -716,6 +716,11 @@ function kvmx_up {
     echo "nohup $startup_command" | kvmx ssh $VM &> /dev/null &
   fi
 
+  if [ ! -z "$startup_rsync_to_guest" ] && [ "$ssh_support" == "y" ]; then
+    echo "Rsyncing to guest: $startup_rsync_to_guest..."
+    kvmx_rsync_to $startup_rsync_to_guest
+  fi
+
   kvmx_status
 }
 
@@ -981,6 +986,16 @@ function kvmx_poweroff {
     exit 1
   fi
 
+  if [ ! -z "$poweroff_pre_command" ] && [ "$ssh_support" == "y" ]; then
+    echo "Running $poweroff_pre_command..."
+    echo "nohup $poweroff_pre_command" | kvmx ssh $VM &> /dev/null &
+  fi
+
+  if [ ! -z "$poweroff_rsync_from_guest" ] && [ "$ssh_support" == "y" ]; then
+    echo "Rsyncing to guest: $poweroff_rsync_from_guest..."
+    kvmx_rsync_to $poweroff_rsync_from_guest
+  fi
+
   if [ "$run_xpra" == "1" ]; then
     $DIRNAME/$BASENAME xpra $VM stop
   fi
@@ -1132,7 +1147,7 @@ function kvmx_rsync_to {
   rsync -av --delete -e "$SSH_COMMAND -o Port=$SSH" --rsync-path "sudo rsync" $ORIG/ 127.0.0.1:$DEST/
 }
 
-# Rsync files to the guest
+# Rsync files from the guest
 function kvmx_rsync_from {
   if ! kvmx_running; then
     echo "$BASENAME: guest $VM is not running"
index 25f676d6c2f35fc5258721d725170b2cb5eed796..8d0a07a5c5a0ca46efbe6f014a0dc7c7062b575d 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -79,6 +79,13 @@ shared_folder_mountpoint="/home/$user/code/$VM"
 #startup_command="/path/to/custom/command"
 #startup_command="hydractl aperiodic-upgrade"
 
+# Pre-poweroff command
+#poweroff_pre_command="/path/to/custom/command"
+
+# Rsync commands to be run on startup or poweroff, useful to keep files synced between host and guest
+#startup_rsync_to_guest="data /var/data"
+#poweroff_rsync_from_guest="/var/data data"
+
 # Graphics
 # See https://wiki.archlinux.org/index.php/QEMU#Graphics
 #graphics="-vga std -nographic -vnc :$GUEST_DISPLAY"