Ubuntu Pastebin

Paste from serge at Wed, 12 Aug 2015 03:05:59 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
diff -Nru libvirt-1.2.16/debian/changelog libvirt-1.2.16/debian/changelog
--- libvirt-1.2.16/debian/changelog	2015-07-27 14:43:02.000000000 -0500
+++ libvirt-1.2.16/debian/changelog	2015-08-11 22:01:32.000000000 -0500
@@ -1,3 +1,18 @@
+libvirt (1.2.16-2ubuntu7) wily; urgency=medium
+
+  * Stop libvirt-bin at pre-inst if upgrading from a non-systemd version,
+    restart at postinst.  (This can be removed after 16.10)
+  * Commonize stopping of vms across upstart/sysvinit/systemd.
+
+ -- Serge Hallyn <serge.hallyn@ubuntu.com>  Tue, 11 Aug 2015 17:40:36 -0500
+
+libvirt (1.2.16-2ubuntu6) wily; urgency=medium
+
+  * Add systemd units and libvirt-stop-guests script to stop VMs before
+    a host completes shutdown  (LP: #1480440)
+
+ -- Serge Hallyn <serge.hallyn@ubuntu.com>  Tue, 11 Aug 2015 15:42:29 -0500
+
 libvirt (1.2.16-2ubuntu5) wily; urgency=medium
 
   * debian/control changes:
diff -Nru libvirt-1.2.16/debian/control libvirt-1.2.16/debian/control
--- libvirt-1.2.16/debian/control	2015-07-27 14:43:51.000000000 -0500
+++ libvirt-1.2.16/debian/control	2015-08-11 17:45:48.000000000 -0500
@@ -7,6 +7,7 @@
 Testsuite: autopkgtest
 Build-Depends: cdbs (>= 0.4.90~),
  debhelper (>= 7),
+ dh-systemd (>= 1.18~),
  dh-autoreconf,
  libxml2-dev,
  libcurl4-gnutls-dev,
@@ -41,6 +42,7 @@
  libnetcf-dev (>= 1:0.2.3-3~) [linux-any],
  libaudit-dev [linux-any],
  libapparmor-dev [linux-any],
+ libsystemd-daemon-dev [linux-any],
  nfs-common,
  librbd-dev [linux-any],
 # For "make check"
diff -Nru libvirt-1.2.16/debian/libvirt-bin.init libvirt-1.2.16/debian/libvirt-bin.init
--- libvirt-1.2.16/debian/libvirt-bin.init	2015-07-10 15:14:14.000000000 -0500
+++ libvirt-1.2.16/debian/libvirt-bin.init	2015-08-11 17:21:11.000000000 -0500
@@ -126,9 +126,10 @@
 	log_daemon_msg "Stopping $DESC" "$NAME"
 	if ! running ;  then
            	log_progress_msg "not running"
-            	log_end_msg 0
-            	exit 0
-       	fi
+                log_end_msg 0
+                exit 0
+        fi
+        /usr/lib/libvirt/libvirt-stop-guests
 	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
 		--exec $DAEMON
 	log_end_msg 0
diff -Nru libvirt-1.2.16/debian/libvirt-bin.install libvirt-1.2.16/debian/libvirt-bin.install
--- libvirt-1.2.16/debian/libvirt-bin.install	2015-07-10 15:14:14.000000000 -0500
+++ libvirt-1.2.16/debian/libvirt-bin.install	2015-08-11 15:37:28.000000000 -0500
@@ -16,3 +16,4 @@
 usr/share/apport/package-hooks/source_libvirt.py
 etc/dnsmasq.d-available/libvirt-bin
 etc/profile.d/libvirt-uri.sh
+usr/lib/libvirt
diff -Nru libvirt-1.2.16/debian/libvirt-bin.libvirt-bin.service libvirt-1.2.16/debian/libvirt-bin.libvirt-bin.service
--- libvirt-1.2.16/debian/libvirt-bin.libvirt-bin.service	1969-12-31 18:00:00.000000000 -0600
+++ libvirt-1.2.16/debian/libvirt-bin.libvirt-bin.service	2015-08-11 15:37:28.000000000 -0500
@@ -0,0 +1,22 @@
+[Unit]
+Description=Virtualization daemon
+Before=libvirt-guests.service
+After=network.target
+After=dbus.service
+After=iscsid.service
+After=apparmor.service
+Documentation=man:libvirtd(8)
+Documentation=http://libvirt.org
+
+[Service]
+Type=notify
+Environment=LIBVIRTD_ARGS= KRB5_KTNAME=/etc/libvirt/libvirt.keytab
+ExecStart=/usr/sbin/libvirtd $LIBVIRTD_ARGS
+ExecReload=/bin/kill -HUP $MAINPID
+KillMode=process
+Restart=on-failure
+# Override the maximum number of opened files
+#LimitNOFILE=2048
+
+[Install]
+WantedBy=multi-user.target
diff -Nru libvirt-1.2.16/debian/libvirt-bin.libvirt-guests.service libvirt-1.2.16/debian/libvirt-bin.libvirt-guests.service
--- libvirt-1.2.16/debian/libvirt-bin.libvirt-guests.service	1969-12-31 18:00:00.000000000 -0600
+++ libvirt-1.2.16/debian/libvirt-bin.libvirt-guests.service	2015-08-11 15:37:28.000000000 -0500
@@ -0,0 +1,14 @@
+[Unit]
+Description=Stop Active Libvirt Guests
+After=network.target libvirtd.service time-sync.target systemd-machined.target
+
+[Service]
+ExecStart=/bin/true
+ExecStop=/usr/lib/libvirt/libvirt-stop-guests
+TimeoutStopSec=60
+Type=oneshot
+RemainAfterExit=yes
+StandardOutput=journal+console
+
+[Install]
+WantedBy=multi-user.target
diff -Nru libvirt-1.2.16/debian/libvirt-bin.postinst libvirt-1.2.16/debian/libvirt-bin.postinst
--- libvirt-1.2.16/debian/libvirt-bin.postinst	2015-07-10 15:14:15.000000000 -0500
+++ libvirt-1.2.16/debian/libvirt-bin.postinst	2015-08-11 22:01:04.000000000 -0500
@@ -216,12 +216,20 @@
     #    symlink wrongly, recreate it
     EXISTED="/etc/libvirt/qemu/networks/autostart/TMP_defaultexisted"
     if [ -z $2 ]; then
-    	maybe_set_autostart
+        maybe_set_autostart
     elif [ -e "$EXISTED" ]; then
         # on upgrade, if default network was previously autostarted,
-	# continue to do so.
-    	rm -f "$EXISTED"
-	set_autostart
+        # continue to do so.
+        rm -f "$EXISTED"
+        set_autostart
+    fi
+
+    # restart libvirt-bin if we had to turn it off.
+    # remove this after 16.10 release
+    WASRUNNING="/run/libvirt/wasrunning"
+    if [ -e "$WASRUNNING" ]; then
+        service libvirt-bin start
+        rm -f "$WASRUNNING"
     fi
 
     ;;
diff -Nru libvirt-1.2.16/debian/libvirt-bin.preinst libvirt-1.2.16/debian/libvirt-bin.preinst
--- libvirt-1.2.16/debian/libvirt-bin.preinst	2015-07-10 15:14:14.000000000 -0500
+++ libvirt-1.2.16/debian/libvirt-bin.preinst	2015-08-11 22:00:57.000000000 -0500
@@ -10,7 +10,16 @@
 		if [ -e /etc/libvirt/qemu/networks/autostart/default.xml ]; then
 			touch "$EXISTED"
 		fi
-		;;
+		# Stop libvirt if we are switching to systemd
+		# remove this after 16.10 release
+		WASRUNNING="/run/libvirt/wasrunning"
+		if [ -n "$2" ] &&  dpkg --compare-versions "$2" le 1.2.16-2ubuntu7; then
+			if service libvirt-bin status > /dev/null 2>&1; then
+				service libvirt-bin stop
+				touch "$WASRUNNING"
+			fi
+		fi
+			;;
 
 	install|abort-upgrade)
 
