]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
xen init script: rewrite xenstored start logic
authorHans van Kranenburg <hans@knorrie.org>
Sat, 9 Feb 2019 23:37:55 +0000 (00:37 +0100)
committerIan Jackson <ian.jackson@citrix.com>
Fri, 22 Feb 2019 14:00:16 +0000 (14:00 +0000)
We're adding oxenstored, and we want use it by default in Xen 4.11.

When doing a Debian upgrade from Stretch to Buster, the xen-utils-common
package will be upgraded to the new version, but it still needs to
support running the Xen 4.8 hypervisor and utils, because the user might
not have rebooted yet, or might boot into the 4.8 hypervisor again
because there were troubles running 4.11.

So, this means that oxenstored might or might not be available, and we
have to deal with that.

See comments in the code for more explanation about the new program
flow.

Also...
* Allow the user to explicitly configure a xenstored binary in
/etc/default/xen.
* Use if statements rather than constructs using || and && to make the
program flow a bit easier to understand.
* Remove the confuscating madness of having 1 as a success return code.
* Don't print the xenstored progress message if we're not touching it.

Signed-off-by: Hans van Kranenburg <hans@knorrie.org>
Acked-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
debian/xen-utils-common.xen.init

index a352823040c52d43cab276eadc272ec11c092db9..7fd18e8030866296c730b53733bcfd5c262e5010 100644 (file)
@@ -61,7 +61,8 @@ fi
 
 XENCONSOLED="$ROOT"/bin/xenconsoled
 XENCONSOLED_PIDFILE="/var/run/xenconsoled.pid"
-XENSTORED="$ROOT"/bin/xenstored
+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 +205,44 @@ 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.
+       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
+                       # s-s-d code 1 here means: "We found a matching live process!"
+                       if [ $? -eq 1 ]; then
+                               return 0
+                       fi
+               fi
+       done
        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 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.
+       case "$XENSTORED" in
+       ?*) try_xenstoreds='XENSTORED' ;;
+       '') try_xenstoreds='OXENSTORED CXENSTORED' ;;
+       esac
+       for try_xenstored_var in $try_xenstoreds; do
+               eval "try_xenstored=\$$try_xenstored_var"
+               if [ -x $try_xenstored ]; then
+                       if start-stop-daemon --start --quiet \
+                               --pidfile "$XENSTORED_PIDFILE" --exec "$try_xenstored" -- \
+                               $XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE"; then
+                                       started_xenstored=$try_xenstored
+                                       break
+                       fi
+               fi
+       done
+       if [ -z "$started_xenstored" ]; then
+               log_failure_msg "No suitable xenstored binary found to start."
+               return 1
+       fi
 
        # Wait for xenstored to actually come up, timing out after 30 seconds
        local time=0
@@ -256,7 +286,7 @@ case "$1" in
        env_setup
        xenstored_start
        case "$?" in
-               0|1) ;;
+               0) ;;
                *) log_end_msg 1; exit ;;
        esac
        xenconsoled_start