Ubuntu

Merge lp:~serge-hallyn/ubuntu/oneiric/libvirt/fix-shutdown into lp:ubuntu/oneiric/libvirt

Proposed by Serge Hallyn on 2011-08-03
Status: Needs review
Proposed branch: lp:~serge-hallyn/ubuntu/oneiric/libvirt/fix-shutdown
Merge into: lp:ubuntu/oneiric/libvirt
Diff against target: 102 lines (+70/-1) 2 files modified
To merge this branch: bzr merge lp:~serge-hallyn/ubuntu/oneiric/libvirt/fix-shutdown
Reviewer Review Type Date Requested Status
Clint Byrum 2011-08-03 Approve on 2011-08-03
Review via email: mp+70245@code.launchpad.net
To post a comment you must log in.
Clint Byrum (clint-fewbar) wrote :

This looks good, I like the use of pre-stop and the fact that this definitively blocks the shutdown until it is done.

review: Approve

Unmerged revisions

120. By Serge Hallyn on 2011-08-03

libvirt-bin.upstart: add a pre-stop script to shut down running VMs
before the host shuts down. (LP: #350936)

Preview Diff

1=== modified file 'debian/changelog'
2--- debian/changelog 2011-07-19 14:20:20 +0000
3+++ debian/changelog 2011-08-03 03:02:29 +0000
4@@ -1,3 +1,10 @@
5+libvirt (0.9.2-4ubuntu7) oneiric; urgency=low
6+
7+ * libvirt-bin.upstart: add a pre-stop script to shut down running VMs
8+ before the host shuts down. (LP: #350936)
9+
10+ -- Serge Hallyn <serge.hallyn@ubuntu.com> Tue, 02 Aug 2011 19:49:40 -0500
11+
12 libvirt (0.9.2-4ubuntu6) oneiric; urgency=low
13
14 * SECURITY UPDATE: integer overflow in virDomainGetVcpus()
15
16=== modified file 'debian/libvirt-bin.upstart'
17--- debian/libvirt-bin.upstart 2011-07-19 14:20:20 +0000
18+++ debian/libvirt-bin.upstart 2011-08-03 03:02:29 +0000
19@@ -2,13 +2,20 @@
20 author "Dustin Kirkland <kirkland@canonical.com>"
21
22 start on (runlevel [2345] and stopped networking RESULT=ok)
23-stop on runlevel [!2345]
24+stop on starting rc RUNLEVEL=[016]
25
26 expect daemon
27 respawn
28
29+# daemonize
30 env libvirtd_opts="-d"
31+# whether libvirtd should run at boot/shutdown
32 env start_libvirtd="yes"
33+# by default wait 30 seconds for vms to shut down
34+env libvirtd_shutdown_timeout=30
35+# uris for which to shut down vms
36+env libvirt_uris='qemu:///system lxc:///'
37+
38 pre-start script
39 [ -r /etc/default/libvirt-bin ] && . /etc/default/libvirt-bin
40 [ ! "x$start_libvirtd" = "xyes" ] && { stop; exit 0; }
41@@ -17,6 +24,61 @@
42 rm -f /var/run/libvirtd.pid
43 end script
44
45+pre-stop script
46+ [ -r /etc/default/libvirt-bin ] && . /etc/default/libvirt-bin
47+
48+ log_msg()
49+ {
50+ logf="/var/log/libvirt/shutdownlog.log"
51+ logger -p daemon.debug -s -t libvirt -- "$@" >> $logf 2>&1
52+ }
53+
54+ run_virsh()
55+ {
56+ # We parse the output for things like domain state;
57+ # make sure the output is in the language we expect.
58+ LANG=C virsh "$@"
59+ }
60+
61+ if [ -z "$RUNLEVEL" ]; then
62+ exit 0
63+ fi
64+
65+ if [ "$RUNLEVEL" -ne 0 ] && [ "$RUNLEVEL" -ne 1 ] && [ "$RUNLEVEL" -ne 6 ]; then
66+ exit 0
67+ fi
68+ log_msg "libvirt-bin: entering pre-stop at $(date)"
69+
70+ for uri in $libvirt_uris; do
71+ for domain in $(run_virsh -c "$uri" list | awk '$3 == "running" {print $2}'); do
72+ log_msg "libvirt-bin: attempting clean shutdown of $domain at $(date)"
73+ run_virsh -c "$uri" shutdown "$domain" >/dev/null
74+ done
75+ done
76+
77+ delay=$libvirtd_shutdown_timeout
78+ while [ $delay -gt 0 ]; do
79+ for uri in $libvirt_uris; do
80+ if ! run_virsh -c "$uri" list | awk '$3 == "running" {exit 1}'; then
81+ # VMs at this URI are still running. Wait, then
82+ # start at the beginning looking for running VMs.
83+ sleep 1
84+ delay=$(($delay - 1))
85+ continue 2
86+ fi
87+ done
88+ break
89+ done
90+
91+ for uri in $libvirt_uris; do
92+ for domain in $(run_virsh -c "$uri" list | awk '$3 == "running" {print $2}'); do
93+ log_msg "destroying $domain"
94+ run_virsh -c "$uri" destroy "$domain" >/dev/null
95+ done
96+ done
97+ log_msg "libvirt-bin: exiting pre-stop at $(date)"
98+end script
99+
100 # If you used to set $libvirtd_opts in /etc/default/libvirt-bin,
101 # change the 'exec' line here instead.
102 exec /usr/sbin/libvirtd $libvirtd_opts

Subscribers

People subscribed via source and target branches

to all changes: