autoconf: xen: enable explicit preference option for xenstored preference
authorLuis R. Rodriguez <mcgrof@suse.com>
Wed, 30 Jul 2014 16:40:02 +0000 (09:40 -0700)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 4 Aug 2014 13:58:24 +0000 (14:58 +0100)
As it stands oxenstored will be used by default if ocaml tools are
found, the init system will also try to use oxenstored first if its
found otherwise the cxenstored will be used. Lets simplify the init
script and let users be explicit about the preference through configure.

This adds support to let you be explicit about the xenstored preference,
you can only use one of these two options:

./configure --with-xenstored=xenstored
./configure --with-xenstored=oxenstored

We continue with the old behaviour and default oxenstored will be used
but only if you have ocaml dependencies. Since the xenstored preference
is explicit now and since we require configure substitutions for it we
make use of the AX_XEN_EXPAND_CONFIG() helpers as otherwise substitution
for SBINDIR is not propagated from the top level configuration.

All this allows us to simplify the init script to use the configured
xenstore from the start. We update the sysconfig/default xencommons file
with the paths for the different options though, this can be used by
users to override the default xenstored, this follows the old behaviour
but we now just explicitly provide the full configured paths for users.

As before, changing the xenstore requires a reboot.

In order to help with documentation we update the README with some
details on configure usage refer to the wiki [0] [1] [2] for more elaborate
details.

Since we are now parsing an entry within Paths.mk.in on tools we let
the move the parsing of the file to be the tool's configure.

[0] http://wiki.xen.org/wiki/Xenstored
[1] http://wiki.xen.org/wiki/XenStore
[2] http://wiki.xen.org/wiki/XenStoreReference

Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
[ ijc -- ran autogen.sh ]

README
m4/xenstored.m4 [new file with mode: 0644]
tools/configure
tools/configure.ac
tools/hotplug/Linux/init.d/sysconfig.xencommons [deleted file]
tools/hotplug/Linux/init.d/sysconfig.xencommons.in [new file with mode: 0644]
tools/hotplug/Linux/init.d/xencommons.in [deleted file]
tools/hotplug/Linux/init.d/xencommons.in.in [new file with mode: 0644]

diff --git a/README b/README
index 0c8c7aacb900d8bcaf3134d85838e8ad959bef73..7c27fbbf404feaf43593169e3ea56481cc3da016 100644 (file)
--- a/README
+++ b/README
@@ -129,6 +129,38 @@ performed with root privileges.]
    versions of those scripts, so that you can copy the dist directory
    to another machine and install from that distribution.
 
+xenstore: xenstored and oxenstored
+====================================
+
+Xen uses a configuration database called xenstore [0] to maintain configuration
+and status information shared between domains. A daemon is implemented as part
+of xenstore to act as an interface for access to the database for dom0 and
+guests. Two xenstored daemons are supported, one written in C which we refer
+to as the xenstored (sometimes referred to as cxenstored), and another written
+in Ocaml called oxenstored. Details for xenstore and the different
+implementations can be found on the wiki's xenstore reference guide [1] and
+the xenstored [2] page. You can choose which xenstore you want to enable as
+default on a system through configure:
+
+       ./configure --with-xenstored=xenstored
+       ./configure --with-xenstored=oxenstored
+
+By default oxenstored will be used if the ocaml development tools are found.
+If you enable oxenstored the xenstored will still be built and installed,
+the xenstored used can be changed through the configuration file:
+
+/etc/sysconfig/xencommons
+or
+/etc/default/xencommons
+
+You can change the preferred xenstored you want to use in the configuration
+but since we cannot stop the daemon a reboot will be required to make the
+change take effect.
+
+[0] http://wiki.xen.org/wiki/XenStore
+[1] http://wiki.xen.org/wiki/XenStoreReference
+[2] http://wiki.xen.org/wiki/Xenstored
+
 Python Runtime Libraries
 ========================
 
diff --git a/m4/xenstored.m4 b/m4/xenstored.m4
new file mode 100644 (file)
index 0000000..30b44c9
--- /dev/null
@@ -0,0 +1,56 @@
+AC_DEFUN([AX_XEN_OCAML_XENSTORE_CHECK], [
+       AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
+               AC_MSG_ERROR([Missing ocaml dependencies for oxenstored, try installing ocaml ocaml-compiler-libs ocaml-runtime ocaml-findlib])
+       ])
+])
+
+AC_DEFUN([AX_XEN_OCAML_XENSTORE_DEFAULTS], [
+       xenstore="oxenstored"
+       xenstored=$SBINDIR/oxenstored
+       AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
+               xenstore="xenstored"
+               xenstored=$SBINDIR/xenstored
+       ])
+])
+
+AC_DEFUN([AX_XENSTORE_OPTIONS], [
+AS_IF([test "x$XENSTORE" = "x"], [
+AC_ARG_WITH([xenstored],
+       AS_HELP_STRING([--with-xenstored@<:@=oxenstored|xenstored@:>@],
+               [This lets you choose which xenstore daemon you want, you have
+               two options: the original xenstored written in C (xenstored)
+               or the newer and robust one written in Ocaml (oxenstored).
+               The oxenstored daemon is the default but will but can only
+               be used if you have ocaml library / build dependencies solved,
+               if you have not specified a preference and do not have ocaml
+               dependencies resolved we'll enable the C xenstored for you. If
+               you ask for oxenstored we'll complain until you resolve those
+               dependencies]),
+       [
+               AS_IF([test "x$withval" = "xxenstored"], [
+                       xenstore=$withval
+                       xenstored=$SBINDIR/xenstored
+               ])
+               AS_IF([test "x$withval" = "xoxenstored"], [
+                       xenstore=$withval
+                       xenstored=$SBINDIR/oxenstored
+                       AX_XEN_OCAML_XENSTORE_CHECK()
+               ])
+               AS_IF([test "x$withval" != "xoxenstored" && test "x$withval" != "xxenstored"], [
+                       AC_MSG_ERROR([Unsupported xenstored specified, supported types: oxenstored xenstored])
+               ])
+       ],
+       [
+               AX_XEN_OCAML_XENSTORE_DEFAULTS()
+       ])
+])
+])
+
+AC_DEFUN([AX_XENSTORE_SET], [
+       XENSTORE=$xenstore
+
+       AS_IF([test "x$XENSTORED" = "x"], [
+               XENSTORED=$xenstored
+       ])
+       AC_SUBST(XENSTORED)
+])
index a4aa8f18559ebf5e8f45f6ce1e4fe514db73358e..08d6a055e5c8bbb562f5c709fdcd8a709ba24bf7 100755 (executable)
@@ -649,6 +649,7 @@ pyconfig
 PYTHONPATH
 CHECKPOLICY
 AWK
+XENSTORED
 OCAMLFIND
 OCAMLBUILD
 OCAMLDOC
@@ -698,6 +699,23 @@ xsmpolicy
 ocamltools
 monitors
 githttp
+XEN_PAGING_DIR
+XEN_LOCK_DIR
+XEN_SCRIPT_DIR
+XEN_CONFIG_DIR
+CONFIG_DIR
+XENFIRMWAREDIR
+PRIVATE_BINDIR
+PKG_XEN_PREFIX
+PRIVATE_PREFIX
+SHAREDIR
+XEN_LIB_STORED
+XEN_LOG_DIR
+XEN_RUN_DIR
+LIBDIR
+LIBEXEC
+SBINDIR
+BINDIR
 FILE_OFFSET_BITS
 OBJEXT
 EXEEXT
@@ -772,6 +790,7 @@ with_system_qemu
 with_system_seabios
 with_system_ovmf
 with_extra_qemuu_configure_args
+with_xenstored
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1451,6 +1470,17 @@ Optional Packages:
   --with-extra-qemuu-configure-args[="--ARG1 ..."]
                           List of additional configure options for upstream
                           qemu
+  --with-xenstored[=oxenstored|xenstored]
+                          This lets you choose which xenstore daemon you want,
+                          you have two options: the original xenstored written
+                          in C (xenstored) or the newer and robust one written
+                          in Ocaml (oxenstored). The oxenstored daemon is the
+                          default but will but can only be used if you have
+                          ocaml library / build dependencies solved, if you
+                          have not specified a preference and do not have
+                          ocaml dependencies resolved we'll enable the C
+                          xenstored for you. If you ask for oxenstored we'll
+                          complain until you resolve those dependencies
 
 Some influential environment variables:
   CC          C compiler command
@@ -2205,7 +2235,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
-ac_config_files="$ac_config_files ../config/Tools.mk"
+ac_config_files="$ac_config_files ../config/Tools.mk hotplug/Linux/init.d/xencommons.in hotplug/Linux/init.d/sysconfig.xencommons"
 
 ac_config_headers="$ac_config_headers config.h"
 
@@ -3587,6 +3617,75 @@ esac
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
+test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
+
+BINDIR=$prefix/bin
+
+
+SBINDIR=$prefix/sbin
+
+
+LIBEXEC=$prefix/lib/xen/bin
+
+
+LIBDIR=`eval echo $libdir`
+
+
+XEN_RUN_DIR=/var/run/xen
+
+
+XEN_LOG_DIR=/var/log/xen
+
+
+XEN_LIB_STORED=/var/lib/xenstored
+
+
+SHAREDIR=$prefix/share
+
+
+PRIVATE_PREFIX=$LIBDIR/xen
+
+
+PKG_XEN_PREFIX=$LIBDIR/xen
+
+
+PRIVATE_BINDIR=$PRIVATE_PREFIX/bin
+
+
+XENFIRMWAREDIR=$prefix/lib/xen/boot
+
+
+CONFIG_DIR=/etc
+
+
+XEN_CONFIG_DIR=$CONFIG_DIR/xen
+
+
+XEN_SCRIPT_DIR=$XEN_CONFIG_DIR/scripts
+
+
+XEN_LOCK_DIR=/var/lock
+
+
+XEN_RUN_DIR=/var/run/xen
+
+
+XEN_PAGING_DIR=/var/lib/xen/xenpaging
+
+
+
 # Enable/disable options
 
 # Check whether --enable-githttp was given.
@@ -4757,51 +4856,8 @@ if test x"${PERL}" = x"no"
 then
     as_fn_error $? "Unable to find perl, please install perl" "$LINENO" 5
 fi
-for ac_prog in gawk mawk nawk awk
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_AWK+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$AWK"; then
-  ac_cv_prog_AWK="$AWK" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_AWK="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-AWK=$ac_cv_prog_AWK
-if test -n "$AWK"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
-$as_echo "$AWK" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-  test -n "$AWK" && break
-done
-
-if test "x$ocamltools" = "xy"; then :
 
-      # checking for ocamlc
+  # checking for ocamlc
   if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}ocamlc", so it can be a program name with args.
 set dummy ${ac_tool_prefix}ocamlc; ac_word=$2
@@ -5895,6 +5951,112 @@ fi
 
 
 
+
+
+if test "x$XENSTORE" = "x"; then :
+
+
+# Check whether --with-xenstored was given.
+if test "${with_xenstored+set}" = set; then :
+  withval=$with_xenstored;
+               if test "x$withval" = "xxenstored"; then :
+
+                       xenstore=$withval
+                       xenstored=$SBINDIR/xenstored
+
+fi
+               if test "x$withval" = "xoxenstored"; then :
+
+                       xenstore=$withval
+                       xenstored=$SBINDIR/oxenstored
+
+       if test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"; then :
+
+               as_fn_error $? "Missing ocaml dependencies for oxenstored, try installing ocaml ocaml-compiler-libs ocaml-runtime ocaml-findlib" "$LINENO" 5
+
+fi
+
+
+fi
+               if test "x$withval" != "xoxenstored" && test "x$withval" != "xxenstored"; then :
+
+                       as_fn_error $? "Unsupported xenstored specified, supported types: oxenstored xenstored" "$LINENO" 5
+
+fi
+
+else
+
+
+       xenstore="oxenstored"
+       xenstored=$SBINDIR/oxenstored
+       if test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"; then :
+
+               xenstore="xenstored"
+               xenstored=$SBINDIR/xenstored
+
+fi
+
+
+fi
+
+
+fi
+
+
+       XENSTORE=$xenstore
+
+       if test "x$XENSTORED" = "x"; then :
+
+               XENSTORED=$xenstored
+
+fi
+
+
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AWK+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AWK="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
+$as_echo "$AWK" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AWK" && break
+done
+
+if test "x$ocamltools" = "xy"; then :
+
     if test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"; then :
 
         if test "x$enable_ocamltools" = "xyes"; then :