diff -Nru libvirt-1.2.16/debian/libvirt-bin.upstart libvirt-1.2.16/debian/libvirt-bin.upstart
--- libvirt-1.2.16/debian/libvirt-bin.upstart	2015-07-10 15:14:15.000000000 -0500
+++ libvirt-1.2.16/debian/libvirt-bin.upstart	2015-08-11 17:33:33.000000000 -0500
@@ -39,21 +39,6 @@
 end script
 
 pre-stop script
-	[ -r /etc/default/libvirt-bin ] && . /etc/default/libvirt-bin
-
-	log_msg()
-	{
-		logf="/var/log/libvirt/shutdownlog.log"
-		logger -p daemon.debug -s -t libvirt -- "$@" >> $logf 2>&1
-	}
-
-	run_virsh()
-	{
-		# We parse the output for things like domain state;
-		# make sure the output is in the language we expect.
-		LANG=C virsh "$@" 2>/dev/null
-	}
-
 	if [ -z "$RUNLEVEL" ]; then
 		exit 0
 	fi
@@ -61,36 +46,8 @@
 	if [ "$RUNLEVEL" -ne 0 ] && [ "$RUNLEVEL" -ne 1 ] && [ "$RUNLEVEL" -ne 6 ]; then
 		exit 0
 	fi
