Skip to contentSkip to conversation

RFC: making the xen startup integrate better with distros

PATCH Daniel P. Berrange 2 participants 2 messages Jun 1, 2007

lore
Share & tools
lore
#0 lore raw

What follows below is an outline of what we're changing in Xen startup for Fedora 8. I know historically when getting into initscripts you tend to hit distro specific issues. So I'm posting this to see if there's any interest from others in having these changes integrated upstream. I'd like to thing that with a few minor tweaks this is general enough to be useful to other Linux distros at least - the init script is basically making use of LSB defined functions...

The way xen init scripts currently work is that they basically call out to /usr/bin/xend which re-implements ideas already provided to all init scripts via /etc/init.d/functions. Only the re-implementation is in python and is slower & doesn't integrate well with standard distro configuration procedure. eg we've no way to config stuff in /etc/sysconfig/xend to give users flexibility. The plan is thus:

* The auto-restart angel process should go since it merely serves to fork-bomb Xend when something goes wrong during startup. We've never seen XenD crash anyway so its not really buying us much except more complexity. Its also not monitoring the other Xen related daemons which have have seen crash! No other system daemons typically have auto crash restart built it - there are plenty of monitoring tools which add this system wide.

* The individual daemons should each be started from the init scripts directly. User can see exactly what's started & what's running. We can then easily pass custom command line args to each one.

* Drop a file in /etc/sysconfig/xen allowing user to customize the startup options for individual daemons.

* Drop a file in /etc/sysconfig/modules/xen.modules to trigger loading of the backend driver modules.

So we have a config file in /etc/sysconfig/modules containing user config options

[root@celery console]# cat /etc/sysconfig/xend
#XENSTORED_PID="/var/run/xenstore.pid"
#XENSTORED_ARGS=

# Log all hypervisor messages (cf xm dmesg)
#XENCONSOLED_LOG_HYPERVISOR=yes

# Log all guest console output (cf xm console)
#XENCONSOLED_LOG_GUESTS=yes

# Location to store guest & hypervisor logs
#XENCONSOLED_LOG_DIR=/var/log/xen/console

#XENCONSOLED_ARGS=

#BLKTAPCTRL_ARGS=

(This would be /etc/default/xend instead on Debian I believe)

When starting, we run all four currently provided Xen daemon processes, list out all daemons being started along the way...

[root@celery console]# service xend start
Starting xen daemons: xenstored blktapctrl xenconsoled xend[ OK ]

And you can see they're each now running

[root@celery console]# service xend status
xenstored (pid 2924) is running...
blktapctrl (pid 2934) is running...
xenconsoled (pid 32595) is running...
xend (pid 32599) is running...
[ OK ]

See the processes running and that they picked up config from settings the user provided in /etc/sysconfig/xend

root      2924  1.0  0.0   8412   988 ?        S    May24 105:31 xenstored --pid-file /var/run/xenstore.pid
root     32595  0.0  0.0  20516   632 ?        Sl   18:11   0:00 /usr/sbin/xenconsoled --log=all --log-dir=/var/log/xen/console
root     32599  4.9  0.3 346952 13732 ?        Sl   18:11   0:09 python /usr/sbin/xend

We can also trigger a reload by directly sending each reloadable daemon a SIGHUP. This makes xend re-read its config file, and make xenconsoled re-open its logfiles

[root@celery console]# service xend reload
Reloading xen daemons: xenconsoled xend [ OK ]

Both Xend & XenConsoleD are capable of being stopped & restarted. It isn't safe to stop blktapctrl or xenstored though. So init script only stops the former two processes. eg:

[root@celery console]# service xend stop
Stopping xen daemons: xenconsoled xend [ OK ]

Looking again at status of individual daemons, notice how we only stopped xend & xenconsoled:

[root@celery console]# service xend status
xenstored (pid 2924) is running...
blktapctrl (pid 2934) is running...
xenconsoled is stopped
xend is stopped
[FAILED]