@@ -8864,6 +9026,8 @@ for ac_config_target in $ac_config_targets
 do
   case $ac_config_target in
     "../config/Tools.mk") CONFIG_FILES="$CONFIG_FILES ../config/Tools.mk" ;;
+    "hotplug/Linux/init.d/xencommons.in") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xencommons.in" ;;
+    "hotplug/Linux/init.d/sysconfig.xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/sysconfig.xencommons" ;;
     "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
index 629d6a044aa8cf6ea44c8266eb78c0a74f81cd84..e74fe4b1353f29332c3984ea4fe58245dcb72dd9 100644 (file)
@@ -5,7 +5,11 @@ AC_PREREQ([2.67])
 AC_INIT([Xen Hypervisor Tools], m4_esyscmd([../version.sh ../xen/Makefile]),
     [xen-devel@lists.xen.org], [xen], [http://www.xen.org/])
 AC_CONFIG_SRCDIR([libxl/libxl.c])
-AC_CONFIG_FILES([../config/Tools.mk])
+AC_CONFIG_FILES([
+../config/Tools.mk
+hotplug/Linux/init.d/xencommons.in
+hotplug/Linux/init.d/sysconfig.xencommons
+])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_AUX_DIR([../])
 
@@ -53,6 +57,10 @@ m4_include([../m4/ptyfuncs.m4])
 m4_include([../m4/extfs.m4])
 m4_include([../m4/fetcher.m4])
 m4_include([../m4/ax_compare_version.m4])
+m4_include([../m4/paths.m4])
+m4_include([../m4/xenstored.m4])
+
+AX_XEN_EXPAND_CONFIG()
 
 # Enable/disable options
 AX_ARG_DEFAULT_DISABLE([githttp], [Download GIT repositories via HTTP])
@@ -203,9 +211,14 @@ AC_PROG_INSTALL
 AC_PATH_PROG([BISON], [bison])
 AC_PATH_PROG([FLEX], [flex])
 AX_PATH_PROG_OR_FAIL([PERL], [perl])
+
+AC_PROG_OCAML
+AC_PROG_FINDLIB
+
+AX_XENSTORE_OPTIONS
+AX_XENSTORE_SET
+
 AS_IF([test "x$ocamltools" = "xy"], [
-    AC_PROG_OCAML
-    AC_PROG_FINDLIB
     AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
         AS_IF([test "x$enable_ocamltools" = "xyes"], [
             AC_MSG_ERROR([Ocaml tools enabled, but unable to find Ocaml])])
diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons b/tools/hotplug/Linux/init.d/sysconfig.xencommons
deleted file mode 100644 (file)
index 25f7f00..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-## Path: System/Virtualization
-## Type: string
-## Default: "none"
-#
-# Log xenconsoled messages (cf xl dmesg)
-#XENCONSOLED_TRACE=[none|guest|hv|all]
-
-## Type: string
-## Default: xenstored
-#
-# Select xenstored implementation
-#XENSTORED=[oxenstored|xenstored]
-
-## Type: string
-## Default: Not defined, tracing off
-#
-# Log xenstored messages
-#XENSTORED_TRACE=[yes|on|1]
-
-## Type: string
-## Default: "/var/lib/xenstored"
-#
-# Running xenstored on XENSTORED_ROOTDIR
-#XENSTORED_ROOTDIR=/var/lib/xenstored
-
-## Type: string
-## Default: Not defined, xenbackendd debug mode off
-#
-# Running xenbackendd in debug mode
-#XENBACKENDD_DEBUG=[yes|on|1]
-
-# qemu path
-#QEMU_XEN=/usr/lib/xen/bin/qemu-system-i386
diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons.in b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
new file mode 100644 (file)
index 0000000..d423ff8
--- /dev/null
@@ -0,0 +1,42 @@
+## Path: System/Virtualization
+## Type: string
+## Default: "none"
+#
+# Log xenconsoled messages (cf xl dmesg)
+#XENCONSOLED_TRACE=[none|guest|hv|all]
+
+## Type: string
+## Default: xenstored
+#
+# Select xenstore implementation, this can be either
+# of these below. If using systemd it's preferred that you
+# just edit the xenstored.service unit file and change
+# the XENSTORED variable there.
+#
+# This can be either of:
+#  * @SBINDIR@/oxenstored
+#  * @SBINDIR@/xenstored
+#
+# Changing this requires a reboot to take effect.
+#XENSTORED=@XENSTORED@
+
+## Type: string
+## Default: Not defined, tracing off
+#
+# Log xenstored messages
+#XENSTORED_TRACE=[yes|on|1]
+
+## Type: string
+## Default: "/var/lib/xenstored"
+#
+# Running xenstored on XENSTORED_ROOTDIR
+#XENSTORED_ROOTDIR=/var/lib/xenstored
+
+## Type: string
+## Default: Not defined, xenbackendd debug mode off
+#
+# Running xenbackendd in debug mode
+#XENBACKENDD_DEBUG=[yes|on|1]
+
+# qemu path
+#QEMU_XEN=/usr/lib/xen/bin/qemu-system-i386
diff --git a/tools/hotplug/Linux/init.d/xencommons.in b/tools/hotplug/Linux/init.d/xencommons.in
deleted file mode 100644 (file)
index 3939bcc..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/bin/bash
-#
-# xencommons    Script to start and stop xenstored and xenconsoled
-#
-# Author:       Ian Jackson <ian.jackson@eu.citrix.com>
-#
-# chkconfig: 2345 70 10
-# description: Starts and stops xenstored and xenconsoled
-### BEGIN INIT INFO
-# Provides:          xenstored xenconsoled
-# Required-Start:    $syslog $remote_fs
-# Should-Start:
-# Required-Stop:     $syslog $remote_fs
-# Should-Stop:
-# Default-Start:     2 3 5
-# Default-Stop:      0 1 6
-# Short-Description: Start/stop xenstored and xenconsoled
-# Description:       Starts and stops the daemons neeeded for xl/xend
-### END INIT INFO
-
-. /etc/xen/scripts/hotplugpath.sh
-
-if [ -d /etc/sysconfig ]; then
-       xencommons_config=/etc/sysconfig
-else
-       xencommons_config=/etc/default
-fi
-
-test -f $xencommons_config/xencommons && . $xencommons_config/xencommons
-
-XENCONSOLED_PIDFILE=/var/run/xenconsoled.pid
-QEMU_PIDFILE=/var/run/qemu-dom0.pid
-shopt -s extglob
-
-# not running in Xen dom0 or domU
-if ! test -d /proc/xen ; then
-       exit 0
-fi
-
-# mount xenfs in dom0 or domU with a pv_ops kernel
-if test "x$1" = xstart && \
-   ! test -f /proc/xen/capabilities && \
-   ! grep '^xenfs ' /proc/mounts >/dev/null;
-then
-       mount -t xenfs xenfs /proc/xen
-fi
-
-# run this script only in dom0:
-# no capabilities file in xenlinux domU kernel
-# empty capabilities file in pv_ops domU kernel
-if test -f /proc/xen/capabilities && \
-   ! grep -q "control_d" /proc/xen/capabilities ; then
-       exit 0
-fi
-
-do_start () {
-        local time=0
-       local timeout=30
-
-       @LOAD_MODULES@
-       mkdir -p /var/run/xen
-
-       if ! `${BINDIR}/xenstore-read -s / >/dev/null 2>&1`
-       then
-               test -z "$XENSTORED_ROOTDIR" && XENSTORED_ROOTDIR="/var/lib/xenstored"
-               rm -f "$XENSTORED_ROOTDIR"/tdb* &>/dev/null
-               test -z "$XENSTORED_TRACE" || XENSTORED_ARGS=" -T /var/log/xen/xenstored-trace.log"
-
-               if [ -n "$XENSTORED" ] ; then
-                   echo -n Starting $XENSTORED...
-                   $XENSTORED --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
-               elif [ -x ${SBINDIR}/oxenstored ] ; then
-                   echo -n Starting oxenstored...
-                   ${SBINDIR}/oxenstored --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
-               elif [ -x ${SBINDIR}/xenstored ] ; then
-                   echo -n Starting C xenstored...
-                   ${SBINDIR}/xenstored --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
-               else
-                   echo "No xenstored found"
-                   exit 1
-               fi
-
-               # Wait for xenstored to actually come up, timing out after 30 seconds
-                while [ $time -lt $timeout ] && ! `${BINDIR}/xenstore-read -s / >/dev/null 2>&1` ; do
-                    echo -n .
-                   time=$(($time+1))
-                    sleep 1
-                done
-               echo
-
-               # Exit if we timed out
-               if ! [ $time -lt $timeout ] ; then
-                   echo Could not start xenstored
-                   exit 1
-               fi
-
-               echo Setting domain 0 name and domid...
-               ${BINDIR}/xenstore-write "/local/domain/0/name" "Domain-0"
-               ${BINDIR}/xenstore-write "/local/domain/0/domid" 0
-       fi
-
-       echo Starting xenconsoled...
-       test -z "$XENCONSOLED_TRACE" || XENCONSOLED_ARGS=" --log=$XENCONSOLED_TRACE"
-       ${SBINDIR}/xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_ARGS
-       echo Starting QEMU as disk backend for dom0
-       test -z "$QEMU_XEN" && QEMU_XEN="${LIBEXEC}/qemu-system-i386"
-       $QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize \
-               -monitor /dev/null -serial /dev/null -parallel /dev/null \
-               -pidfile $QEMU_PIDFILE
-}
-do_stop () {
-        echo Stopping xenconsoled
-       if read 2>/dev/null <$XENCONSOLED_PIDFILE pid; then
-               kill $pid
-               while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
-               rm -f $XENCONSOLED_PIDFILE
-       fi
-
-       echo Stopping QEMU
-       if read 2>/dev/null <$QEMU_PIDFILE pid; then
-               kill $pid
-               while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
-               rm -f $QEMU_PIDFILE
-       fi
-
-       echo WARNING: Not stopping xenstored, as it cannot be restarted.
-}
-
-case "$1" in
-  start)
-       do_start
-       ;;
-  status)
-        ${BINDIR}/xenstore-read -s /
-       ;;
-  stop)
-       do_stop
-       ;;
-  reload)
-       echo >&2 'Reload not available; use force-reload'; exit 1
-       ;;
-  force-reload|restart)
-        do_stop
-       do_start
-       ;;
-  *)
-       # do not advertise unreasonable commands that there is no reason
-       # to use with this device
-       echo $"Usage: $0 {start|stop|status|restart|force-reload}"
-       exit 1
-esac
-
-exit $?
diff --git a/tools/hotplug/Linux/init.d/xencommons.in.in b/tools/hotplug/Linux/init.d/xencommons.in.in
new file mode 100644 (file)
index 0000000..b311bb8
--- /dev/null
@@ -0,0 +1,149 @@
+#!/bin/bash
+#
+# xencommons    Script to start and stop xenstored and xenconsoled
+#
+# Author:       Ian Jackson <ian.jackson@eu.citrix.com>
+#
+# chkconfig: 2345 70 10
+# description: Starts and stops xenstored and xenconsoled
+### BEGIN INIT INFO
+# Provides:          xenstored xenconsoled
+# Required-Start:    $syslog $remote_fs
+# Should-Start:
+# Required-Stop:     $syslog $remote_fs
+# Should-Stop:
+# Default-Start:     2 3 5
+# Default-Stop:      0 1 6
+# Short-Description: Start/stop xenstored and xenconsoled
+# Description:       Starts and stops the daemons neeeded for xl/xend
+### END INIT INFO
+
+XENSTORED=@XENSTORED@
+
+. /etc/xen/scripts/hotplugpath.sh
+
+if [ -d /etc/sysconfig ]; then
+       xencommons_config=/etc/sysconfig
+else
+       xencommons_config=/etc/default
+fi
+
+test -f $xencommons_config/xencommons && . $xencommons_config/xencommons
+
+XENCONSOLED_PIDFILE=/var/run/xenconsoled.pid
+QEMU_PIDFILE=/var/run/qemu-dom0.pid
+shopt -s extglob
+
+# not running in Xen dom0 or domU
+if ! test -d /proc/xen ; then
+       exit 0
+fi
+
+# mount xenfs in dom0 or domU with a pv_ops kernel
+if test "x$1" = xstart && \
+   ! test -f /proc/xen/capabilities && \
+   ! grep '^xenfs ' /proc/mounts >/dev/null;
+then
+       mount -t xenfs xenfs /proc/xen
+fi
+
+# run this script only in dom0:
+# no capabilities file in xenlinux domU kernel
+# empty capabilities file in pv_ops domU kernel
+if test -f /proc/xen/capabilities && \
+   ! grep -q "control_d" /proc/xen/capabilities ; then
+       exit 0
+fi
+
+do_start () {
+        local time=0
+       local timeout=30
+
+       @LOAD_MODULES@
+       mkdir -p /var/run/xen
+
+       if ! `${BINDIR}/xenstore-read -s / >/dev/null 2>&1`
+       then
+               test -z "$XENSTORED_ROOTDIR" && XENSTORED_ROOTDIR="/var/lib/xenstored"
+               rm -f "$XENSTORED_ROOTDIR"/tdb* &>/dev/null
+               test -z "$XENSTORED_TRACE" || XENSTORED_ARGS=" -T /var/log/xen/xenstored-trace.log"
+
+               if [ -n "$XENSTORED" ] ; then
+                   echo -n Starting $XENSTORED...
+                   $XENSTORED --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
+               else
+                   echo "No xenstored found"
+                   exit 1
+               fi
+
+               # Wait for xenstored to actually come up, timing out after 30 seconds
+                while [ $time -lt $timeout ] && ! `${BINDIR}/xenstore-read -s / >/dev/null 2>&1` ; do
+                    echo -n .
+                   time=$(($time+1))
+                    sleep 1
+                done
+               echo
+
+               # Exit if we timed out
+               if ! [ $time -lt $timeout ] ; then
+                   echo Could not start xenstored
+                   exit 1
+               fi
+
+               echo Setting domain 0 name and domid...
+               ${BINDIR}/xenstore-write "/local/domain/0/name" "Domain-0"
+               ${BINDIR}/xenstore-write "/local/domain/0/domid" 0
+       fi
+
+       echo Starting xenconsoled...
+       test -z "$XENCONSOLED_TRACE" || XENCONSOLED_ARGS=" --log=$XENCONSOLED_TRACE"
+       ${SBINDIR}/xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_ARGS
+       echo Starting QEMU as disk backend for dom0
+       test -z "$QEMU_XEN" && QEMU_XEN="${LIBEXEC}/qemu-system-i386"
+       $QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize \
+               -monitor /dev/null -serial /dev/null -parallel /dev/null \
+               -pidfile $QEMU_PIDFILE
+}
+do_stop () {
+        echo Stopping xenconsoled
+       if read 2>/dev/null <$XENCONSOLED_PIDFILE pid; then
+               kill $pid
+               while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
+               rm -f $XENCONSOLED_PIDFILE
+       fi
+
+       echo Stopping QEMU
+       if read 2>/dev/null <$QEMU_PIDFILE pid; then
+               kill $pid
+               while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
+               rm -f $QEMU_PIDFILE
+       fi
+
+       echo WARNING: Not stopping xenstored, as it cannot be restarted.
+}
+
+case "$1" in
+  start)
+       do_start
+       ;;
+  status)
+        ${BINDIR}/xenstore-read -s /
+       ;;
+  stop)
+       do_stop
+       ;;
+  reload)
+       echo >&2 'Reload not available; use force-reload'; exit 1
+       ;;
+  force-reload|restart)
+        do_stop
+       do_start
+       ;;
+  *)
+       # do not advertise unreasonable commands that there is no reason
+       # to use with this device
+       echo $"Usage: $0 {start|stop|status|restart|force-reload}"
+       exit 1
+esac
+
+exit $?