-	log_msg "libvirt-bin: entering pre-stop at $(date)"
-
-	for uri in $libvirt_uris; do
-		for domain in $(run_virsh -c "$uri" list | awk '$3 == "running" {print $2}'); do
-			log_msg "libvirt-bin: attempting clean shutdown of $domain at $(date)"
-			run_virsh -c "$uri" shutdown "$domain" >/dev/null
-		done
-	done
-
-	delay=$libvirtd_shutdown_timeout
-	while [ $delay -gt 0 ]; do
-		for uri in $libvirt_uris; do
-			if ! run_virsh -c "$uri" list | awk '$3 == "running" {exit 1}'; then
-				# VMs at this URI are still running. Wait, then
-				# start at the beginning looking for running VMs.
-				sleep 1
-				delay=$(($delay - 1))
-				continue 2
-			fi
-		done
-		break
-	done
 
-	for uri in $libvirt_uris; do
-		for domain in $(run_virsh -c "$uri" list | awk '$3 == "running" {print $2}'); do
-			log_msg "destroying $domain"
-			run_virsh -c "$uri" destroy "$domain" >/dev/null
-		done
-	done
-	log_msg "libvirt-bin: exiting pre-stop at $(date)"
+        /usr/lib/libvirt/libvirt-stop-guests
 end script
 
 # /etc/default/libvirt-bin will be deprecated soon.
diff -Nru libvirt-1.2.16/debian/libvirt-stop-guests libvirt-1.2.16/debian/libvirt-stop-guests
--- libvirt-1.2.16/debian/libvirt-stop-guests	1969-12-31 18:00:00.000000000 -0600
+++ libvirt-1.2.16/debian/libvirt-stop-guests	2015-08-11 17:32:15.000000000 -0500
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+libvirt_uris='qemu:///system lxc:/// xen:///'
+libvirtd_shutdown_timeout=30
+
+[ -r /etc/default/libvirt-bin ] && . /etc/default/libvirt-bin
+
+run_virsh()
+{
+    # We parse the output for things like domain state;
+    # make sure the output is in the language we expect.
+    LANG=C virsh "$@" 2>/dev/null
+}
+
+log_msg()
+{
+    logf="/var/log/libvirt/shutdownlog.log"
+    logger -p daemon.debug -s -t libvirt -- "$@" >> $logf 2>&1
+}
+
+wait_on_vms() {
+	log_msg "libvirt-bin: starting wait_on_vms at $(date)"
+	for uri in $libvirt_uris; do
+		for domain in $(run_virsh -c "$uri" list | awk '$3 == "running" {print $2}'); do
+			log_msg "libvirt-bin: attempting clean shutdown of $uri:$domain at $(date)"
+			run_virsh -c "$uri" shutdown "$domain" >/dev/null
+		done
+	done
+
+	delay=$libvirtd_shutdown_timeout
+	while [ $delay -gt 0 ]; do
+		for uri in $libvirt_uris; do
+			if ! run_virsh -c "$uri" list | awk '$3 == "running" {exit 1}'; then
+				# VMs at this URI are still running. Wait, then
+				# start at the beginning looking for running VMs.
+				sleep 1
+				delay=$(($delay - 1))
+				continue 2
+			fi
+		done
+		break
+	done
+
+	for uri in $libvirt_uris; do
+		for domain in $(run_virsh -c "$uri" list | awk '$3 == "running" {print $2}'); do
+			log_msg "destroying $uri:$domain"
+			run_virsh -c "$uri" destroy "$domain" >/dev/null
+		done
+	done
+	log_msg "libvirt-bin: done with wait_on_vms at $(date)"
+}
+
+wait_on_vms
diff -Nru libvirt-1.2.16/debian/rules libvirt-1.2.16/debian/rules
--- libvirt-1.2.16/debian/rules	2015-07-10 15:14:14.000000000 -0500
+++ libvirt-1.2.16/debian/rules	2015-08-11 15:37:28.000000000 -0500
@@ -45,6 +45,8 @@
   else
       WITH_LXC        = --with-lxc
   endif
