Blob Blame History Raw
diff -rup xen-3.1.0-src/tools/examples/init.d/xend xen-3.1.0-src.new/tools/examples/init.d/xend
--- xen-3.1.0-src/tools/examples/init.d/xend	2007-05-31 12:14:19.000000000 -0400
+++ xen-3.1.0-src.new/tools/examples/init.d/xend	2007-05-31 17:53:29.000000000 -0400
@@ -19,48 +19,161 @@
 # Description:       Starts and stops the Xen control daemon.
 ### END INIT INFO
 
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+if [ ! -d /proc/xen ]; then
+	exit 0
+fi
 if ! grep -q "control_d" /proc/xen/capabilities ; then
 	exit 0
 fi
 
-# Wait for Xend to be up
-function await_daemons_up
-{
-	i=1
-	rets=10
-	xend status
-	while [ $? -ne 0 -a $i -lt $rets ]; do
-	    sleep 1
-	    echo -n .
-	    i=$(($i + 1))
-	    xend status
-	done
+# Default config params
+XENSTORED_PID="/var/run/xenstore.pid"
+XENSTORED_ARGS=
+
+XENCONSOLED_LOG_HYPERVISOR=no
+XENCONSOLED_LOG_GUESTS=no
+XENCONSOLED_LOG_DIR=/var/log/xen/console
+XENCONSOLED_ARGS=
+
+BLKTAPCTRL_ARGS=
+
+# User customized params
+test -f /etc/sysconfig/xend && . /etc/sysconfig/xend
+
+XENCONSOLED_LOG=none
+if [ "$XENCONSOLED_LOG_HYPERVISOR" = "yes" ]
+then
+        if [ "$XENCONSOLED_LOG_GUESTS" = "yes" ]
+        then
+                XENCONSOLED_LOG=all
+        else
+                XENCONSOLED_LOG=hv
+        fi
+else
+        if [ "$XENCONSOLED_LOG_GUESTS" = "yes" ]
+        then
+                XENCONSOLED_LOG=guest
+        fi
+fi
+
+start() {
+	echo -n $"Starting xen daemons: "
+
+	echo -n "xenstored "
+        /usr/sbin/xenstored --pid-file $XENSTORED_PID $XENSTORED_ARGS
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	echo -n "blktapctrl "
+        /usr/sbin/blktapctrl $BLKTAPCTRL_ARGS
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	echo -n "xenconsoled "
+        /usr/sbin/xenconsoled --log=$XENCONSOLED_LOG --log-dir=$XENCONSOLED_LOG_DIR $XENCONSOLED_ARGS
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+        echo -n "xend"
+	/usr/sbin/xend
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	test $RETVAL = 0 && echo_success || echo_failure
+        echo
+        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/xend
 }
 
+stop() {
+	echo -n $"Stopping xen daemons: "
+
+	# NB not safe to stop xenstored, or blktapctrl if guests are active
+	# or backend driver modules are loaded, so we skip them
+
+	echo -n "xenconsoled "
+	killproc xenconsoled > /dev/null
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	echo -n "xend "
+	killproc xend > /dev/null
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	test $RETVAL = 0 && echo_success || echo_failure
+        echo
+        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xend
+}
+
+rcstatus() {
+        status xenstored
+        rc=$?
+        test $rc != 0 && RETVAL=$rc
+
+        status blktapctrl
+        rc=$?
+        test $rc != 0 && RETVAL=$rc
+
+        status xenconsoled
+        rc=$?
+        test $rc != 0 && RETVAL=$rc
+
+        status xend
+        rc=$?
+        test $rc != 0 && RETVAL=$rc
+	test $RETVAL = 0 && echo_success || echo_failure
+	echo
+}
+
+reload() {
+	echo -n $"Reloading xen daemons: "
+
+	echo -n "xenconsoled "
+	killproc xenconsoled -HUP > /dev/null
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	echo -n "xend "
+	killproc xend -HUP > /dev/null
+	rc=$?
+	test $rc = 0 || RETVAL=$rc
+
+	test $RETVAL = 0 && echo_success || echo_failure
+        echo
+}
+
+RETVAL=0
 case "$1" in
   start)
-	xend start
-	await_daemons_up
+        start
 	;;
   stop)
-	xend stop
+        stop
 	;;
   status)
-	xend status
+        rcstatus
 	;;
   reload)
-        xend reload
+	reload
         ;;
   restart|force-reload)
-	xend restart
-	await_daemons_up
+	stop
+        start
 	;;
+  condrestart)
+        if [ -f /var/lock/subsys/xend ]
+        then
+                stop
+                start
+        fi
+        ;;
   *)
