[Pkg-xen-devel] [PATCH 08/13] xen init script: rewrite xenstored start logic

Hans van Kranenburg hans at knorrie.org
Sun Feb 10 23:42:06 GMT 2019


By adding oxenstored, this just got a whole lot more complex.

In the Xen 4.11 packages and newer, we're shipping oxenstored. This init
script can still be used while the current running Xen version is e.g.
4.8.

We give the user the option to define which xenstored they want to run
(in /etc/default/xen). The C one or the ocaml one.

Whenever any xenstored is running, we don't touch it, because all state
about domains is only kept in memory in the process.

Combining all of the possiblities and limitations...

* If there's anything known running, just let it be.
* If the user has a specific (o)xenstored set as preference, try
starting that, but horribly explode if that's not possible.
* Otherwise, prefer oxenstored if available, and otherwise start normal
C xenstored.

Hint: debugging this on a dom0 can be done by adding set -x and running
it with SYSTEMCTL_SKIP_REDIRECT=YOLO /etc/init.d/xen <action> so that
systemd does not hijack it and hide all output.
---
 debian/xen-utils-common.xen.init | 55 ++++++++++++++++++++++++++++----
 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/debian/xen-utils-common.xen.init b/debian/xen-utils-common.xen.init
index a352823040..f736b9a17c 100644
--- a/debian/xen-utils-common.xen.init
+++ b/debian/xen-utils-common.xen.init
@@ -61,7 +61,15 @@ fi
 
 XENCONSOLED="$ROOT"/bin/xenconsoled
 XENCONSOLED_PIDFILE="/var/run/xenconsoled.pid"
-XENSTORED="$ROOT"/bin/xenstored
+# In /etc/default/xen, the user can set XENSTORED, which has to be either
+# 'xenstored' or 'oxenstored'. In here, we add the version specific path.
+if [ -n "$XENSTORED" ]; then
+	USER_XENSTORED="$ROOT"/bin/$XENSTORED
+else
+	USER_XENSTORED=""
+fi
+CXENSTORED="$ROOT"/bin/xenstored
+OXENSTORED="$ROOT"/bin/oxenstored
 XENSTORED_PIDFILE="/var/run/xenstore.pid"
 QEMU=/usr/bin/qemu-system-i386
 QEMU_PIDFILE="/var/run/qemu-dom0.pid"
@@ -204,15 +212,50 @@ qemu_stop_real()
 
 xenstored_start()
 {
+	# First, we check if any of xenstored or oxenstored is already running. If
+	# so, we abort and leave it alone, even if the user has switched the value
+	# in /etc/default/xen from one to another.
+	for try_xenstored in "$OXENSTORED" "$CXENSTORED"; do
+		if [ -x $try_xenstored ]; then
+			start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" \
+				--exec "$try_xenstored" --test > /dev/null
+			if [ $? -eq 1 ]; then
+				return 1
+			fi
+		fi
+	done
+	# If none of them are running, then try starting one. If the user made an
+	# explicit choice, then run that. Else try the different xenstored
+	# implementations we know about in order of preference.
 	log_progress_msg "xenstored"
-	start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" --exec "$XENSTORED" --test > /dev/null \
-		|| return 1
 	[ -d "$XENSTORED_DIR" ] || mkdir -p "$XENSTORED_DIR"
 	[ -x /sbin/restorecon ] && /sbin/restorecon "$XENSTORED_DIR"
 	export XENSTORED_ROOTDIR="$XENSTORED_DIR"
-	start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" --exec "$XENSTORED" -- \
-		$XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE" \
-		|| return 2
+	if [ -n "$USER_XENSTORED" ]; then
+		if [ ! -x "$USER_XENSTORED" ]; then
+			log_failure_msg "Failed to start $USER_XENSTORED: no such executable."
+			return 2
+		else
+			start-stop-daemon --start --quiet \
+				--pidfile "$XENSTORED_PIDFILE" --exec "$USER_XENSTORED" -- \
+				$XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE"
+			if [ $? -ne 0 ]; then
+				return 2
+			fi
+		fi
+	else
+		for try_xenstored in "$OXENSTORED" "$CXENSTORED"; do
+			if [ -x $try_xenstored ]; then
+				start-stop-daemon --start --quiet \
+					--pidfile "$XENSTORED_PIDFILE" --exec "$try_xenstored" -- \
+					$XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE"
+				if [ $? -ne 0 ]; then
+					return 2
+				fi
+				break
+			fi
+		done
+	fi
 
 	# Wait for xenstored to actually come up, timing out after 30 seconds
 	local time=0
-- 
2.20.1




More information about the Pkg-xen-devel mailing list