WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 22/24] [xen-unstable.hg] move xenstored from xend out

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 22/24] [xen-unstable.hg] move xenstored from xend out into its own rc script and add xenstore sysconfig file
From: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
Date: Mon, 23 Mar 2009 15:21:34 +0000
Delivery-date: Mon, 23 Mar 2009 08:40:54 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.19 (X11/20090105)


This patch starts xenstore in its own rc script instead of in xend.

This creates a logical place where the user can select between a xenstore
daemon running in dom0 and a xenstore stub domain.

It also makes more sense to have xenstore started seperately.  Prior to this
change xend started xenstored when it was first run, but would not kill
it when it died.  If xend was run again it would try to start xenstored again
but this would fail silently as xenstored was already running.  This was a
bit confusing.

In order to prevent problems arising from the new rc script not being 
chkconfig'd
"service xend start" now checks "service xenstored status" and starts xenstored
if necessary.

Signed-off-by: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>

diff -r f115d0051672 tools/hotplug/Linux/Makefile
--- a/tools/hotplug/Linux/Makefile      Fri Mar 20 15:45:45 2009 +0000
+++ b/tools/hotplug/Linux/Makefile      Mon Mar 23 11:16:18 2009 +0000
@@ -2,9 +2,11 @@
 include $(XEN_ROOT)/tools/Rules.mk
 
 # Init scripts.
+XENSTORED_INITD = init.d/xenstored
 XEND_INITD = init.d/xend
 XENDOMAINS_INITD = init.d/xendomains
 XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
+XENSTORE_SYSCONFIG = init.d/sysconfig.xenstore
 
 # Xen configuration dir and configs to go there.
 XEN_CONFIG_DIR = /etc/xen
