1 |
tamiko 15/06/24 09:48:26 |
2 |
|
3 |
Added: libvirtd.init-r15 libvirtd.confd-r5 |
4 |
Log: |
5 |
provide a configuration option for domains and network on restart, bug #551854 |
6 |
|
7 |
(Portage version: 2.2.18/cvs/Linux x86_64, signed Manifest commit with key BD3A97A3) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 app-emulation/libvirt/files/libvirtd.init-r15 |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r15?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r15?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: libvirtd.init-r15 |
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 virtlockd |
27 |
after ntp-client ntpd nfs nfsmount portmap rpc.statd iptables ip6tables ebtables corosync sanlock cgconfig xenconsoled |
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 |
# Test configuration directories in /etc/libvirt/ to be either not |
68 |
# present or a directory, i.e. not a regular file, bug #532892 |
69 |
for dir in lxc nwfilter qemu storage; do |
70 |
if [ -f /etc/libvirt/$dir ]; then |
71 |
eerror "/etc/libvirt/$dir was created as a regular file. It must be either" |
72 |
eerror "a directory or not present for libvirtd to start up successfully." |
73 |
return 1 |
74 |
fi |
75 |
done |
76 |
|
77 |
ebegin "Starting libvirtd" |
78 |
start-stop-daemon --start \ |
79 |
--env KRB5_KTNAME=/etc/libvirt/krb5.tab \ |
80 |
--exec /usr/sbin/libvirtd -- -d ${LIBVIRTD_OPTS} |
81 |
eend $? |
82 |
} |
83 |
|
84 |
stop() { |
85 |
local policy= |
86 |
local counter= |
87 |
local net_policy= |
88 |
local vm_name= |
89 |
local net_name= |
90 |
local dom_id= |
91 |
|
92 |
ebegin "Stopping libvirtd" |
93 |
|
94 |
if [ "${RC_CMD}" = "restart" -a -n "${LIBVIRTD_KVM_RESTART}" ] ; then |
95 |
policy="${LIBVIRTD_KVM_RESTART}" |
96 |
else |
97 |
policy="${LIBVIRTD_KVM_SHUTDOWN}" |
98 |
fi |
99 |
|
100 |
# sanitize policy: |
101 |
if [ "${policy}" != "none" -a "${policy}" != "managedsave" -a "${policy}" != "shutdown" ] ; then |
102 |
if [ -n "${policy}" ] ; then |
103 |
eerror " !!! Invalid policy \"${policy}\" specified in LIBVIRTD_KVM_SHUTDOWN/RESTART" |
104 |
fi |
105 |
einfo " Using default policy \"managedsave\" for domains" |
106 |
policy="managedsave" |
107 |
fi |
108 |
|
109 |
if [ -n "${LIBVIRTD_KVM_SHUTDOWN_MAXWAIT}" ] ; then |
110 |
counter="${LIBVIRTD_KVM_SHUTDOWN_MAXWAIT}" |
111 |
else |
112 |
counter=500 |
113 |
fi |
114 |
|
115 |
if [ "${RC_CMD}" = "restart" -a -n "${LIBVIRTD_KVM_NET_RESTART}" ] ; then |
116 |
net_policy="${LIBVIRTD_KVM_NET_RESTART}" |
117 |
else |
118 |
net_policy="${LIBVIRTD_KVM_NET_SHUTDOWN}" |
119 |
fi |
120 |
|
121 |
# try to shutdown all (KVM/Qemu) domains |
122 |
if [ "${policy}" != "none" ] \ |
123 |
&& [ "$(libvirtd_dom_count qemu)" != "0" ] ; then |
124 |
|
125 |
einfo " Shutting down domain(s):" |
126 |
for dom_id in $(libvirtd_dom_list qemu) ; do |
127 |
vm_name="$(libvirtd_virsh qemu domname ${dom_id} | head -n 1)" |
128 |
einfo " ${vm_name}" |
129 |
libvirtd_virsh qemu ${policy} ${dom_id} > /dev/null |
130 |
done |
131 |
|
132 |
if [ "${policy}" = "shutdown" ]; then |
133 |
einfo " Waiting ${counter} seconds while domains shutdown ..." |
134 |
DOM_COUNT="$(libvirtd_dom_count qemu)" |
135 |
while [ ${DOM_COUNT} -gt 0 ] && [ ${counter} -gt 0 ] ; do |
136 |
DOM_COUNT="$(libvirtd_dom_count qemu)" |
137 |
sleep 1 |
138 |
counter=$((${counter} - 1)) |
139 |
echo -n "." |
140 |
done |
141 |
fi |
142 |
|
143 |
if [ "$(libvirtd_dom_count qemu)" != "0" ] ; then |
144 |
eerror " !!! Some guests are still running, stopping anyway" |
145 |
fi |
146 |
fi |
147 |
|
148 |
# try to shutdown all networks |
149 |
if [ "${net_policy}" != "no" ] \ |
150 |
&& [ "$(libvirtd_net_count qemu)" != "0" ]; then |
151 |
|
152 |
einfo " Shutting down network(s):" |
153 |
for net_name in $(libvirtd_net_list qemu); do |
154 |
einfo " ${net_name}" |
155 |
libvirtd_virsh qemu net-destroy ${net_name} > /dev/null |
156 |
done |
157 |
|
158 |
if [ "$(libvirtd_net_count qemu)" != "0" ]; then |
159 |
eerror " !!! Some networks are still active, stopping anyway" |
160 |
fi |
161 |
fi |
162 |
|
163 |
# Now actually stop the daemon |
164 |
start-stop-daemon --stop --quiet --exec \ |
165 |
/usr/sbin/libvirtd --pidfile=/var/run/libvirtd.pid |
166 |
eend $? |
167 |
} |
168 |
|
169 |
halt() { |
170 |
ebegin "Stopping libvirtd without shutting down your VMs" |
171 |
start-stop-daemon --stop --quiet --exec \ |
172 |
/usr/sbin/libvirtd --pidfile=/var/run/libvirtd.pid |
173 |
eend $? |
174 |
} |
175 |
|
176 |
reload() { |
177 |
halt |
178 |
start |
179 |
} |
180 |
|
181 |
|
182 |
|
183 |
1.1 app-emulation/libvirt/files/libvirtd.confd-r5 |
184 |
|
185 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.confd-r5?rev=1.1&view=markup |
186 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.confd-r5?rev=1.1&content-type=text/plain |
187 |
|
188 |
Index: libvirtd.confd-r5 |
189 |
=================================================================== |
190 |
# /etc/conf.d/libvirtd |
191 |
|
192 |
# Startup dependency |
193 |
# libvirtd typically requires all networks to be up and settled which |
194 |
# is what rc_need="net" provides. However if you only use specific networks |
195 |
# for libvirtd, you may override this. Or if you only use libvirtd locally. |
196 |
rc_need="net" |
197 |
|
198 |
# LIBVIRTD_OPTS |
199 |
# You may want to add '--listen' to have libvirtd listen for tcp/ip |
200 |
# connections if you want to use libvirt for remote control. Please |
201 |
# consult 'libvirtd --help' for more options. |
202 |
#LIBVIRTD_OPTS="--listen" |
203 |
|
204 |
# LIBVIRTD_KVM_SHUTDOWN |
205 |
# controls the behavior for kvm guests on daemon shutdown |
206 |
# |
207 |
# Valid options: |
208 |
# * shutdown |
209 |
# - Sends an ACPI shutdown (think when you tap the power button on your |
210 |
# machine and it begins a graceful shutdown). If your VM ignores this, |
211 |
# it will have the power yanked out from under it in |
212 |
# LIBVIRTD_KVM_SHUTDOWN_MAXWAIT seconds. |
213 |
# * managedsave |
214 |
# - Performs a state save external to the VM. qemu-kvm will stop stop the |
215 |
# CPU and save off all state to a separate file. When the machine is |
216 |
# started again, it will resume like nothing ever happened. This is |
217 |
# guarenteed to always successfully stop your machine and restart it. |
218 |
# However it may take some time to finish. |
219 |
# * none |
220 |
# - No attempts will be made to stop any VMs. If you are restarting your |
221 |
# machine the qemu-kvm process will be simply killed, which may result |
222 |
# in your VMs having disk corruption. |
223 |
LIBVIRTD_KVM_SHUTDOWN="managedsave" |
224 |
|
225 |
# LIBVIRTD_KVM_SHUTDOWN_MAXWAIT |
226 |
# timeout in seconds until stopping libvirtd and "pulling the plug" on |
227 |
# the remaining VM's still in a running state |
228 |
LIBVIRTD_KVM_SHUTDOWN_MAXWAIT="500" |
229 |
|
230 |
# LIBVIRTD_KVM_RESTART |
231 |
# controls the behavior for kvm guests on daemon restart |
232 |
# |
233 |
# Valid options: |
234 |
# * <empty> |
235 |
# - apply the same policy on daemon restart as defined by |
236 |
# LIBVIRTD_KVM_SHUTDOWN for the shutdown |
237 |
# * shutdown |
238 |
# * managedsave |
239 |
# * none |
240 |
# - as defined for LIBVIRTD_KVM_SHUTDOWN |
241 |
LIBVIRTD_KVM_RESTART="" |
242 |
|
243 |
# LIBVIRTD_KVM_NET_SHUTDOWN |
244 |
# If libvirtd created networks for you (e.g. NATed networks) then this |
245 |
# init script will shut them down for you if this is set to 'yes'. |
246 |
# Otherwise, the networks will be left running once libvirt is shutdown. |
247 |
# For this option to be useful you must have enabled the 'virt-network' |
248 |
# USE flag and have had libvirt create a NATed network for you. Valid |
249 |
# values: 'yes' or 'no' |
250 |
LIBVIRTD_KVM_NET_SHUTDOWN="yes" |
251 |
|
252 |
# LIBVIRTD_KVM_NET_RESTART |
253 |
# Valid options: |
254 |
# * <empty> |
255 |
# - apply the same policy on daemon restart as defined by |
256 |
# LIBVIRTD_KVM_NET_SHUTDOWN for the shutdown |
257 |
# * yes |
258 |
# * no |
259 |
# - as defined for LIBVIRTD_KVM_NET_SHUTDOWN |
260 |
LIBVIRTD_KVM_NET_RESTART="" |