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