@@ -56,9 +58,11 @@
 install-initd:
        [ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d
        [ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) 
$(DESTDIR)/etc/sysconfig
+       $(INSTALL_PROG) $(XENSTORED_INITD) $(DESTDIR)/etc/init.d
        $(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d
        $(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d
        $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) 
$(DESTDIR)/etc/sysconfig/xendomains
+       $(INSTALL_PROG) $(XENSTORE_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xenstore
 
 .PHONY: install-scripts
 install-scripts:
diff -r f115d0051672 tools/hotplug/Linux/init.d/xend
--- a/tools/hotplug/Linux/init.d/xend   Fri Mar 20 15:45:45 2009 +0000
+++ b/tools/hotplug/Linux/init.d/xend   Mon Mar 23 11:16:18 2009 +0000
@@ -8,9 +8,9 @@
 # description: Starts and stops the Xen control daemon.
 ### BEGIN INIT INFO
 # Provides:          xend
-# Required-Start:    $syslog $remote_fs
+# Required-Start:    $syslog $remote_fs xenstored
 # Should-Start:
-# Required-Stop:     $syslog $remote_fs
+# Required-Stop:     $syslog $remote_fs xenstored
 # Should-Stop:
 # Default-Start:     3 4 5
 # Default-Stop:      0 1 2 6
@@ -39,6 +39,17 @@
 
 case "$1" in
   start)
+       # Make sure xenstored is running before continuing.  It was recently
+       # moved out to its own rc script so it may not have been chkconfig'd
+       if ! service xenstored status &>/dev/null ; then
+           echo "xend: service xenstored not running"
+           echo "xend: please chkconfig xenstored"
+           echo "xend: starting service xenstored"
+           service xenstored start
+           if [ $? -ne 0 ] ; then 
+               exit 1
+           fi
+       fi
        touch /var/lock/subsys/xend
        xend start
        await_daemons_up
diff -r f115d0051672 tools/hotplug/Linux/init.d/xendomains
--- a/tools/hotplug/Linux/init.d/xendomains     Fri Mar 20 15:45:45 2009 +0000
+++ b/tools/hotplug/Linux/init.d/xendomains     Mon Mar 23 11:16:18 2009 +0000
@@ -16,9 +16,9 @@
 #
 ### BEGIN INIT INFO
 # Provides:          xendomains
-# Required-Start:    $syslog $remote_fs xend
+# Required-Start:    $syslog $remote_fs xenstored xend
 # Should-Start:
-# Required-Stop:     $syslog $remote_fs xend
+# Required-Stop:     $syslog $remote_fs xenstored xend
 # Should-Stop:
 # Default-Start:     3 4 5
 # Default-Stop:      0 1 2 6
diff -r f115d0051672 tools/hotplug/Linux/init.d/xenstored
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/init.d/xenstored      Mon Mar 23 11:16:18 2009 +0000
@@ -0,0 +1,152 @@
+#!/bin/bash
+#
+# xend         Script to start and stop xenstored.
+#
+# Author:       Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
+#
+# chkconfig: 2345 97 02
+# description: Starts and stops the xenstore daemon which 
+#              stores the xenbus state for all the VMs running.
+#              This daemon runs either in dom0 or in a dedicated
+#              stub domain.
+### BEGIN INIT INFO
+# Provides:          xend
+# Required-Start:    $syslog $remote_fs
+# Should-Start:
+# Required-Stop:     $syslog $remote_fs
+# Should-Stop:
+# Default-Start:     3 4 5
+# Default-Stop:      0 1 2 6
+# Default-Enabled:   yes
+# Short-Description: Start/stop xenstored
+# Description:       Starts and stops the XenStore daemon.
+### END INIT INFO
+
+if ! grep -q "control_d" /proc/xen/capabilities ; then
+    exit 0
+fi
+
+if [ -f /etc/sysconfig/xenstore ] ; then 
+    .  /etc/sysconfig/xenstore
+fi
+
+if [ "$STUBDOM" = yes ] ; then
+    IMG=/usr/lib/xen/boot/xenstore-stubdom.gz
+    ARGS="--no-fork"
+    XS_DOM_BUILDER=/usr/lib/xen/bin/xs_dom_builder
+    XENCONSOLE_DUMP=/usr/bin/xenconsole_dump
+else
+    ROOTDIR=${ROOTDIR:-/var/lib/xenstored}
+    PIDFILE="/var/run/xenstore.pid"
+    ARGS="--pid-file $PIDFILE"
+    #ARGS="$ARGS -T /var/log/xen/xenstored-trace.log"
+fi
+
+# Wait for xenstored to be up
+function await_xenstored_up
+{
+       i=1
+       rets=10
+       xenstore exists /local &>/dev/null
+       while [ $? -ne 0 -a $i -lt $rets ]; do
+           sleep 1
+           echo -n .
+           i=$(($i + 1))
+           xenstore exists /local &>/dev/null
+       done
+}
+
+stubdom_start() {
+    $XS_DOM_BUILDER $IMG - $ARGS &>/dev/null
+    return $?
+}
+
+daemon_start() {
+    touch $PIDFILE
+    if [ -n "$(pidof xenstored)" ] ; then
+       echo "Error: xenstored still running" >&2
+       return
+    fi
+    rm -f $ROOTDIR/tdb*
+    xenstored $ARGS && touch /var/lock/subsys/xenstored
+    return 0
+}
+
+stubdom_stop() {
+    echo "Cannot stop xenstored running in stub domain" >&2
+}
+
+daemon_stop() {
+    kill `cat $PIDFILE` && rm -f /var/lock/subsys/xenstored
+    RETVAL=$?
+    if [ $RETVAL -ne 0 ] ; then 
+       echo "Error: could not kill xenstored - check running" >&2
+    fi
+}
+
+stubdom_status() {
+    xenstore exists /local 
+    RETVAL=$?
+    if [ $RETVAL -eq 0 ] ; then 
+       echo "xenstore stub domain running"
+    else
+       echo "xenstore stub domain not running"
+    fi
+    return $RETVAL
+}
+
+daemon_status() {
+    PID="$(pidof xenstored)"
+    if [ -n "$PID" ] ; then
+       echo "xenstored [ PID $PID ] running ... "
+       return 0
+    else
+       echo "xenstored not running ... "
+       return 1
+    fi
+}
+
+stubdom_console() {
+    $XENCONSOLE_DUMP --domid=`cat /var/run/xenstore.did` --remote-port=1
+}
+
+if [ "$STUBDOM" = yes ] ; then
+    case "$1" in
+       start)
+           stubdom_start && await_xenstored_up
+           ;;
+       stop)
+           stubdom_stop
+           ;;
+       status)
+           stubdom_status
+           ;;
+       console)
+           stubdom_console
+           ;;
+       *)
+           echo $"Usage: $0 {start|stop|status|console}"
+           exit 1
+    esac
+else
+    case "$1" in
+       start)
+           daemon_start && await_xenstored_up
+           ;;
+       stop)
+           daemon_stop
+           ;;
+       status)
+           daemon_status
+           ;;
+       restart)
+           daemon_stop && daemon_start && await_xenstored_up
+           ;;
+       *)
+           echo $"Usage: $0 {start|stop|status|restart}"
+           exit 1
+    esac
+fi
+
+exit $?
+
diff -r f115d0051672 tools/misc/xend
--- a/tools/misc/xend   Fri Mar 20 15:45:45 2009 +0000
+++ b/tools/misc/xend   Mon Mar 23 11:16:18 2009 +0000
@@ -81,30 +81,6 @@
     if os.fork() == 0:
         os.execvp(daemon, (daemon,) + args)
 
-def start_xenstored():
-    pidfname = "/var/run/xenstore.pid"
-    try:
-        f = open(pidfname, "a")
-        try:
-            fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
-            rootdir = os.getenv("XENSTORED_ROOTDIR") or "/var/lib/xenstored"
-            for i in glob.glob(rootdir + "/tdb*"):
-                try:
-                    os.unlink(i)
-                except:
-                    pass
-            os.unlink(pidfname)
-        except:
-            pass
-        f.close()
-    except:
-        pass
-    XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
-    cmd = "xenstored --pid-file /var/run/xenstore.pid"
-    if XENSTORED_TRACE:
-        cmd += " -T /var/log/xen/xenstored-trace.log"
-    s,o = commands.getstatusoutput(cmd)
-
 def start_consoled():
     XENCONSOLED_TRACE = os.getenv("XENCONSOLED_TRACE")
     args = ""
@@ -127,12 +103,10 @@
         print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
     elif sys.argv[1] == 'start':
         if os.uname()[0] != "SunOS":
-            start_xenstored()
             start_consoled()
             start_blktapctrl()
         return daemon.start()
     elif sys.argv[1] == 'trace_start':
-        start_xenstored()
         start_consoled()
         start_blktapctrl()
         return daemon.start(trace=1)
@@ -141,7 +115,6 @@
     elif sys.argv[1] == 'reload':
         return daemon.reloadConfig()
     elif sys.argv[1] == 'restart':
-        start_xenstored()
         start_consoled()
         start_blktapctrl()
         return daemon.stop() or daemon.start()


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 22/24] [xen-unstable.hg] move xenstored from xend out into its own rc script and add xenstore sysconfig file, Alex Zeffertt <=