[Pkg-xen-changes] r984 - trunk/xen/debian

Bastian Blank waldi at alioth.debian.org
Sun Apr 22 18:36:01 UTC 2012


Author: waldi
Date: Sun Apr 22 18:36:01 2012
New Revision: 984

Log:
debian/xen-utils-common.xendomains.init:
Replace with current upstream version. It it broken.

Modified:
   trunk/xen/debian/xen-utils-common.xendomains.init

Modified: trunk/xen/debian/xen-utils-common.xendomains.init
==============================================================================
--- trunk/xen/debian/xen-utils-common.xendomains.init	Thu Apr 19 08:54:54 2012	(r983)
+++ trunk/xen/debian/xen-utils-common.xendomains.init	Sun Apr 22 18:36:01 2012	(r984)
@@ -1,28 +1,46 @@
 #!/bin/bash
 ### BEGIN INIT INFO
 # Provides:          xendomains
-# Required-Start:    $syslog $remote_fs xend
-# Should-Start:
-# Required-Stop:     $syslog $remote_fs xend
-# Should-Stop:
+# Required-Start:    $syslog $remote_fs xen
+# Required-Stop:     $syslog $remote_fs xen
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: Start/stop secondary xen domains
 # Description:       Start / stop domains automatically when domain 0 
 #                    boots / shuts down.
 ### END INIT INFO
-# Default-Enabled:   yes
 
-PATH=/usr/lib/xen-common/bin:/sbin:/bin:/usr/sbin:/usr/bin
-VERSION=$(xen-version)
-ROOT=/usr/lib/xen-$VERSION
-
-test "$VERSION" || exit 0
-test -e /proc/xen/privcmd || exit 0
-grep -q "control_d" /proc/xen/capabilities || exit 0
+CMD=xm
+$CMD list &> /dev/null
+if test $? -ne 0
+then
+	CMD=xl
+fi
+
+$CMD list &> /dev/null
+if test $? -ne 0
+then
+	exit 0;
+fi
+
+# Correct exit code would probably be 5, but it's enough 
+# if xend complains if we're not running as privileged domain
+if ! [ -e /proc/xen/privcmd ]; then
+	exit 0
+fi
+
+# See docs/misc/distro_mapping.txt
+if [ -d /var/lock/subsys ]; then
+	LOCKFILE=/var/lock/subsys/xendomains
+else
+	LOCKFILE=/var/lock/xendomains
+fi
 
-LOCKFILE=/var/lock/xendomains
-XENDOM_CONFIG=/etc/default/xendomains
+if [ -d /etc/sysconfig ]; then
+	XENDOM_CONFIG=/etc/sysconfig/xendomains
+else
+	XENDOM_CONFIG=/etc/default/xendomains
+fi
 
 test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
 	if [ "$1" = "stop" ]; then exit 0;
@@ -30,49 +48,90 @@
 
 . $XENDOM_CONFIG
 
