ia64/xen-unstable

changeset 7528:895d66f6de44

New xendomains init script, courtesy of Kurt Garloff:

It now allows the user to configure what he wants to be done on
xendomains stop: sysrq, migrate, save, or shutdown.
For this to be safe, a timeout has been introduced (optional).
On start, saved domains may be restored, and not yet started
domains from the auto start dir will be started in addition.
status reports missing domains, restart and reload work as well.

The init script is somewhat SUSE-ish, but it should work on LSB
compliant and on RH based distros as well.

I would appreciate this to be put into tools/examples/init.d/

Signed-off-by: Kurt Garloff <garloff@suse.de>
author emellor@leeni.uk.xensource.com
date Wed Oct 26 14:55:32 2005 +0100 (2005-10-26)
parents a39aee6d660f
children 4983606a263e
files tools/examples/Makefile tools/examples/init.d/sysconfig.xendomains tools/examples/init.d/xendomains
line diff
     1.1 --- a/tools/examples/Makefile	Wed Oct 26 13:41:00 2005 +0100
     1.2 +++ b/tools/examples/Makefile	Wed Oct 26 14:55:32 2005 +0100
     1.3 @@ -9,6 +9,7 @@ INSTALL_DATA	= $(INSTALL) -m0644
     1.4  # Init scripts.
     1.5  XEND_INITD = init.d/xend
     1.6  XENDOMAINS_INITD = init.d/xendomains
     1.7 +XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
     1.8  
     1.9  # Xen configuration dir and configs to go there.
    1.10  XEN_CONFIG_DIR = /etc/xen
    1.11 @@ -51,8 +52,10 @@ install: all install-initd install-confi
    1.12  
    1.13  install-initd:
    1.14  	[ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d
    1.15 +	[ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) $(DESTDIR)/etc/sysconfig
    1.16  	$(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d
    1.17  	$(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d
    1.18 +	$(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xendomains
    1.19  
    1.20  install-configs: $(XEN_CONFIGS)
    1.21  	[ -d $(DESTDIR)$(XEN_CONFIG_DIR) ] || \
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/examples/init.d/sysconfig.xendomains	Wed Oct 26 14:55:32 2005 +0100
     2.3 @@ -0,0 +1,126 @@
     2.4 +## Path: System/xen
     2.5 +## Description: xen domain start/stop on boot
     2.6 +## Type: string
     2.7 +## Default: 
     2.8 +#
     2.9 +# The xendomains script can send SysRq requests to domains on shutdown.
    2.10 +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility
    2.11 +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks
    2.12 +# of the domains ("s").
    2.13 +#
    2.14 +XENDOMAINS_SYSRQ=""
    2.15 +
    2.16 +## Type: integer 
    2.17 +## Default: 100000
    2.18 +#
    2.19 +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait
    2.20 +# (in microseconds) after each SysRq, so the domain has a chance to react.
    2.21 +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set
    2.22 +# it to a relatively high value (1200000).
    2.23 +#
    2.24 +XENDOMAINS_USLEEP=100000
    2.25 +
    2.26 +## Type: string
    2.27 +## Default: ""
    2.28 +#
    2.29 +# Set this to a non-empty string if you want to migrate virtual machines
    2.30 +# on shutdown. The string will be passed to the xm migrate DOMID command
    2.31 +# as is: It should contain the target IP address of the physical machine
    2.32 +# to migrate to and optionally parameters like --live. Leave empty if
    2.33 +# you don't want to try virtual machine relocation on shutdown.
    2.34 +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for
    2.35 +# that domain.
    2.36 +#
    2.37 +XENDOMAINS_MIGRATE=""
    2.38 +
    2.39 +## Type: string
    2.40 +## Default: /var/lib/xen/save
    2.41 +#
    2.42 +# Directory to save running domains to when the system (dom0) is
    2.43 +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE
    2.44 +# is set (see below). Leave empty to disable domain saving on shutdown 
    2.45 +# (e.g. because you rather shut domains down).
    2.46 +# If domain saving does succeed, SHUTDOWN will not be executed.
    2.47 +#
    2.48 +XENDOMAINS_SAVE=/var/lib/xen/save
    2.49 +
    2.50 +## Type: string
    2.51 +## Default: "--halt --wait"
    2.52 +#
    2.53 +# If neither MIGRATE nor SAVE were enabled or if they failed, you can
    2.54 +# try to shut down a domain by sending it a shutdown request. To do this,
    2.55 +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting
    2.56 +# for the domain to be really down. Leave empty to skip domain shutdown.
    2.57 +#
    2.58 +XENDOMAINS_SHUTDOWN="--halt --wait"
    2.59 +
    2.60 +## Type: string
    2.61 +## Default: "--all --halt --wait"
    2.62 +#
    2.63 +# After we have gone over all virtual machines (resp. all automatically
    2.64 +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq,
    2.65 +# migrated, saved and/or shutdown according to the settings above, we
    2.66 +# might want to shutdown the virtual machines that are still running
    2.67 +# for some reason or another. To do this, set this variable to
    2.68 +# "--all --halt --wait", it will be passed to xm shutdown.
    2.69 +# Leave it empty not to do anything special here.
    2.70 +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY
    2.71 +# is set.)
    2.72 +# 
    2.73 +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait"
    2.74 +
    2.75 +## Type: boolean
    2.76 +## Default: true
    2.77 +#
    2.78 +# This variable determines whether saved domains from XENDOMAINS_SAVE
    2.79 +# will be restored on system startup. 
    2.80 +#
    2.81 +XENDOMAINS_RESTORE=true
    2.82 +
    2.83 +## Type: string
    2.84 +## Default: /etc/xen/auto
    2.85 +#
    2.86 +# This variable sets the directory where domains configurations
    2.87 +# are stored that should be started on system startup automatically.
    2.88 +# Leave empty if you don't want to start domains automatically
    2.89 +# (or just don't place any xen domain config files in that dir).
    2.90 +# Note that the script tries to be clever if both RESTORE and AUTO are 
    2.91 +# set: It will first restore saved domains and then only start domains
    2.92 +# in AUTO which are not running yet. 
    2.93 +# Note that the name matching is somewhat fuzzy.
    2.94 +#
    2.95 +XENDOMAINS_AUTO=/etc/xen/auto
    2.96 +
    2.97 +## Type: boolean
    2.98 +## Default: false
    2.99 +# 
   2.100 +# If this variable is set to "true", only the domains started via config 
   2.101 +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ,
   2.102 +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise
   2.103 +# all running domains will be. 
   2.104 +# Note that the name matching is somewhat fuzzy.
   2.105 +# 
   2.106 +XENDOMAINS_AUTO_ONLY=false
   2.107 +
   2.108 +## Type: integer
   2.109 +## Default: 300
   2.110 +#
   2.111 +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown,
   2.112 +# shutdown --all) may be executed. In the worst case, these commands may
   2.113 +# stall forever, which will prevent a successful shutdown of the machine.
   2.114 +# If this variable is non-zero, the script will set up a watchdog timer
   2.115 +# for every of these xm commands and time it out after the number of seconds
   2.116 +# specified by this variable.
   2.117 +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only
   2.118 +# zombies are still running, so you don't need to enable this timeout just
   2.119 +# for the zombie case.
   2.120 +# The setting should be large enough to make sure that migrate/save/shutdown
   2.121 +# can succeed. If you do live migrations, keep in mind that live migration
   2.122 +# of a 1GB machine over Gigabit ethernet may actually take something like
   2.123 +# 100s (assuming that live migration uses 10% of the network # bandwidth).
   2.124 +# Depending on the virtual machine, a shutdown may also require a significant
   2.125 +# amount of time. So better setup this variable to a huge number and hope the
   2.126 +# watchdog never fires.
   2.127 +#
   2.128 +XENDOMAINS_STOP_MAXWAIT=300
   2.129 +
     3.1 --- a/tools/examples/init.d/xendomains	Wed Oct 26 13:41:00 2005 +0100
     3.2 +++ b/tools/examples/init.d/xendomains	Wed Oct 26 14:55:32 2005 +0100
     3.3 @@ -1,4 +1,4 @@
     3.4 -#!/bin/sh
     3.5 +#!/bin/bash
     3.6  #
     3.7  # /etc/init.d/xendomains
     3.8  # Start / stop domains automatically when domain 0 boots / shuts down.
     3.9 @@ -22,101 +22,388 @@
    3.10  # Should-Stop:
    3.11  # Default-Start:     3 4 5
    3.12  # Default-Stop:      0 1 2 6
    3.13 +# Default-Enabled:   yes
    3.14  # Short-Description: Start/stop secondary xen domains
    3.15  # Description:       Start / stop domains automatically when domain 0 
    3.16  #                    boots / shuts down.
    3.17  ### END INIT INFO
    3.18  
    3.19 +# Correct exit code would probably be 5, but it's enough 
    3.20 +# if xend complains if we're not running as privileged domain
    3.21  if ! [ -e /proc/xen/privcmd ]; then
    3.22  	exit 0
    3.23  fi
    3.24  
    3.25 -RETVAL=0
    3.26 +LOCKFILE=/var/lock/subsys/xendomains
    3.27 +XENDOM_CONFIG=/etc/sysconfig/xendomains
    3.28  
    3.29 -INITD=/etc/init.d
    3.30 +test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
    3.31 +	if [ "$1" = "stop" ]; then exit 0;
    3.32 +	else exit 6; fi; }
    3.33  
    3.34 -AUTODIR=/etc/xen/auto
    3.35 -LOCKFILE=/var/lock/subsys/xendomains
    3.36 +. $XENDOM_CONFIG
    3.37  
    3.38 -if [ -e /lib/lsb ]; then
    3.39 -    # assume an LSB-compliant distro (Debian with LSB package,
    3.40 -    # recent-enough SuSE, others...)
    3.41 -
    3.42 -    . /lib/lsb/init-functions # source LSB standard functions
    3.43 -
    3.44 -    on_fn_exit()
    3.45 +# Use the SUSE rc_ init script functions;
    3.46 +# emulate them on LSB, RH and other systems
    3.47 +if test -e /etc/rc.status; then
    3.48 +    # SUSE rc script library
    3.49 +    . /etc/rc.status
    3.50 +else    
    3.51 +    _cmd=$1
    3.52 +    declare -a _SMSG
    3.53 +    if test "${_cmd}" = "status"; then
    3.54 +	_SMSG=(running dead dead unused unknown)
    3.55 +	_RC_UNUSED=3
    3.56 +    else
    3.57 +	_SMSG=(done failed failed missed failed skipped unused failed failed)
    3.58 +	_RC_UNUSED=6
    3.59 +    fi
    3.60 +    if test -e /lib/lsb/init-functions; then
    3.61 +	# LSB    
    3.62 +    	. /lib/lsb/init-functions
    3.63 +	echo_rc()
    3.64 +	{
    3.65 +	    if test ${_RC_RV} = 0; then
    3.66 +		log_success_msg "  [${_SMSG[${_RC_RV}]}] "
    3.67 +	    else
    3.68 +		log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
    3.69 +	    fi
    3.70 +	}
    3.71 +    elif test -e /etc/init.d/functions; then
    3.72 +	# REDHAT
    3.73 +	. /etc/init.d/functions
    3.74 +	echo_rc()
    3.75 +	{
    3.76 +	    #echo -n "  [${_SMSG[${_RC_RV}]}] "
    3.77 +	    if test ${_RC_RV} = 0; then
    3.78 +		success "  [${_SMSG[${_RC_RV}]}] "
    3.79 +	    else
    3.80 +		failure "  [${_SMSG[${_RC_RV}]}] "
    3.81 +	    fi
    3.82 +	}
    3.83 +    else    
    3.84 +	# emulate it
    3.85 +	echo_rc()
    3.86 +	{
    3.87 +	    echo "  [${_SMSG[${_RC_RV}]}] "
    3.88 +	}
    3.89 +    fi
    3.90 +    rc_reset() { _RC_RV=0; }
    3.91 +    rc_failed()
    3.92      {
    3.93 -	if [ $RETVAL -eq 0 ]; then
    3.94 -	    log_success_msg
    3.95 -	else
    3.96 -	    log_failure_msg
    3.97 -	fi
    3.98 +	if test -z "$1"; then 
    3.99 +	    _RC_RV=1;
   3.100 +	elif test "$1" != "0"; then 
   3.101 +	    _RC_RV=$1; 
   3.102 +    	fi
   3.103 +	return ${_RC_RV}
   3.104      }
   3.105 -elif [ -r $INITD/functions ]; then
   3.106 -    # assume a Redhat-like distro
   3.107 -    . $INITD/functions # source Redhat functions
   3.108 -
   3.109 -    on_fn_exit()
   3.110 +    rc_check()
   3.111 +    {
   3.112 +	return rc_failed $?
   3.113 +    }	
   3.114 +    rc_status()
   3.115      {
   3.116 -	if [ $RETVAL -eq 0 ]; then
   3.117 -	    success
   3.118 -	else
   3.119 -	    failure
   3.120 -	fi
   3.121 -	
   3.122 -	echo
   3.123 +	rc_failed $?
   3.124 +	if test "$1" = "-r"; then _RC_RV=0; shift; fi
   3.125 +	if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
   3.126 +	if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
   3.127 +	if test "$1" = "-v"; then echo_rc; shift; fi
   3.128 +	if test "$1" = "-r"; then _RC_RV=0; shift; fi
   3.129 +	return ${_RC_RV}
   3.130      }
   3.131 -else
   3.132 -    # none of the above
   3.133 -    LOCKFILE=/var/lock/xendomains
   3.134 -
   3.135 -    on_fn_exit()
   3.136 +    rc_exit() { exit ${_RC_RV}; }
   3.137 +    rc_active() 
   3.138      {
   3.139 -	echo
   3.140 +	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
   3.141 +	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
   3.142 +	return 1
   3.143      }
   3.144  fi
   3.145  
   3.146 +# Reset status of this service
   3.147 +rc_reset
   3.148  
   3.149 +# read name from xen config file
   3.150 +rdname()
   3.151 +{
   3.152 +    NM=`grep '^name *=' $1 | sed -e 's/^name *= *"\([^"]*\)".*$/\1/' -e 's/%[id]/[0-9]*/g'`
   3.153 +}
   3.154  
   3.155 -start() {
   3.156 -    if [ -f $LOCKFILE ]; then return; fi
   3.157 +rdnames()
   3.158 +{
   3.159 +    NAMES=
   3.160 +    if test ! -d $XENDOMAINS_AUTO -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then 
   3.161 +	return
   3.162 +    fi
   3.163 +    for dom in $XENDOMAINS_AUTO/*; do
   3.164 +	rdname $dom
   3.165 +	if test -z $NAMES; then 
   3.166 +	    NAMES=$NM; 
   3.167 +	else
   3.168 +	    NAMES="$NAMES|$NM"
   3.169 +	fi
   3.170 +    done
   3.171 +}
   3.172  
   3.173 -    echo -n $"Starting auto Xen domains:"
   3.174 +parseln()
   3.175 +{
   3.176 +    name=`echo "$1" | cut -c0-17`
   3.177 +    name=${name%% *}
   3.178 +    rest=`echo "$1" | cut -c18- `
   3.179 +    read id mem cpu vcpu state tm < <(echo "$rest")
   3.180 +}
   3.181  
   3.182 -    # We expect config scripts for auto starting domains to be in
   3.183 -    # AUTODIR - they could just be symlinks to files elsewhere
   3.184 -    if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then
   3.185 +is_running()
   3.186 +{
   3.187 +    rdname $1
   3.188 +    RC=1
   3.189 +    while read LN; do
   3.190 +	parseln "$LN"
   3.191 +	if test $id = 0; then continue; fi
   3.192 +	case $name in 
   3.193 +	    ($NM)
   3.194 +		RC=0
   3.195 +		;;
   3.196 +	esac
   3.197 +    done < <(xm list | grep -v '^Name')
   3.198 +    return $RC
   3.199 +}
   3.200 +
   3.201 +start() 
   3.202 +{
   3.203 +    if [ -f $LOCKFILE ]; then 
   3.204 +	echo -n "xendomains already running (lockfile exists)"
   3.205 +	return; 
   3.206 +    fi
   3.207 +
   3.208 +    if test "$XENDOMAINS_RESTORE" = "true" -a -n "$XENDOMAINS_SAVE" \
   3.209 +	    -a -d $XENDOMAINS_SAVE -a `/bin/ls $XENDOMAINS_SAVE | wc -l` -gt 0; then
   3.210 +
   3.211  	touch $LOCKFILE
   3.212 -	
   3.213 -       # Create all domains with config files in AUTODIR.
   3.214 -	for dom in  $AUTODIR/*; do
   3.215 -	    xm create --quiet --defconfig $dom
   3.216 +	echo -n "Restoring Xen domains:"
   3.217 +	for dom in $XENDOMAINS_SAVE/*; do
   3.218 +	    echo -n " ${dom##*/}"
   3.219 +	    xm restore $dom
   3.220  	    if [ $? -ne 0 ]; then
   3.221 -		RETVAL=$?
   3.222 +		rc_failed $?
   3.223 +		echo -n '!'
   3.224 +	    else
   3.225 +		# mv $dom ${dom%/*}/.${dom##*/}
   3.226 +		rm $dom
   3.227  	    fi
   3.228  	done
   3.229 -
   3.230      fi
   3.231  
   3.232 -    on_fn_exit
   3.233 +    if test -n "$XENDOMAINS_AUTO" -a -d $XENDOMAINS_AUTO \
   3.234 +	    -a `/bin/ls $XENDOMAINS_AUTO | wc -l` -gt 0; then
   3.235 +
   3.236 +	touch $LOCKFILE
   3.237 +	echo -n "Starting auto Xen domains:"
   3.238 +	# We expect config scripts for auto starting domains to be in
   3.239 +	# XENDOMAINS_AUTO - they could just be symlinks to files elsewhere
   3.240 +
   3.241 +	# Create all domains with config files in XENDOMAINS_AUTO.
   3.242 +	# TODO: We should record which domain name belongs 
   3.243 +	# so we have the option to selectively shut down / migrate later
   3.244 +	for dom in $XENDOMAINS_AUTO/*; do
   3.245 +	    echo -n " ${dom##*/}"
   3.246 +	    if is_running $dom; then
   3.247 +		echo -n "(skip)"
   3.248 +	    else
   3.249 +		xm create --quiet --defconfig $dom
   3.250 +		if [ $? -ne 0 ]; then
   3.251 +		    rc_failed $?
   3.252 +		    echo -n '!'
   3.253 +		fi
   3.254 +	    fi
   3.255 +	done
   3.256 +    fi	
   3.257 +}
   3.258 +
   3.259 +all_zombies()
   3.260 +{
   3.261 +    while read LN; do
   3.262 +	parseln "$LN"
   3.263 +	if test $id = 0; then continue; fi
   3.264 +	if test "$state" != "-b---d" -a "$state" != "-----d"; then
   3.265 +	    return 1;
   3.266 +	fi
   3.267 +    done < <(xm list | grep -v '^Name')
   3.268 +    return 0
   3.269 +}
   3.270 +
   3.271 +# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish;
   3.272 +# if it has not exited by that time kill it, so the init script will
   3.273 +# succeed within a finite amount of time; if $2 is nonnull, it will
   3.274 +# kill the command as well as soon as no domain (except for zombies)
   3.275 +# are left (used for shutdown --all).
   3.276 +watchdog_xm()
   3.277 +{
   3.278 +    if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
   3.279 +	exit
   3.280 +    fi
   3.281 +    usleep 20000
   3.282 +    for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
   3.283 +	# exit if xm save/migrate/shutdown is finished
   3.284 +	PSAX=`ps axlw | grep "xm $1" | grep -v grep`
   3.285 +	if test -z "$PSAX"; then exit; fi
   3.286 +	echo -n "."; sleep 1
   3.287 +	# go to kill immediately if there's only zombies left
   3.288 +	if all_zombies && test -n "$2"; then break; fi
   3.289 +    done
   3.290 +    sleep 1
   3.291 +    read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
   3.292 +    # kill xm $1
   3.293 +    kill $PSPID >/dev/null 2>&1
   3.294  }
   3.295  
   3.296  stop()
   3.297  {
   3.298 +    # Collect list of domains to shut down
   3.299 +    if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
   3.300 +	rdnames
   3.301 +    fi
   3.302 +    echo -n "Shutting down Xen domains:"
   3.303 +    while read LN; do
   3.304 +	parseln "$LN"
   3.305 +	if test $id = 0; then continue; fi
   3.306 +	echo -n " $name"
   3.307 +	if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
   3.308 +	    case $name in
   3.309 +		($NAMES)
   3.310 +		    # nothing
   3.311 +		    ;;
   3.312 +		(*)
   3.313 +		    echo -n "(skip)"
   3.314 +		    continue
   3.315 +		    ;;
   3.316 +	    esac
   3.317 +	fi
   3.318 +	# XENDOMAINS_SYSRQ chould be something like just "s" 
   3.319 +	# or "s e i u" or even "s e s i u o"
   3.320 +	# for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so
   3.321 +	if test -n "$XENDOMAINS_SYSRQ"; then
   3.322 +	    for sysrq in $XENDOMAINS_SYSRQ; do
   3.323 +		echo -n "(SR-$sysrq)"
   3.324 +		xm sysrq $id $sysrq
   3.325 +		if test $? -ne 0; then
   3.326 +		    rc_failed $?
   3.327 +		    echo -n '!'
   3.328 +		fi
   3.329 +		# usleep just ignores empty arg
   3.330 +		usleep $XENDOMAINS_USLEEP
   3.331 +	    done
   3.332 +	fi
   3.333 +	if test "$state" = "-b---d" -o "$state" = "-----d"; then
   3.334 +	    echo -n "(zomb)"
   3.335 +	    continue
   3.336 +	fi
   3.337 +	if test -n "$XENDOMAINS_MIGRATE"; then
   3.338 +	    echo -n "(migr)"
   3.339 +	    watchdog_xm migrate &
   3.340 +	    WDOG_PID=$!
   3.341 +	    xm migrate $id $XENDOMAINS_MIGRATE
   3.342 +	    if test $? -ne 0; then
   3.343 +		rc_failed $?
   3.344 +		echo -n '!'
   3.345 +		kill $WDOG_PID >/dev/null 2>&1
   3.346 +	    else
   3.347 +		kill $WDOG_PID >/dev/null 2>&1
   3.348 +		continue
   3.349 +	    fi
   3.350 +	fi
   3.351 +	if test -n "$XENDOMAINS_SAVE"; then
   3.352 +	    echo -n "(save)"
   3.353 +	    watchdog_xm save &
   3.354 +	    WDOG_PID=$!
   3.355 +	    xm save $id $XENDOMAINS_SAVE/$name
   3.356 +	    if test $? -ne 0; then
   3.357 +		rc_failed $?
   3.358 +		echo -n '!'
   3.359 +		kill $WDOG_PIG >/dev/null 2>&1
   3.360 +	    else
   3.361 +		kill $WDOG_PIG >/dev/null 2>&1
   3.362 +		continue
   3.363 +	    fi
   3.364 +	fi
   3.365 +	if test -n "$XENDOMAINS_SHUTDOWN"; then
   3.366 +	    # XENDOMAINS_SHUTDOWN should be "--halt --wait"
   3.367 +	    echo -n "(shut)"
   3.368 +	    watchdog_xm shutdown &
   3.369 +	    WDOG_PID=$!
   3.370 +	    xm shutdown $id $XENDOMAINS_SHUTDOWN
   3.371 +	    if test $? -ne 0; then
   3.372 +		rc_failed $?
   3.373 +		echo -n '!'
   3.374 +	    fi
   3.375 +	    kill $WDOG_PIG >/dev/null 2>&1
   3.376 +	fi
   3.377 +    done < <(xm list | grep -v '^Name')
   3.378 +
   3.379      # NB. this shuts down ALL Xen domains (politely), not just the ones in
   3.380      # AUTODIR/*
   3.381      # This is because it's easier to do ;-) but arguably if this script is run
   3.382      # on system shutdown then it's also the right thing to do.
   3.383 -    
   3.384 -    echo -n $"Shutting down all Xen domains:"
   3.385 +    if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
   3.386 +	# XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait"
   3.387 +	echo -n " SHUTDOWN_ALL "
   3.388 +	watchdog_xm shutdown 1 &
   3.389 +	WDOG_PID=$!
   3.390 +	xm shutdown $XENDOMAINS_SHUTDOWN_ALL
   3.391 +	if test $? -ne 0; then
   3.392 +	    rc_failed $?
   3.393 +	    echo -n '!'
   3.394 +	fi
   3.395 +	kill $WDOG_PID >/dev/null 2>&1
   3.396 +    fi
   3.397  
   3.398 -    xm shutdown --all --wait --halt
   3.399 +    # Unconditionally delete lock file
   3.400 +    rm -f $LOCKFILE
   3.401 +}
   3.402  
   3.403 -    RETVAL=$?
   3.404 +check_domain_up()
   3.405 +{
   3.406 +    while read LN; do
   3.407 +	parseln "$LN"
   3.408 +	if test $id = 0; then continue; fi
   3.409 +	case $name in 
   3.410 +	    ($1)
   3.411 +		return 0
   3.412 +		;;
   3.413 +	esac
   3.414 +    done < <(xm list | grep -v "^Name")
   3.415 +    return 1
   3.416 +}
   3.417  
   3.418 -    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
   3.419 +check_all_auto_domains_up()
   3.420 +{
   3.421 +    if test -z "$XENDOMAINS_AUTO" -o ! -d "$XENDOMAINS_AUTO" \
   3.422 +	    -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then return 0; fi
   3.423 +    missing=
   3.424 +    for nm in $XENDOMAINS_AUTO/*; do
   3.425 +	rdname $nm
   3.426 +	found=0
   3.427 +	if check_domain_up "$NM"; then 
   3.428 +	    echo -n " $name"
   3.429 +	else 
   3.430 +	    missing="$missing $NM"
   3.431 +	fi
   3.432 +    done
   3.433 +    if test -n "$missing"; then
   3.434 +	echo -n " MISS AUTO:$missing"
   3.435 +	return 1
   3.436 +    fi
   3.437 +    return 0
   3.438 +}
   3.439  
   3.440 -    on_fn_exit
   3.441 +check_all_saved_domains_up()
   3.442 +{
   3.443 +    if test -z "$XENDOMAINS_SAVE" -o ! -d "$XENDOMAINS_SAVE" \
   3.444 +	    -o `/bin/ls $XENDOMAINS_SAVE | wc -l` -eq 0; then return 0; fi
   3.445 +    missing=`/bin/ls $XENDOMAINS_SAVE`
   3.446 +    echo -n " MISS SAVED: " $missing
   3.447 +    return 1
   3.448  }
   3.449  
   3.450  # This does NOT necessarily restart all running domains: instead it
   3.451 @@ -124,47 +411,56 @@ stop()
   3.452  # AUTODIR.  If other domains have been started manually then they will
   3.453  # not get restarted.
   3.454  # Commented out to avoid confusion!
   3.455 -#
   3.456 -#restart()
   3.457 -#{
   3.458 -#    stop
   3.459 -#    start
   3.460 -#}
   3.461  
   3.462 -# same as restart for now - commented out to avoid confusion
   3.463 -#reload()
   3.464 -#{
   3.465 -#    restart
   3.466 -#}
   3.467 +restart()
   3.468 +{
   3.469 +    stop
   3.470 +    start
   3.471 +}
   3.472 +
   3.473 +reload()
   3.474 +{
   3.475 +    restart
   3.476 +}
   3.477  
   3.478  
   3.479  case "$1" in
   3.480      start)
   3.481  	start
   3.482 +	rc_status
   3.483 +	if test -f $LOCKFILE; then rc_status -v; fi
   3.484  	;;
   3.485  
   3.486      stop)
   3.487  	stop
   3.488 +	rc_status -v
   3.489 +	;;
   3.490 +
   3.491 +    restart)
   3.492 +	restart
   3.493 +	;;
   3.494 +    reload)
   3.495 +	reload
   3.496  	;;
   3.497  
   3.498 -# The following are commented out to disable them by default to avoid confusion
   3.499 -# - see the notes above
   3.500 -#
   3.501 -#    restart)
   3.502 -#	restart
   3.503 -#	;;
   3.504 -#
   3.505 -#    reload)
   3.506 -#	reload
   3.507 -#	;;
   3.508 -
   3.509      status)
   3.510 -	xm list
   3.511 +	echo -n "Checking for xendomains:" 
   3.512 +	if test ! -f $LOCKFILE; then 
   3.513 +	    rc_failed 3
   3.514 +	else
   3.515 +	    check_all_auto_domains_up
   3.516 +	    rc_status
   3.517 +	    check_all_saved_domains_up
   3.518 +	    rc_status
   3.519 +	fi
   3.520 +	rc_status -v
   3.521  	;;
   3.522  
   3.523      *)
   3.524 -	echo $"Usage: $0 {start|stop|status}"
   3.525 +	echo "Usage: $0 {start|stop|restart|reload|status}"
   3.526 +	rc_failed 3
   3.527 +	rc_status -v
   3.528  	;;
   3.529  esac
   3.530  
   3.531 -exit $RETVAL
   3.532 +rc_exit