Skip to content

Instantly share code, notes, and snippets.

@pgrm
Created December 4, 2013 11:45
Show Gist options
  • Save pgrm/7786286 to your computer and use it in GitHub Desktop.
Save pgrm/7786286 to your computer and use it in GitHub Desktop.
Automatically saves the state of all running KVM guests when the system is shut down put into /etc/init.d and reference from /etc/rc0.d and name it with a prefix which makes it execute before any of the other scripts (for instance K01)
#! /bin/sh
suspend_vms () {
for output in $(virsh list --state-running --uuid)
do
exec virsh managedsave $output --bypass-cache
done
}
case "$1" in
start)
# No-op
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
suspend_vms
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment