Gentoo Archives: gentoo-commits

From: "Doug Goldstein (cardoe)" <cardoe@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-emulation/libvirt/files: libvirtd.init-r11
Date: Sun, 04 Nov 2012 01:29:54
Message-Id: 20121104012938.6874F215FF@flycatcher.gentoo.org
1 cardoe 12/11/04 01:29:38
2
3 Added: libvirtd.init-r11
4 Log:
5 Version bump. Add support for firewalld as well.
6
7 (Portage version: 2.2.0_alpha142/cvs/Linux x86_64, unsigned Manifest commit)
8
9 Revision Changes Path
10 1.1 app-emulation/libvirt/files/libvirtd.init-r11
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r11?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r11?rev=1.1&content-type=text/plain
14
15 Index: libvirtd.init-r11
16 ===================================================================
17 #!/sbin/runscript
18
19 description="Virtual Machine Management daemon (libvirt)"
20 extra_started_commands="reload halt"
21 description_halt="Stops the libvirt daemon without stopping your VMs"
22 description_reload="Restarts the libvirt daemon without stopping your VMs"
23
24 depend() {
25 USE_FLAG_FIREWALLD
26 use USE_FLAG_AVAHI USE_FLAG_ISCSI USE_FLAG_RBD dbus
27 after ntp-client ntpd nfs nfsmount portmap rpc.statd iptables ip6tables ebtables corosync sanlock cgconfig
28 }
29
30 libvirtd_virsh() {
31 local mode=$1
32 shift
33
34 # Silence errors because virsh always throws an error about
35 # not finding the hypervisor version when connecting to libvirtd
36 LC_ALL=C virsh -c ${mode}:///system "$@" 2>/dev/null
37 }
38
39 libvirtd_dom_list() {
40 # Make sure that it wouldn't be confused if the domain name
41 # contains the word running.
42 libvirtd_virsh $1 list | awk '$3 == "running" { print $1 }'
43 }
44
45 libvirtd_dom_count() {
46 # Make sure that it wouldn't be confused if the domain name
47 # contains the word running.
48 libvirtd_virsh $1 list | awk 'BEGIN { count = 0 } \
49 $3 == "running" { count++ } \
50 END { print count }'
51 }
52
53 libvirtd_net_list() {
54 # The purpose of the awk is to avoid networks with 'active' in the name
55 libvirtd_virsh $1 net-list | awk '$2 == "active" { print $1 }'
56 }
57
58 libvirtd_net_count() {
59 # The purpose of the awk is to avoid networks with 'active' in the name
60 libvirtd_virsh $1 net-list | awk 'BEGIN { count = 0 } \
61 $2 == "active" { count++ } \
62 END { print count }'
63 }
64
65
66 start() {
67 ebegin "Starting libvirtd"
68 start-stop-daemon --start \
69 --env KRB5_KTNAME=/etc/libvirt/krb5.tab \
70 --exec /usr/sbin/libvirtd -- -d ${LIBVIRTD_OPTS}
71 eend $?
72 }
73
74 stop() {
75 local counter=
76 local vm_name=
77 local net_name=
78 local dom_id=
79
80 ebegin "Stopping libvirtd"
81 # try to shutdown all (KVM/Qemu) domains
82 if [ "${LIBVIRTD_KVM_SHUTDOWN}" != "none" ] \
83 && [ "$(libvirtd_dom_count qemu)" != "0" ] ; then
84
85 einfo " Shutting down domain(s):"
86 for dom_id in $(libvirtd_dom_list qemu) ; do
87 vm_name="$(libvirtd_virsh qemu domname ${dom_id} | head -n 1)"
88 einfo " ${vm_name}"
89 libvirtd_virsh qemu ${LIBVIRTD_KVM_SHUTDOWN} ${dom_id} > /dev/null
90 done
91
92 if [ -n "${LIBVIRTD_KVM_SHUTDOWN_MAXWAIT}" ] ; then
93 counter="${LIBVIRTD_KVM_SHUTDOWN_MAXWAIT}"
94 else
95 counter=500
96 fi
97
98 if [ "${LIBVIRTD_KVM_SHUTDOWN}" = "shutdown" ]; then
99 einfo " Waiting ${counter} seconds while domains shutdown ..."
100 DOM_COUNT="$(libvirtd_dom_count qemu)"
101 while [ ${DOM_COUNT} -gt 0 ] && [ ${counter} -gt 0 ] ; do
102 DOM_COUNT="$(libvirtd_dom_count qemu)"
103 sleep 1
104 counter=$((${counter} - 1))
105 echo -n "."
106 done
107 fi
108
109 if [ "$(libvirtd_dom_count qemu)" != "0" ] ; then
110 eerror " !!! Some guests are still running, stopping anyway"
111 fi
112
113 fi
114
115 if [ "${LIBVIRTD_KVM_NET_SHUTDOWN}" != "no" ] \
116 && [ "$(libvirtd_net_count qemu)" != "0" ]; then
117
118 einfo " Shutting down network(s):"
119 for net_name in $(libvirtd_net_list qemu); do
120 einfo " ${net_name}"
121 libvirtd_virsh qemu net-destroy ${net_name} > /dev/null
122 done
123
124 if [ "$(libvirtd_net_count qemu)" != "0" ]; then
125 eerror " !!! Some networks are still active, stopping anyway"
126 fi
127 fi
128
129 # Now actually stop the daemon
130 start-stop-daemon --stop --quiet --exec \
131 /usr/sbin/libvirtd --pidfile=/var/run/libvirtd.pid
132 eend $?
133 }
134
135 halt() {
136 ebegin "Stopping libvirtd without shutting down your VMs"
137 start-stop-daemon --stop --quiet --exec \
138 /usr/sbin/libvirtd --pidfile=/var/run/libvirtd.pid
139 eend $?
140 }
141
142 reload() {
143 halt
144 start
145 }