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-r10 libvirtd.confd-r4
Date: Tue, 30 Oct 2012 04:43:54
Message-Id: 20121030044343.42FBD21601@flycatcher.gentoo.org
1 cardoe 12/10/30 04:43:43
2
3 Added: libvirtd.init-r10 libvirtd.confd-r4
4 Log:
5 Version bump. Tweak to the init script to better support need net in newer OpenRC and to start up init scripts we are dependant on based on USE flags.
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-r10
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r10?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.init-r10?rev=1.1&content-type=text/plain
14
15 Index: libvirtd.init-r10
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_AVAHI
26 use USE_FLAG_ISCSI USE_FLAG_RBD
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 }
146
147
148
149 1.1 app-emulation/libvirt/files/libvirtd.confd-r4
150
151 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.confd-r4?rev=1.1&view=markup
152 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-emulation/libvirt/files/libvirtd.confd-r4?rev=1.1&content-type=text/plain
153
154 Index: libvirtd.confd-r4
155 ===================================================================
156 # /etc/conf.d/libvirtd
157
158 # Startup dependency
159 # libvirtd typically requires all networks to be up and settled which
160 # is what rc_need="net" provides. However if you only use specific networks
161 # for libvirtd, you may override this. Or if you only use libvirtd locally.
162 rc_need="net"
163
164 # LIBVIRTD_OPTS
165 # You may want to add '--listen' to have libvirtd listen for tcp/ip connections
166 # if you want to use libvirt for remote control
167 # Please consult 'libvirtd --help' for more options
168 #LIBVIRTD_OPTS="--listen"
169
170 # LIBVIRTD_KVM_SHUTDOWN
171 # Valid options:
172 # * shutdown - Sends an ACPI shutdown (think when you tap the power button
173 # on your machine and it begins a graceful shutdown). If your
174 # VM ignores this, it will have the power yanked out from under
175 # it in LIBVIRTD_KVM_SHUTDOWN_MAXWAIT seconds.
176 # * managedsave - Performs a state save external to the VM. qemu-kvm will stop
177 # stop the CPU and save off all state to a separate file. When
178 # the machine is started again, it will resume like nothing ever
179 # happened. This is guarenteed to always successfully stop your
180 # machine and restart it. However it may take some time to finish.
181 # * none - No attempts will be made to stop any VMs. If you are restarting your
182 # machine the qemu-kvm process will be simply killed, which may result
183 # in your VMs having disk corruption.
184 LIBVIRTD_KVM_SHUTDOWN="managedsave"
185
186 # LIBVIRTD_KVM_SHUTDOWN_MAXWAIT
187 # Timeout in seconds until stopping libvirtd and "pulling the plug" on the
188 # remaining VM's still in a running state
189 #LIBVIRTD_KVM_SHUTDOWN_MAXWAIT="500"
190
191 # LIBVIRTD_KVM_NET_SHUTDOWN
192 # If libvirtd created networks for you (e.g. NATed networks) then this init
193 # script will shut them down for you if this is set to 'yes'. Otherwise,
194 # the networks will be left running once libvirt is shutdown. For this
195 # option to be useful you must have enabled the 'virt-network' USE flag and
196 # have had libvirt create a NATed network for you.
197 # Valid values: 'yes' or 'no'
198 #LIBVIRTD_KVM_NET_SHUTDOWN="yes"