+  WITH_INIT_SCRIPT    = --with-init-script=systemd
+  WITH_SYSTEMD        = --with-systemd-daemon
 else
   WITH_STORAGE_LVM    = --without-storage-lvm
   WITH_STORAGE_ISCSI  = --without-storage-iscsi
@@ -60,6 +62,8 @@
   WITH_NUMA           = --without-numactl
   WITH_NETCF          = --without-netcf
   WITH_AUDIT          = --without-audit
+  WITH_INIT_SCRIPT    = --with-init-script=none
+  WITH_SYSTEMD        = --without-systemd-daemon
 endif
 
 DEB_BUILDDIR := $(CURDIR)/debian/build
@@ -93,6 +97,7 @@
 	$(WITH_XEN)		 \
 	$(WITH_LXC)		 \
 	$(WITH_AUDIT)		 \
+	$(WITH_INIT_SCRIPT)	 \
 	--with-apparmor		 \
 	--with-vbox \
     --without-firewalld \
@@ -102,7 +107,6 @@
 DEB_COMPRESS_EXCLUDE = .o event-test hellolibvirt info1 suspend
 DEB_PYTHON_SETUP_CMD = /dev/null
 DEB_DH_MAKESHLIBS_ARGS_libvirt0 += -V 'libvirt0 (>= 0.5.0)'
-DEB_DH_INSTALLINIT_ARGS = --upstart-only --restart-after-upgrade
 
 LOGROTATE = $(basename $(basename $(notdir $(wildcard daemon/libvirtd*.logrotate.in))))
 EXAMPLES_DIR = $(CURDIR)/debian/libvirt-doc/usr/share/doc/libvirt-doc/examples/
@@ -118,10 +122,18 @@
 	DEB_DH_GENCONTROL_ARGS_libvirt-bin = -- -V'dist:Conflicts=apparmor (<< 2.8.96~2652-0ubuntu1)'
 endif
 
+install/libvirt-bin::
+	# helper to stop vms at shutdown
+	mkdir -p debian/libvirt-bin/usr/lib/libvirt
+	cp debian/libvirt-stop-guests debian/libvirt-bin/usr/lib/libvirt
+	chmod ugo+x debian/libvirt-bin/usr/lib/libvirt/libvirt-stop-guests
+	dh_systemd_enable
+	dh_installinit -p libvirt-bin --name=libvirt-bin --restart-after-upgrade -- defaults 28 72
+	dh_installinit -p libvirt-bin --name=libvirt-guests --no-restart-on-upgrade -- defaults 29 71
+	dh_systemd_start -p libvirt-bin --restart-after-upgrade libvirt-bin.service
+	dh_systemd_start -p libvirt-bin --no-restart-on-upgrade libvirt-guests.service
+
 binary-install/libvirt-bin::
-	#cp $(CURDIR)/tools/libvirt-guests.init.sh $(CURDIR)/debian/libvirt-bin.libvirt-guests.init
-	#cp $(CURDIR)/tools/libvirt-guests.sysconf $(CURDIR)/debian/libvirt-bin.libvirt-guests.default
-	#dh_installinit --name=libvirt-guests --no-restart-on-upgrade -- defaults 29 71
 	rm debian/libvirt-bin/usr/lib/libvirt/connection-driver/*.la
 	# Don't ship api files in the daemon package
 	rm -r debian/libvirt-bin/usr/share/libvirt/api/
Download as text