All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [PATCH 22/24] [xen-unstable.hg] move xenstored from xend out into its own rc script and add xenstore sysconfig file
Date: Mon, 23 Mar 2009 15:21:34 +0000	[thread overview]
Message-ID: <49C7A8FE.5080504@eu.citrix.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2 bytes --]




[-- Attachment #2: independent-xend-and-xenstored --]
[-- Type: text/plain, Size: 8831 bytes --]

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@eu.citrix.com>

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@eu.citrix.com>
+#
+# 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()



[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

                 reply	other threads:[~2009-03-23 15:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49C7A8FE.5080504@eu.citrix.com \
    --to=alex.zeffertt@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.