Author: waldi Date: Sun Apr 22 20:57:39 2012 New Revision: 989 Log: debian/xen-utils-common.xendomains.init: Replace start code. 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 Sun Apr 22 20:36:09 2012 (r988) +++ trunk/xen/debian/xen-utils-common.xendomains.init Sun Apr 22 20:57:39 2012 (r989) @@ -34,6 +34,8 @@ . $XENDOM_CONFIG +shopt -s nullglob + echo_rc() { if test ${_RC_RV} = 0; then @@ -127,89 +129,6 @@ done } -is_running() -{ - rdname $1 - RC=1 - while read id name rest; do - case $name in - ($NM) - RC=0 - ;; - esac - done < <(/usr/lib/xen-common/bin/xen-init-list) - return $RC -} - -start() -{ - if [ -f $LOCKFILE ]; then - echo -e "xendomains already running (lockfile exists)" - return; - fi - - saved_domains=" " - if [ "$XENDOMAINS_RESTORE" = "true" ] && - contains_something "$XENDOMAINS_SAVE" - then - mkdir -p $(dirname "$LOCKFILE") - touch $LOCKFILE - echo -n "Restoring Xen domains:" - 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=`xen 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" - then - touch $LOCKFILE - echo -n "Starting auto Xen domains:" - # We expect config scripts for auto starting domains to be in - # XENDOMAINS_AUTO - they could just be symlinks to files elsewhere - - # 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##*/}" - 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 - XMC=`xen create --quiet --defconfig $dom` - if [ $? -ne 0 ]; then - echo -e "\nAn error occurred while creating domain ${dom##*/}: $XMC\n" - rc_failed $? - echo -e ''!'' - else - usleep $XENDOMAINS_CREATE_USLEEP - fi - fi - done - fi -} - all_zombies() { while read id name rest; do @@ -220,6 +139,12 @@ return 0 } +check_running() +{ + xen domid "$1" > /dev/null 2>&1 + return $? +} + coproc_timeout() { TIMEOUT="$1" @@ -233,6 +158,59 @@ return 1 } +do_start_restore() +{ + for file in $XENDOMAINS_SAVE/*; do + if [ -f $file ] ; then + HEADER=$(head -c 16 "$file" | head -n 1 2> /dev/null) + if [ $HEADER = "LinuxGuestRecord" ]; then + name="${file##*/}" + log_action_begin_msg "Restoring Xen domain $name" + + out=$(xen restore "$file" 2>&1 1>/dev/null) + case "$?" in + 0) + rm "$file" + log_action_end_msg 0 + ;; + *) + log_action_end_msg 1 + ;; + esac + fi + fi + done +} + +do_start_auto() +{ + for file in $XENDOMAINS_AUTO/*; do + rdname "$file" + name="$NM" + log_action_begin_msg "Starting Xen domain $name ($file)" + + if check_running "$name"; then + log_action_end_msg 0 "already running" + else + out=$(xen create --quiet --defconfig "$file" 2>&1 1>/dev/null) + log_action_end_msg $? + fi + done +} + +do_start() +{ + if [ -f $LOCKFILE ]; then + echo -e "xendomains already running (lockfile exists)" + return; + fi + mkdir -p $(dirname "$LOCKFILE") + touch $LOCKFILE + + do_start_restore + do_start_auto +} + do_stop_migrate() { while read id name rest; do @@ -328,7 +306,7 @@ restart() { do_stop - start + do_start } reload() @@ -339,7 +317,7 @@ case "$1" in start) - start + do_start rc_status if test -f $LOCKFILE; then rc_status -v; fi ;;