diff options
author | Leonardo Arena <rnalrd@gmail.com> | 2011-05-16 13:59:53 +0000 |
---|---|---|
committer | Leonardo Arena <rnalrd@gmail.com> | 2011-05-16 14:00:58 +0000 |
commit | d44c14790917243e49797896a79c6fefc9a9b94d (patch) | |
tree | 37dd46ddaf26c9c2d68002a7b711f0503c22c3e6 /main/libvirt/libvirt.initd | |
parent | d95f46d8f7ee391376b9870c16918227a7311b90 (diff) | |
download | aports-d44c14790917243e49797896a79c6fefc9a9b94d.tar.bz2 aports-d44c14790917243e49797896a79c6fefc9a9b94d.tar.xz |
testing/libvirt: move to main
Diffstat (limited to 'main/libvirt/libvirt.initd')
-rw-r--r-- | main/libvirt/libvirt.initd | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/main/libvirt/libvirt.initd b/main/libvirt/libvirt.initd new file mode 100644 index 0000000000..d0b9d34a01 --- /dev/null +++ b/main/libvirt/libvirt.initd @@ -0,0 +1,87 @@ +#!/sbin/runscript + +opts="start stop status reload restart" + +depend() { + need net + after firewall +} + +libvirtd_virsh() { + # Silence errors because virsh always throws an error about + # not finding the hypervisor version when connecting to libvirtd + LC_ALL=C virsh -c qemu:///system "$@" 2>/dev/null +} + +libvirtd_dom_list() { + # Make sure that it wouldn't be confused if the domain name + # contains the word running. + libvirtd_virsh list | awk '$3 == "running" { print $1 }' +} + +libvirtd_dom_count() { + # Make sure that it wouldn't be confused if the domain name + # contains the word running. + libvirtd_virsh list | awk 'BEGIN { count = 0 } \ + $3 == "running" { count++ } \ + END { print count }' +} + +start() { + ebegin "Starting libvirtd" + start-stop-daemon --start \ + --env KRB5_KTNAME=/etc/libvirt/krb5.tab \ + --exec /usr/sbin/libvirtd -- -d ${LIBVIRTD_OPTS} + eend $? +} + +stop() { + ebegin "Stopping libvirtd" + # try to shutdown all (KVM/Qemu) domains + DOM_COUNT="$(libvirtd_dom_count)" + if [ "${LIBVIRTD_KVM_SHUTDOWN}" != "none" ] \ + && [ "${DOM_COUNT}" != "0" ] ; then + + einfo " Shutting down domain(s):" + for DOM_ID in $(libvirtd_dom_list) ; do + NAME="$(libvirtd_virsh domname ${DOM_ID} | head -n 1)" + einfo " ${NAME}" + libvirtd_virsh ${LIBVIRTD_KVM_SHUTDOWN} ${DOM_ID} > /dev/null + done + + if [ -n "${LIBVIRTD_KVM_SHUTDOWN_MAXWAIT}" ] ; then + COUNTER="${LIBVIRTD_KVM_SHUTDOWN_MAXWAIT}" + else + COUNTER=500 + fi + + if [ "${LIBVIRTD_KVM_SHUTDOWN}" = "shutdown" ]; then + einfo " Waiting ${COUNTER} seconds while domains shutdown ..." + DOM_COUNT="$(libvirtd_dom_count)" + while [ ${DOM_COUNT} -gt 0 ] && [ ${COUNTER} -gt 0 ] ; do + DOM_COUNT="$(libvirtd_dom_count)" + sleep 1 + COUNTER=$((${COUNTER} - 1)) + echo -n "." + done + fi + + DOM_COUNT="$(libvirtd_dom_count)" + if [ "${DOM_COUNT}" != "0" ] ; then + eerror " !!! Some guests are still running, stopping anyways" + fi + + fi + start-stop-daemon --stop --quiet --exec /usr/sbin/libvirtd --pidfile=/var/run/libvirtd.pid + eend $? +} + +reload() { + ebegin "Reloading libvirtd without shutting down your VMs" + start-stop-daemon --stop --quiet --exec /usr/sbin/libvirtd --pidfile=/var/run/libvirtd.pid + if [ $? -ne 0 ]; then + eend $? + fi + start-stop-daemon --start --quiet --exec /usr/sbin/libvirtd -- -d ${LIBVIRTD_OPTS} + eend $? +} |