public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-x86 commit in app-emulation/libvirt/files: libvirtd.confd-r2 libvirtd.init-r2
@ 2011-01-27 21:02 Doug Goldstein (cardoe)
  0 siblings, 0 replies; only message in thread
From: Doug Goldstein (cardoe) @ 2011-01-27 21:02 UTC (permalink / raw
  To: gentoo-commits

cardoe      11/01/27 21:02:56

  Added:                libvirtd.confd-r2 libvirtd.init-r2
  Log:
  Add to the init script the shutting down of NATed networks created by libvirt itself. This functionality was written by Jan Vansteenkiste <jan@vstone.eu>. It complements the 'virt-network' USE flag.
  
  (Portage version: 2.1.9.35/cvs/Linux x86_64)

Revision  Changes    Path
1.1                  app-emulation/libvirt/files/libvirtd.confd-r2

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.confd-r2?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.confd-r2?rev=1.1&content-type=text/plain

Index: libvirtd.confd-r2
===================================================================
# /etc/conf.d/libvirtd

# LIBVIRTD_OPTS
# You may want to add '--listen' to have libvirtd listen for tcp/ip connections
# if you want to use libvirt for remote control
# Please consult 'libvirtd --help' for more options
#LIBVIRTD_OPTS="--listen"

# LIBVIRTD_KVM_SHUTDOWN
# Valid options:
# * shutdown - Sends an ACPI shutdown (think when you tap the power button
# 				on your machine and it begins a graceful shutdown). If your
# 				VM ignores this, it will have the power yanked out from under
# 				it in LIBVIRTD_KVM_SHUTDOWN_MAXWAIT seconds.
# * managedsave - Performs a state save external to the VM. qemu-kvm will stop
# 				stop the CPU and save off all state to a separate file. When
# 				the machine is started again, it will resume like nothing ever
# 				happened. This is guarenteed to always successfully stop your
# 				machine and restart it. However it may take some time to finish.
# * none - No attempts will be made to stop any VMs. If you are restarting your
# 		machine the qemu-kvm process will be simply killed, which may result
# 		in your VMs having disk corruption.
LIBVIRTD_KVM_SHUTDOWN="managedsave"

# LIBVIRTD_KVM_SHUTDOWN_MAXWAIT
# Timeout in seconds until stopping libvirtd and "pulling the plug" on the
# remaining VM's still in a running state
#LIBVIRTD_KVM_SHUTDOWN_MAXWAIT="500"

# LIBVIRTD_NET_SHUTDOWN
# If libvirtd created networks for you (e.g. NATed networks) then this init
# script will shut them down for you if this is set to 'yes'. Otherwise,
# the networks will be left running once libvirt is shutdown. For this
# option to be useful you must have enabled the 'virt-network' USE flag and
# have had libvirt create a NATed network for you.
# Valid values: 'yes' or 'no'
#LIBVIRTD_NET_SHUTDOWN="yes"



1.1                  app-emulation/libvirt/files/libvirtd.init-r2

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r2?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r2?rev=1.1&content-type=text/plain

Index: libvirtd.init-r2
===================================================================
#!/sbin/runscript

opts="start stop status reload restart"

depend() {
    need net
    before sshd ntp-client ntpd nfs nfsmount rsyncd portmap dhcp
}

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 }'
}

libvirtd_net_list() {
	# The purpose of the awk is to avoid networks with 'active' in the name
	libvirtd_virsh net-list | awk '$2 == "active" { print $1 }'
}

libvirtd_net_count() {
	# The purpose of the awk is to avoid networks with 'active' in the name
	libvirtd_virsh net-list | awk 'BEGIN { count = 0 } \
		$2 == "active" { 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 anyway"
        fi

    fi

	NET_COUNT="$(libvirtd_net_count)"
	if [ "${LIBVIRTD_NET_SHUTDOWN}" != "no" \
		&& "${NET_COUNT}" != "0" ]; then

		einfo " Shutting down network(s):"
			for NET_NAME in $(libvirtd_net_list); do
				einfo "   ${NET_NAME}"
				libvirtd_virsh net-destroy ${NET_NAME} > /dev/null
			done

		NET_COUNT="$(libvirtd_net_count)"
		if [ "${NET_COUNT}" != "0" ]; then
			eerror " !!! Some networks are still active, stopping anyway"
		fi
	fi

	# Now actually stop the daemon
    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 $?
}






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-01-27 21:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-27 21:02 [gentoo-commits] gentoo-x86 commit in app-emulation/libvirt/files: libvirtd.confd-r2 libvirtd.init-r2 Doug Goldstein (cardoe)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox