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