-_cmd=$1
-declare -a _SMSG
-if test "${_cmd}" = "status"; then
-    _SMSG=(running dead dead unused unknown)
-    _RC_UNUSED=3
-else
-    _SMSG=(done failed failed missed failed skipped unused failed failed)
-    _RC_UNUSED=6
-fi
-. /lib/lsb/init-functions
-echo_rc()
-{
-    if test ${_RC_RV} = 0; then
-	log_success_msg "  [${_SMSG[${_RC_RV}]}] "
+# Use the SUSE rc_ init script functions;
+# emulate them on LSB, RH and other systems
+if test -e /etc/rc.status; then
+    # SUSE rc script library
+    . /etc/rc.status
+else    
+    _cmd=$1
+    declare -a _SMSG
+    if test "${_cmd}" = "status"; then
+	_SMSG=(running dead dead unused unknown)
+	_RC_UNUSED=3
     else
-	log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
+	_SMSG=(done failed failed missed failed skipped unused failed failed)
+	_RC_UNUSED=6
     fi
-}
-rc_reset() { _RC_RV=0; }
-rc_failed()
-{
-    if test -z "$1"; then 
-	_RC_RV=1;
-    elif test "$1" != "0"; then 
-	_RC_RV=$1; 
-    fi
-    return ${_RC_RV}
-}
-rc_check()
-{
-    return rc_failed $?
-}	
-rc_status()
-{
-    rc_failed $?
-    if test "$1" = "-r"; then _RC_RV=0; shift; fi
-    if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
-    if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
-    if test "$1" = "-v"; then echo_rc; shift; fi
-    if test "$1" = "-r"; then _RC_RV=0; shift; fi
-    return ${_RC_RV}
-}
-rc_exit() { exit ${_RC_RV}; }
+    if test -e /etc/init.d/functions; then
+	# REDHAT
+	. /etc/init.d/functions
+	echo_rc()
+	{
+	    #echo -n "  [${_SMSG[${_RC_RV}]}] "
+	    if test ${_RC_RV} = 0; then
+		success "  [${_SMSG[${_RC_RV}]}] "
+	    else
+		failure "  [${_SMSG[${_RC_RV}]}] "
+	    fi
+	}
+    elif test -e /lib/lsb/init-functions; then
+	# LSB    
+    	. /lib/lsb/init-functions
+        if alias log_success_msg >/dev/null 2>/dev/null; then
+	  echo_rc()
+	  {
+	       echo "  [${_SMSG[${_RC_RV}]}] "
+	  }
+        else
+	  echo_rc()
+	  {
+	    if test ${_RC_RV} = 0; then
+		log_success_msg "  [${_SMSG[${_RC_RV}]}] "
+	    else
+		log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
+	    fi
+	  }
+        fi
+    else    
+	# emulate it
+	echo_rc()
+	{
+	    echo "  [${_SMSG[${_RC_RV}]}] "
+	}
+    fi
+    rc_reset() { _RC_RV=0; }
+    rc_failed()
+    {
+	if test -z "$1"; then 
+	    _RC_RV=1;
+	elif test "$1" != "0"; then 
+	    _RC_RV=$1; 
+    	fi
+	return ${_RC_RV}
+    }
+    rc_check()
+    {
+	return rc_failed $?
+    }	
+    rc_status()
+    {
+	rc_failed $?
+	if test "$1" = "-r"; then _RC_RV=0; shift; fi
+	if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
+	if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
+	if test "$1" = "-v"; then echo_rc; shift; fi
+	if test "$1" = "-r"; then _RC_RV=0; shift; fi
+	return ${_RC_RV}
+    }
+    rc_exit() { exit ${_RC_RV}; }
+    rc_active() 
+    {
+	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
+	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
+	return 1
+    }
+fi
 
 if ! which usleep >&/dev/null
 then
@@ -105,7 +164,7 @@
 # read name from xen config file
 rdname()
 {
-    NM=$(xm create --quiet --dryrun --defconfig "$1" |
+    NM=$($CMD create --quiet --dryrun --defconfig "$1" |
          sed -n 's/^.*(name \(.*\))$/\1/p')
 }
 
@@ -126,55 +185,75 @@
     done
 }
 
+LIST_GREP='((domain\|(domid\|(name\|^{$\|"name":\|"domid":'
 parseln()
 {
-    name=`echo $1 | cut -d\  -f1`
-    name=${name%% *}
-    rest=`echo $1 | cut -d\  -f2-`
-    read id mem cpu vcpu state tm < <(echo "$rest")
+    if [[ "$1" =~ '(domain' ]] || [[ "$1" = "{" ]]; then
+        name=;id=
+    elif [[ "$1" =~ '(name' ]]; then
+        name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/')
+    elif [[ "$1" =~ '(domid' ]]; then
+        id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/')
+    elif [[ "$1" =~ '"name":' ]]; then
+        name=$(echo $1 | sed -e 's/^.*"name": "\(.*\)",$/\1/')
+    elif [[ "$1" =~ '"domid":' ]]; then
+        id=$(echo $1 | sed -e 's/^.*"domid": \(.*\),$/\1/')
+    fi
+
+    [ -n "$name" -a -n "$id" ] && return 0 || return 1
 }
 
 is_running()
 {
     rdname $1
     RC=1
+    name=;id=
     while read LN; do
-	parseln "$LN"
+	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
 	case $name in 
 	    ($NM)
 		RC=0
 		;;
 	esac
-    done < <(xm list | tail -n +2)
+    done < <($CMD list -l | grep $LIST_GREP)
     return $RC
 }
 
 start() 
 {
     if [ -f $LOCKFILE ]; then 
-	echo -n "xendomains already running (lockfile exists)"
+	echo -e "xendomains already running (lockfile exists)"
 	return; 
     fi
 
+    saved_domains=" "
     if [ "$XENDOMAINS_RESTORE" = "true" ] &&
        contains_something "$XENDOMAINS_SAVE"
     then
-        mkdir -p $(dirname "$LOCKFILE")
+	mkdir -p $(dirname "$LOCKFILE")
 	touch $LOCKFILE
 	echo -n "Restoring Xen domains:"
-	for dom in $XENDOMAINS_SAVE/*; do
-	    echo -n " ${dom##*/}"
-	    xm restore $dom
-	    if [ $? -ne 0 ]; then
-		rc_failed $?
-		echo -n '!'
-	    else
-		# mv $dom ${dom%/*}/.${dom##*/}
-		rm $dom
-	    fi
-	done
-	echo .
+	saved_domains=`ls $XENDOMAINS_SAVE`
+        for dom in $XENDOMAINS_SAVE/*; do
+            if [ -f $dom ] ; then
+                HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
+                if [ $HEADER = "LinuxGuestRecord" ]; then
+                    echo -n " ${dom##*/}"
+                    XMR=`$CMD restore $dom 2>&1 1>/dev/null`
+                    #$CMD restore $dom
+                    if [ $? -ne 0 ]; then
+                        echo -e "\nAn error occurred while restoring domain ${dom##*/}:\n$XMR"
+                        rc_failed $?
+                        echo -e '!'
+                    else
+                        # mv $dom ${dom%/*}/.${dom##*/}
+                        rm $dom
+                    fi
+                fi
+            fi
+        done
+	echo -e
     fi
 
     if contains_something "$XENDOMAINS_AUTO"
@@ -187,81 +266,98 @@
 	# Create all domains with config files in XENDOMAINS_AUTO.
 	# TODO: We should record which domain name belongs 
 	# so we have the option to selectively shut down / migrate later
+	# If a domain statefile from $XENDOMAINS_SAVE matches a domain name
+	# in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't 
+	# restore correctly it requires administrative attention.
 	for dom in $XENDOMAINS_AUTO/*; do
 	    echo -n " ${dom##*/}"
-	    if is_running $dom; then
+	    shortdom=$(echo $dom | sed -n 's/^.*\/\(.*\)$/\1/p')
+	    echo $saved_domains | grep -w $shortdom > /dev/null
+	    if [ $? -eq 0 ] || is_running $dom; then
 		echo -n "(skip)"
 	    else
-		xm create --quiet --defconfig $dom
+		XMC=`$CMD create --quiet --defconfig $dom`
 		if [ $? -ne 0 ]; then
+		    echo -e "\nAn error occurred while creating domain ${dom##*/}: $XMC\n"
 		    rc_failed $?
-		    echo -n '!'
+		    echo -e '!'
 		else
 		    usleep $XENDOMAINS_CREATE_USLEEP
 		fi
 	    fi
 	done
-    fi	
+    fi
 }
 
 all_zombies()
 {
+    name=;id=
     while read LN; do
-	parseln "$LN"
+	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
 	if test "$state" != "-b---d" -a "$state" != "-----d"; then
 	    return 1;
 	fi
-    done < <(xm list | tail -n +2)
+    done < <($CMD list -l | grep $LIST_GREP)
     return 0
 }
 
-# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish;
+# Wait for max $XENDOMAINS_STOP_MAXWAIT for $CMD $1 to finish;
 # if it has not exited by that time kill it, so the init script will
 # succeed within a finite amount of time; if $2 is nonnull, it will
 # kill the command as well as soon as no domain (except for zombies)
