diff options
author | Sebastian Arcus <s.arcus@open-t.co.uk> | 2017-06-07 07:17:02 -0500 |
---|---|---|
committer | Willy Sudiarto Raharjo <willysr@slackbuilds.org> | 2017-06-10 10:47:30 +0700 |
commit | 942af95bd1342a34bbd0121249b8371e527aae6c (patch) | |
tree | 25aee79c3521f5d996b360048fd55df09d77626a /libraries | |
parent | 2f03ac59d744b94e13f5b7f4e879b3a1b4db7bfd (diff) | |
download | slackbuilds-942af95bd1342a34bbd0121249b8371e527aae6c.tar.gz |
libraries/libvirt: managesave running VMs on shutdown by default
Signed-off-by: Robby Workman <rworkman@slackbuilds.org>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/libvirt/README | 16 | ||||
-rw-r--r-- | libraries/libvirt/rc.libvirt | 65 |
2 files changed, 72 insertions, 9 deletions
diff --git a/libraries/libvirt/README b/libraries/libvirt/README index 55b664a2e7..fbe09fd2b6 100644 --- a/libraries/libvirt/README +++ b/libraries/libvirt/README @@ -18,6 +18,7 @@ to /etc/rc.d/rc.local if [ -x /etc/rc.d/rc.libvirt ]; then /etc/rc.d/rc.libvirt start fi + and if you want it to stop at shutdown add this to /etc/rc.d/rc.local_shutdown @@ -26,6 +27,21 @@ and if you want it to stop at shutdown add this to /etc/rc.d/rc.libvirt stop fi +The enclosed rc.libvirt script will do a 'managedsave' on all running +and paused guests when issuing 'rc.libvirt stop'. Please note that this +saves the RAM of each guest to the host system's disk (by default under +/var/lib/libvirt/qemu/save) - so make sure enough space is available. If +you prefer to perform a full shutdown on all running guests instead, +issue a 'rc.libvirt guests_shutdown' followed by 'rc.libvirt shutdown'. + +By default 'rc.libvirt stop' and 'rc.libvirt guests_shutdown' will wait +a maximum of 5 minutes for all guests to shutdown, after which any +guests still running will be destroyed. Adjust this to a suitable value +for your system, as destroying a running guest carries a high risk of +data loss! + +There is also a 'guests_reboot' for rebooting all running guests. + Have a look at the commented part of rc.libvirt for some gotchas. netcat-openbsd is an optional dependency (needed if you diff --git a/libraries/libvirt/rc.libvirt b/libraries/libvirt/rc.libvirt index 844fbcd6c6..18cc374059 100644 --- a/libraries/libvirt/rc.libvirt +++ b/libraries/libvirt/rc.libvirt @@ -12,7 +12,7 @@ # on your setup MODULES="tun vhost_net" -TIMEOUT=${TIMEOUT:-40} +TIMEOUT=${TIMEOUT:-300} LIBVIRTD_PIDFILE="/var/run/libvirt/libvirtd.pid" LIBVIRTD_OPTS=${LIBVIRT_OPTS:-" -v -f /etc/libvirt/libvirtd.conf -p $LIBVIRTD_PIDFILE "} VIRTLOGD_PIDFILE="/var/run/libvirt/virtlogd.pid" @@ -20,15 +20,21 @@ VIRTLOGD_OPTS=${VIRTLOGD_OPTS:-" -v -f /etc/libvirt/virtlogd.conf -p $VIRTLOGD_P VIRTLOCKD_PIDFILE="/var/run/libvirt/virtlockd.pid" VIRTLOCKD_OPTS=${VIRTLOCKD_OPTS:-" -v -f /etc/libvirt/virtlockd.conf -p $VIRTLOCKD_PIDFILE "} -check_running_machines() { +guests_reboot() { - count=0 + for machine in $(/usr/sbin/virsh list --name --state-running | grep -v ^$) ; do + /usr/sbin/virsh reboot $machine + done + +} + +guests_shutdown() { for machine in $(/usr/sbin/virsh list --name --state-running | grep -v ^$) ; do - /usr/sbin/virsh shutdown $machine + /usr/sbin/virsh shutdown $machine & done - echo -n "Waiting machines" + echo -n "Waiting for guests to finish shutting down" while [ $(/usr/sbin/virsh list --name --state-running | grep -v ^$ | wc -l) -gt "0" ]; do if [ "$count" -ge "$TIMEOUT" ];then @@ -43,18 +49,53 @@ check_running_machines() { if [ $(/usr/sbin/virsh list --name --state-running | grep -v ^$ | wc -l) -gt "0" ];then - echo -n "The following machines are still running, forcing shutdown: " + echo -n "The following guests are still running, destroying them: " for machine in $(/usr/sbin/virsh list --name --state-running | grep -v ^$) ; do /usr/sbin/virsh destroy $machine echo -n "$machine " done - echo "" sleep 2 fi } + +guests_managedsave() { + # apply managedsave on running and paused machines (as we can't distinguish between + # the two states while managedsave is being applied, so won't know when to finish waiting) + + count=0 + + for machine in $(/usr/sbin/virsh list --name | grep -v ^$) ; do + /usr/sbin/virsh managedsave $machine & + done + + echo -n "Waiting for managedsave to finish on all guests" + + while [ $(/usr/sbin/virsh list --name | grep -v ^$ | wc -l) -gt "0" ]; do + if [ "$count" -ge "$TIMEOUT" ];then + break + fi + echo -n "." + count=$(expr $count + 1) + sleep 1 + done + + echo "" + + if [ $(/usr/sbin/virsh list --name | grep -v ^$ | wc -l) -gt "0" ];then + + echo -n "The following guests are still running, destroying them: " + for machine in $(/usr/sbin/virsh list --name | grep -v ^$) ; do + /usr/sbin/virsh destroy $machine + echo -n "$machine " + done + + sleep 2 + fi +} + check_processor() { egrep 'vmx' /proc/cpuinfo > /dev/null @@ -96,7 +137,7 @@ stop_libvirtd() { echo "libvirt is not running..." exit 2 fi - check_running_machines + guests_managedsave check_processor echo "Stopping libvirtd..." for network in $(/usr/sbin/virsh net-list | tail -n +3 | awk '{print $1}'); do @@ -167,8 +208,14 @@ restart) start_virtlogd start_libvirtd ;; +guests_shutdown) + guests_shutdown + ;; +guests_reboot) + guests_reboot + ;; *) - echo "Usage: $0 (start|stop|restart)" + echo "Usage: $0 (start|stop|restart|guests_shutdown|guests_reboot)" ;; esac |