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