[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-users] "vmid-based VMs" xendomains script addition



See attached xendomains init script and the comments and a
pseudocode representation of the logic added (below).

This is not endorsed in any way by the Xen team.  It's
something I wanted and I can see others wanting it as
well...maybe.

...
AUTODIR_VMIDBASED=/etc/xen/auto-vmid
VMIDBASED_CONFIG=/etc/xen/auto-vmid/vmid-based.cfg
...
    # If configured for it, create the "vmid-based" VMs.  This
    # logic is based on the idea that you have a single master
    # controller configuration file with code in it to make use
    # of a passed-in VM identifier (like /etc/xen/xmexample2 in
    # the Xen distribution).  It expects the configuration file
    # to be set at the top of this script as VMIDBASED_CONFIG
    # and will loop over everything in AUTODIR_VMIDBASED and try
    # to pass each filename to 'xm create...blah...vmid=THATFILENAME".
    # For example, to enable my 3 VMs, I have my config file in
    # the proper place and my 3 separate VM OS images already
    # configured -- then I run "touch 1 2 3" and from there on out
    # the code below will create the VMs every time this script
    # runs.

    if AUTODIR_VMIDBASED directory exists and has more than 1 file
        if VMIDBASED_CONFIG file exists
            for every "filename" in AUTODIR_VMIDBASED
                if filename is same as VMIDBASED_CONFIG
                    skip over it
                else
                    xm create ... VMIDBASED_CONFIG vmid=filename
                endif
            end-of-for-loop
        endif
    endif
...
#!/bin/sh
#
# /etc/init.d/xendomains
# Start / stop domains automatically when domain 0 boots / shuts down.
#
# chkconfig: 345 99 00
# description: Start / stop Xen domains.
#
# This script offers fairly basic functionality.  It should work on Redhat
# but also on LSB-compliant SuSE releases and on Debian with the LSB package
# installed.  (LSB is the Linux Standard Base)
#
# Based on the example in the "Designing High Quality Integrated Linux
# Applications HOWTO" by Avi Alkalay
# <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/>
#

RETVAL=0

INITD=/etc/init.d

AUTODIR=/etc/xen/auto
# Full path required
AUTODIR_VMIDBASED=/etc/xen/auto-vmid
# Full path required
VMIDBASED_CONFIG=/etc/xen/auto-vmid/vmid-based.cfg
LOCKFILE=/var/lock/subsys/xendomains

if [ -e /lib/lsb ]; then
    # assume an LSB-compliant distro (Debian with LSB package,
    # recent-enough SuSE, others...)

    . /lib/lsb/init-functions # source LSB standard functions

    on_fn_exit()
    {
        if [ $RETVAL -eq 0 ]; then
            log_success_msg
        else
            log_failure_msg
        fi
    }
elif [ -r $INITD/functions ]; then
    # assume a Redhat-like distro
    . $INITD/functions # source Redhat functions

    on_fn_exit()
    {
        if [ $RETVAL -eq 0 ]; then
            success
        else
            failure
        fi
        
        echo
    }
else
    # none of the above
    LOCKFILE=/var/lock/xendomains

    on_fn_exit()
    {
        echo
    }
fi



start() {
    if [ -f $LOCKFILE ]; then return; fi

    echo -n $"Starting auto Xen domains:"

    # We expect config scripts for auto starting domains to be in
    # AUTODIR - they could just be symlinks to files elsewhere
    if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then
        touch $LOCKFILE
        
       # Create all domains with config files in AUTODIR.
        for dom in  $AUTODIR/*; do
            xm create --quiet --defconfig $dom
            if [ $? -ne 0 ]; then
                RETVAL=$?
            fi
        done

    fi

    # If configured for it, create the "vmid-based" VMs.  This
    # logic is based on the idea that you have a single master
    # controller configuration file with code in it to make use
    # of a passed-in VM identifier (like /etc/xen/xmexample2 in
    # the Xen distribution).  It expects the configuration file
    # to be set at the top of this script as VMIDBASED_CONFIG
    # and will loop over everything in AUTODIR_VMIDBASED and try
    # to pass each filename to 'xm create...blah...vmid=THATFILENAM".
    # For example, to enable my 3 VMs, I have my config file in
    # the proper place and my 3 separate VM OS images already
    # configured -- then I run "touch 1 2 3" and from there on out
    # the code below will create the VMs every time this script
    # runs.
    if [ -d $AUTODIR_VMIDBASED ] && [ $(ls $AUTODIR_VMIDBASED | wc -l) -gt 1 ]; 
then
        if [ -f $VMIDBASED_CONFIG ]; then
            for dom in $AUTODIR_VMIDBASED/*; do
                if [ "$dom" = "$VMIDBASED_CONFIG" ]; then
                    # Skip the config file itself
                    continue
                fi
                VMID=`basename $dom`
                xm create --quiet --defconfig $VMIDBASED_CONFIG vmid=$VMID
                if [ $? -ne 0 ]; then
                    RETVAL=$?
                fi
            done
        fi
    fi

    on_fn_exit
}

stop()
{
    # NB. this shuts down ALL Xen domains (politely), not just the ones in
    # AUTODIR/*
    # This is because it's easier to do ;-) but arguably if this script is run
    # on system shutdown then it's also the right thing to do.
    
    echo -n $"Shutting down all Xen domains:"

    xm shutdown --all --wait --halt

    RETVAL=$?

    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE

    on_fn_exit
}

# This does NOT necessarily restart all running domains: instead it
# stops all running domains and then boots all the domains specified in
# AUTODIR.  If other domains have been started manually then they will
# not get restarted.
# Commented out to avoid confusion!
#
#restart()
#{
#    stop
#    start
#}

# same as restart for now - commented out to avoid confusion
#reload()
#{
#    restart
#}


case "$1" in
    start)
        start
        ;;

    stop)
        stop
        ;;

# The following are commented out to disable them by default to avoid confusion
# - see the notes above
#
#    restart)
#       restart
#       ;;
#
#    reload)
#       reload
#       ;;

    status)
        xm list
        ;;

    *)
        echo $"Usage: $0 {start|stop|status}"
        ;;
esac

exit $RETVAL
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.