[Pkg-libvirt-maintainers] Bug#501155: Please add script for	automatic restart of kvm-based instances
    Andreas Barth 
    aba at not.so.argh.org
       
    Sat Oct  4 21:13:53 UTC 2008
    
    
  
Package: libvirt-bin
Version: 0.4.4-3
Hi,
this scripts works for me, I added it with
update-rc.d libvirt-suspendonreboot defaults 21 19
Nothing too great, but it makes sure kvm-domains survive a reboot of the host
machine (and it doesn't check for possible symlink attacks in
/var/lib/libvirt/autosuspend, so make sure that directory is root-only).
Cheers,
Andi
#! /bin/bash
# (c) Andi Barth <aba at not.so.argh.org> 2008
# Distributable under the terms of the GNU GPL version 2.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
suspenddir=/var/lib/libvirt/autosuspend
case "$1" in
  start)
    for domain in ${suspenddir}/*dump; do
        if [ -f $domain ]; then
            domain=$(basename $domain .dump)
            echo "resuming $domain ..."
            virsh restore ${suspenddir}/${domain}.dump && rm ${suspenddir}/${domain}.dump
        fi
    done
    ;;
  stop)
    for domain in /etc/libvirt/qemu/*xml; do
        domain=$(basename $domain .xml)
        state=$(virsh domstate $domain)
        if [ "$state" == "running" ]; then
            echo "suspending $domain ..."
            virsh save ${domain} ${suspenddir}/${domain}.dump
        fi
    done
    ;;
  reload|force-reload|restart)
    # No action, nothing to reload
    ;;
  *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
        exit 1
esac
    
    
More information about the Pkg-libvirt-maintainers
mailing list