The attached patch shows the changes to the init script to do this, as well as killing off most of tools/misc/xend (what becomes /usr/sbin/xend). It could probably go a bit further a kill off alot of stuff in the python class tools/python/xen/xend/server/SrvDaemon.py since much of that isn't needed now that its leveraging standard LSB init functions to do most of the PID file handling for shutdown, reload, status commands.

Regards,
Dan.

Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
tools/examples/init.d/xend +136 -23
diff -rup xen-3.1.0-src/tools/examples/init.d/xend xen-3.1.0-src.new/tools/examples/init.d/xend
@@ -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=yes
+XENCONSOLED_LOG_GUESTS=yes
+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
 
tools/misc/xend +1 -108

124 lines not on this page · raw message

tools/python/xen/xend/osdep.py +1 -1
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
@@ -25,7 +25,7 @@ _scripts_dir = {
 }
 
 _xend_autorestart = {
-    "Linux": True,
+    "Linux": False,
     "SunOS": False,
 }
 
tools/python/xen/xend/server/SrvDaemon.py +8 -1
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
@@ -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

#!/bin/sh

test -f /proc/xen/capabilities || exit 0 grep -q "control_d" /proc/xen/capabilities || exit 0

for m in blkbk netbk blktap xenblktap
do
modprobe $m >/dev/null 2>&1
done

#XENSTORED_PID="/var/run/xenstore.pid"
#XENSTORED_ARGS=

# Log all hypervisor messages (cf xm dmesg)
#XENCONSOLED_LOG_HYPERVISOR=yes

# Log all guest console output (cf xm console)
#XENCONSOLED_LOG_GUESTS=yes

# Location to store guest & hypervisor logs
#XENCONSOLED_LOG_DIR=/var/log/xen/console

#XENCONSOLED_ARGS=

#BLKTAPCTRL_ARGS=

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 1 line · Daniel P. Berrange

What follows below is an outline of what we're changing in Xen startup for Fedora 8. I know historically when getting into initscripts you tend to hit distro specific issues. So I'm posting this to see if there's any interest from others in having these changes integrated upstream. I'd like to thing that with a few minor tweaks this is general enough to be useful to other Linux distros at least - the init script is basically making use of LSB defined functions...

Sounds like an excellent idea. Debian and Ubuntu don't ship with a 'functions' file, but I think this could easily be made to work on both.

Quoted 3 lines

* The individual daemons should each be started from the init scripts directly. User can see exactly what's started & what's running. We can then easily pass custom command line args to each one.

Agreed. The other advantage of this is that it would be easy to launch said programs from a daemon monitoring app (ie, daemontools, etc).

Quoted 2 lines

* Drop a file in /etc/sysconfig/xen allowing user to customize the startup options for individual daemons.

Like you said, also /etc/default/xen on Debian. Debian does already have an /etc/default/xendomains which control the way that domains are started/stopped.

Quoted 1 line

We can also trigger a reload by directly sending each reloadable daemon a SIGHUP. This makes xend re-read its config file, and make xenconsoled re-open its logfiles

Beautiful!

Quoted 1 line

The attached patch shows the changes to the init script to do this, as well as killing off most of tools/misc/xend (what becomes /usr/sbin/xend). It could probably go a bit further a kill off alot of stuff in the python class tools/python/xen/xend/server/SrvDaemon.py since much of that isn't needed now that its leveraging standard LSB init functions to do most of the PID file handling for shutdown, reload, status commands.

The Debian packaging for Xen also includes a pile of patches to allow python paths and such to be more configurable - this is because Debian allows you to have multiple versions of the tools and hypervisor installed. It'd be really nice to see these integrated upstream; they are the primary thing that takes awhile to patch up with each new Xen release to get Debian packages built. If you're interested in seeing what they are, I can post them, or convince one of the regular Deb developers to upload them. :)

------------------------------------------------------------------------

| nate carlson | [email protected] | http://www.natecarlson.com |
|       depriving some poor village of its idiot since 1981            |

------------------------------------------------------------------------