-# are left (used for shutdown --all).
-watchdog_xm()
+# are left (used for shutdown --all). Third parameter, if any, suppresses
+# output of dots per working state (formatting issues)
+watchdog_xencmd()
 {
     if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
 	exit
     fi
+
     usleep 20000
     for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
-	# exit if xm save/migrate/shutdown is finished
-	PSAX=`ps axlw | grep "xm $1" | grep -v grep`
+	# exit if $CMD save/migrate/shutdown is finished
+	PSAX=`ps axlw | grep "$CMD $1" | grep -v grep`
 	if test -z "$PSAX"; then exit; fi
-	echo -n "."; sleep 1
+	if ! test -n "$3"; then echo -n '.'; fi
+	sleep 1
 	# go to kill immediately if there's only zombies left
 	if all_zombies && test -n "$2"; then break; fi
     done
     sleep 1
     read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
-    # kill xm $1
+    # kill $CMD $1
     kill $PSPID >/dev/null 2>&1
+    
+    echo -e .
 }
 
 stop()
 {
+    exec 3>&2 2> /dev/null
+    
     # Collect list of domains to shut down
     if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
 	rdnames
     fi
     echo -n "Shutting down Xen domains:"
+    name=;id=
     while read LN; do
-	parseln "$LN"
+	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
 	echo -n " $name"
 	if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
-	    case $name in
+	    eval "
+	    case \"\$name\" in
 		($NAMES)
 		    # nothing
 		    ;;
 		(*)
-		    echo -n "(skip)"
+		    echo -e '(skip)'
 		    continue
 		    ;;
 	    esac
+	    "
 	fi
 	# XENDOMAINS_SYSRQ chould be something like just "s" 
 	# or "s e i u" or even "s e s i u o"
@@ -269,8 +365,9 @@
 	if test -n "$XENDOMAINS_SYSRQ"; then
 	    for sysrq in $XENDOMAINS_SYSRQ; do
 		echo -n "(SR-$sysrq)"
-		xm sysrq $id $sysrq
+		XMR=`$CMD sysrq $id $sysrq 2>&1 1>/dev/null`
 		if test $? -ne 0; then
+		    echo -e "\nAn error occurred while doing sysrq on domain:\n$XMR\n"
 		    rc_failed $?
 		    echo -n '!'
 		fi
@@ -284,46 +381,55 @@
 	fi
 	if test -n "$XENDOMAINS_MIGRATE"; then
 	    echo -n "(migr)"
-	    watchdog_xm migrate &
+	    watchdog_xencmd migrate &
 	    WDOG_PID=$!
-	    xm migrate $id $XENDOMAINS_MIGRATE
+	    XMR=`$CMD migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
 	    if test $? -ne 0; then
+		echo -e "\nAn error occurred while migrating domain:\n$XMR\n"
 		rc_failed $?
-		echo -n '!'
+		echo -e '!'
+
 		kill $WDOG_PID >/dev/null 2>&1
 	    else
 		kill $WDOG_PID >/dev/null 2>&1
+		
+		echo -e .
+		usleep 1000
 		continue
 	    fi
 	fi
 	if test -n "$XENDOMAINS_SAVE"; then
 	    echo -n "(save)"
-	    watchdog_xm save &
+	    watchdog_xencmd save &
 	    WDOG_PID=$!
 	    mkdir -p "$XENDOMAINS_SAVE"
-	    xm save $id $XENDOMAINS_SAVE/$name
+	    XMR=`$CMD save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
 	    if test $? -ne 0; then
+		echo -e "\nAn error occurred while saving domain:\n$XMR\n"
 		rc_failed $?
-		echo -n '!'
+		echo -e '!'
 		kill $WDOG_PID >/dev/null 2>&1
 	    else
 		kill $WDOG_PID >/dev/null 2>&1
+		echo -e .
+		usleep 1000
 		continue
 	    fi
 	fi
 	if test -n "$XENDOMAINS_SHUTDOWN"; then
 	    # XENDOMAINS_SHUTDOWN should be "--halt --wait"
 	    echo -n "(shut)"
-	    watchdog_xm shutdown &
+	    watchdog_xencmd shutdown &
 	    WDOG_PID=$!
-	    xm shutdown $id $XENDOMAINS_SHUTDOWN
+	    XMR=`$CMD shutdown $id $XENDOMAINS_SHUTDOWN 2>&1 1>/dev/null`
 	    if test $? -ne 0; then
+		echo -e "\nAn error occurred while shutting down domain:\n$XMR\n"
 		rc_failed $?
-		echo -n '!'
+		echo -e '!'
 	    fi
 	    kill $WDOG_PID >/dev/null 2>&1
 	fi
-    done < <(xm list | tail -n +2)
+    done < <($CMD list -l | grep $LIST_GREP)
 
     # NB. this shuts down ALL Xen domains (politely), not just the ones in
     # AUTODIR/*
@@ -332,31 +438,35 @@
     if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
 	# XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait"
 	echo -n " SHUTDOWN_ALL "
-	watchdog_xm shutdown 1 &
+	watchdog_xencmd shutdown 1 false &
 	WDOG_PID=$!
-	xm shutdown $XENDOMAINS_SHUTDOWN_ALL
+	XMR=`$CMD shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
 	if test $? -ne 0; then
+	    echo -e "\nAn error occurred while shutting down all domains: $XMR\n"
 	    rc_failed $?
-	    echo -n '!'
+	    echo -e '!'
 	fi
 	kill $WDOG_PID >/dev/null 2>&1
     fi
 
     # Unconditionally delete lock file
     rm -f $LOCKFILE
+    
+    exec 2>&3
 }
 
 check_domain_up()
 {
+    name=;id=
     while read LN; do
-	parseln "$LN"
+	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
 	case $name in 
 	    ($1)
 		return 0
 		;;
 	esac
-    done < <(xm list | tail -n +2)
+    done < <($CMD list -l | grep $LIST_GREP)
     return 1
 }
 
@@ -427,7 +537,7 @@
     restart)
 	restart
 	;;
-    force-reload|reload)
+    reload|force-reload)
 	reload
 	;;
 



More information about the Pkg-xen-changes mailing list