-	# do not advertise unreasonable commands that there is no reason
-	# to use with this device
-	echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
+	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
 	exit 1
 esac
 
-exit $?
+exit $RETVAL
 
diff -rup xen-3.1.0-src/tools/misc/xend xen-3.1.0-src.new/tools/misc/xend
--- xen-3.1.0-src/tools/misc/xend	2007-05-31 13:10:49.000000000 -0400
+++ xen-3.1.0-src.new/tools/misc/xend	2007-05-31 13:44:14.000000000 -0400
@@ -8,123 +8,16 @@
 """Xen management daemon.
    Provides console server and HTTP management api.
 
-   Run:
-   xend start
-
-   Restart:
-   xend restart
-
-   The daemon is stopped with:
-   xend stop
-
    The daemon should reconnect to device control interfaces
    and recover its state when restarted.
-
-   On Solaris, the daemons are SMF managed, and you should not attempt
-   to start xend by hand.
 """
-import os
-import os.path
 import sys
-import socket
-import signal
-import time
-import commands
-
-result = commands.getstatusoutput(os.path.join(os.path.dirname(sys.argv[0]),
-                                               'xen-python-path'))
-if result[0] != 0:
-    print >>sys.stderr, result[1]
-    sys.exit(1)
-
-sys.path.append(result[1])
 
 from xen.xend.server import SrvDaemon
 
-class CheckError(ValueError):
-    pass
-
-def hline():
-    print >>sys.stderr, "*" * 70
-
-def msg(message):
-    print >>sys.stderr, "*" * 3, message
-
-def check_logging():
-    """Check python logging is installed and raise an error if not.
-    Logging is standard from Python 2.3 on.
-    """
-    try:
-        import logging
-    except ImportError:
-        hline()
-        msg("Python logging is not installed.")
-        msg("Use 'make install-logging' at the xen root to install.")
-        msg("")
-        msg("Alternatively download and install from")
-        msg("http://www.red-dove.com/python_logging.html")
-        hline()
-        raise CheckError("logging is not installed")
-
-def check_user():
-    """Check that the effective user id is 0 (root).
-    """
-    if os.geteuid() != 0:
-        hline()
-        msg("Xend must be run as root.")
-        hline()
-        raise CheckError("invalid user")
-
-def start_xenstored():
-    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():
-    if os.fork() == 0:
-        os.execvp('xenconsoled', ['xenconsoled'])
-
-def start_blktapctrl():
-    if os.fork() == 0:
-        os.execvp('blktapctrl', ['blktapctrl'])
-            
 def main():
-    try:
-        check_logging()
-        check_user()
-    except CheckError:
-        sys.exit(1)
-    
     daemon = SrvDaemon.instance()
-    if not sys.argv[1:]:
-        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)
-    elif sys.argv[1] == 'stop':
-        return daemon.stop()
-    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()
-    elif sys.argv[1] == 'status':
-        return daemon.status()
-    else:
-        print 'not an option:', sys.argv[1]
-    return 1
+    return daemon.start()
 
 if __name__ == '__main__':
     sys.exit(main())
diff -rup xen-3.1.0-src/tools/python/xen/xend/osdep.py xen-3.1.0-src.new/tools/python/xen/xend/osdep.py
--- xen-3.1.0-src/tools/python/xen/xend/osdep.py	2007-05-18 10:45:21.000000000 -0400
+++ xen-3.1.0-src.new/tools/python/xen/xend/osdep.py	2007-05-31 13:13:07.000000000 -0400
@@ -25,7 +25,7 @@ _scripts_dir = {
 }
 
 _xend_autorestart = {
-    "Linux": True,
+    "Linux": False,
     "SunOS": False,
 }
 
diff -rup xen-3.1.0-src/tools/python/xen/xend/server/SrvDaemon.py xen-3.1.0-src.new/tools/python/xen/xend/server/SrvDaemon.py
--- xen-3.1.0-src/tools/python/xen/xend/server/SrvDaemon.py	2007-05-18 10:45:21.000000000 -0400
+++ xen-3.1.0-src.new/tools/python/xen/xend/server/SrvDaemon.py	2007-05-31 14:36:23.000000000 -0400
@@ -109,7 +109,14 @@ class Daemon:
         # Fork, this allows the group leader to exit,
         # which means the child can never again regain control of the
         # terminal
-        if os.fork():
+        child = os.fork()
+        if child:
+            if not osdep.xend_autorestart:
+                pidfile = open(XEND_PID_FILE, 'w')
+                try:
+                    pidfile.write(str(child))
+                finally:
+                    pidfile.close()
             os._exit(0)
 
         # Detach from standard file descriptors, and redirect them to