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

Proposed by Serge Hallyn
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
debian/changelog (+7/-0)
debian/libvirt-bin.upstart (+63/-1)
To merge this branch: bzr merge lp:~serge-hallyn/ubuntu/oneiric/libvirt/fix-shutdown
Reviewer Review Type Date Requested Status
Clint Byrum (community) Approve
Review via email: mp+70245@code.launchpad.net
To post a comment you must log in.
Revision history for this message
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

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

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: