From mboxrd@z Thu Jan 1 00:00:00 1970 From: lhh@sourceware.org Date: 12 Jul 2006 15:43:57 -0000 Subject: [Cluster-devel] cluster/rgmanager/src/resources Makefile xenvm.sh Message-ID: <20060712154357.2056.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: lhh at sourceware.org 2006-07-12 15:43:56 Modified files: rgmanager/src/resources: Makefile Added files: rgmanager/src/resources: xenvm.sh Log message: Add missing xenvm.sh resource Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/xenvm.sh.diff?cvsroot=cluster&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/Makefile.diff?cvsroot=cluster&r1=1.11&r2=1.12 /cvs/cluster/cluster/rgmanager/src/resources/xenvm.sh,v --> standard output revision 1.1 --- cluster/rgmanager/src/resources/xenvm.sh +++ - 2006-07-12 15:43:57.727243000 +0000 @@ -0,0 +1,432 @@ +#!/bin/bash + +PATH=/bin:/sbin:/usr/bin:/usr/sbin + +export PATH + +# +# Xen para VM start/stop script. +# + +meta_data() +{ + cat < + + 1.0 + + + Defines a Xen Para-Virtual Machine + + + Defines a Xen domain. + + + + + + This is the name of the Xen domain. + + + Name + + + + + + + Fail over domains define lists of cluster members + to try in the event that the host of the Xen domain + fails. + + + Cluster Fail Over Domain + + + + + + + If set to yes, this resource group will automatically be started + after the cluster forms a quorum. If set to no, this resource + group will start in the 'disabled' state after the cluster forms + a quorum. + + + Automatic start after quorum formation + + + + + + + This currently has three possible options: "restart" tries + to restart failed parts of this resource group locally before + attempting to relocate (default); "relocate" does not bother + trying to restart the service locally; "disable" disables + the resource group if any component fails. Note that + any resource with a valid "recover" operation which can be + recovered without a restart will be. + + + Failure recovery policy + + + + + + + Memory size. This can be reconfigured on the fly. + + + Memory Size + + + + + + + Root disk for the Xen VM (as presented to the VM) + + + Boot loader that can start the Xen VM from physical image + + + + + + + root disk for the Xen VM. (physical, on the host) + + + root disk for the Xen VM. (physical, on the host) + + + + + + + rootdisk for the Xen VM. (as presented to the VM) + + + rootdisk for the Xen VM. (as presented to the VM) + + + + + + + + Swap disk for the Xen VM. (physical, on the host) + + + Swap disk for the Xen VM. (physical, on the host) + + + + + + + Swap disk for the Xen VM. (as presented to the VM) + + + Swap disk for the Xen VM. (as presented to the VM) + + + + + + + Virtual interface MAC address + + + Virtual interface MAC address + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +EOT +} + + +# +# Find a list of possible IP addresses to try. +# +xen_host_ips() +{ + declare xen_ips=$(ip -f inet -o addr list | grep 'xen-br[0-9]\+[^:]' | awk '{print $4}') + declare tmp1="" + declare i + + for i in $xen_ips; do + i=${i/\/*/} + if [ -z "$tmp1" ]; then + tmp1="$i" + else + tmp1="$i,$tmp1" + fi + done + + echo $tmp1 +} + + +build_xen_cmdline() +{ + # + # Virtual domains should never restart themselves when + # controlled externally; the external monitoring app + # should. + # + declare cmdline="restart=\"never\"" + declare varp val temp + + + # + # Transliterate the OCF_RESKEY_* to something the xm + # command can recognize. + # + for var in ${!OCF_RESKEY_*}; do + varp=${var/OCF_RESKEY_/} + val=`eval "echo \\$$var"` + + case $varp in + bootloader) + cmdline="$cmdline bootloader=\"$val\"" + ;; + rootdisk_physical) + [ -n "$OCF_RESKEY_rootdisk_virtual" ] || exit 2 + cmdline="$cmdline disk=\"phy:$val,$OCF_RESKEY_rootdisk_virtual,w\"" + ;; + swapdisk_physical) + [ -n "$OCF_RESKEY_swapdisk_virtual" ] || exit 2 + cmdline="$cmdline disk=\"phy:$val,$OCF_RESKEY_swapdisk_virtual,w\"" + ;; + vif) + cmdline="$cmdline vif=\"mac=$val\"" + ;; + recovery|autostart|domain) + ;; + memory) + cmdline="$cmdline $varp=$val" + ;; + swapdisk_virtual) + ;; + rootdisk_virtual) + ;; + *) + cmdline="$cmdline $varp=\"$val\"" + ;; + esac + done + + echo $cmdline +} + + +# +# Start a Xen para-virtual machine given the parameters from +# the environment. +# +start() +{ + # Use /dev/null for the configuration file, if xmdefconfig + # doesn't exist... + # + declare cmdline + + if [ -f "/etc/xen/xmdefconfig" ]; then + cmdline="`build_xen_cmdline`" + else + cmdline="`build_xen_cmdline` /dev/null" + fi + + echo $cmdline + + eval xm create $cmdline + return $? +} + + +# +# Stop a Xen VM. Try to shut it down. Wait a bit, and if it +# doesn't shut down, destroy it. +# +stop() +{ + declare -i timeout=120 + declare -i ret=1 + declare st + + for op in $*; do + echo xm $op $OCF_RESKEY_name ... + xm $op $OCF_RESKEY_name + + timeout=120 + while [ $timeout -gt 0 ]; do + sleep 5 + ((timeout -= 5)) + status || return 0 + while read dom state; do + # + # State is "stopped". Kill it. + # + if [ "$dom" != "$OCF_RESKEY_name" ]; then + continue + fi + if [ "$state" != "---s-" ]; then + continue + fi + xm destroy $OCF_RESKEY_name + done < <(xm list | awk '{print $1, $5}') + done + done + + return 1 +} + + +# +# Reconfigure a running Xen VM. Currently, all we support is +# memory ballooning. +# +reconfigure() +{ + if [ -n "$OCF_RESKEY_memory" ]; then + echo "xm balloon $OCF_RESKEY_name $OCF_RESKEY_memory" + xm balloon $OCF_RESKEY_name $OCF_RESKEY_memory + return $? + fi + return 0 +} + + +# +# Simple status check: Find the Xen VM in the list of running +# VMs +# +status() +{ + xm list $OCF_RESKEY_name &> /dev/null + return $? +} + + +verify_all() +{ + declare errors=0 + declare tmp1, tmp2 + + if [ -z "$OCF_RESKEY_kernel" ]; then + echo "Required parameter OCF_RESKEY_kernel is not present" + ((errors++)) + elif ! [ -f "$OCF_RESKEY_kernel" ]; then + echo "$OCF_RESKEY_kernel (OCF_RESKEY_kernel) is not valid" + ((errors++)) + fi + + tmp1=`echo $OCF_RESKEY_swapdisk | cut -f1 -d,` + tmp2=`echo $OCF_RESKEY_swapdisk | cut -f2 -d,` + + if [ -z "$tmp2" ]; then + echo "Swapdisk option malformed" + ((errors++)) + fi + + if ! [ -b "$tmp1" ]; then + echo "Specified swapdisk device $tmp1 is not a block device" + ((errors++)) + fi + + if [ -z "$OCF_RESKEY_rootdisk" ]; then + echo "Required parameter OCF_RESKEY_rootdisk is not present" + ((errors++)) + else + tmp1=`echo $OCF_RESKEY_rootdisk | cut -f1 -d,` + tmp2=`echo $OCF_RESKEY_rootdisk | cut -f2 -d,` + + if [ -z "$tmp2" ]; then + echo "Rootdisk option malformed" + ((errors++)) + fi + + if ! [ -b "$tmp1" ]; then + echo "Specified rootdisk device $tmp1 is not a block device" + ((errors++)) + fi + fi +} + +# +# A Resource group is abstract, but the OCF RA API doesn't allow for abstract +# resources, so here it is. +# +case $1 in + start) + start + exit $? + ;; + stop) + stop shutdown destroy + exit $? + ;; + kill) + stop destroy + exit $? + ;; + recover|restart) + exit 0 + ;; + status|monitor) + status + exit $? + ;; + reload) + exit 0 + ;; + reconfig) + echo "$0 RECONFIGURING $OCF_RESKEY_memory" + reconfigure + exit $? + ;; + meta-data) + meta_data + exit 0 + ;; + verify-all) + verify_all + exit $? + ;; + *) + echo "usage: $0 {start|stop|restart|status|reload|reconfig|meta-data|verify-all}" + exit 1 + ;; +esac --- cluster/rgmanager/src/resources/Makefile 2006/06/02 17:37:10 1.11 +++ cluster/rgmanager/src/resources/Makefile 2006/07/12 15:43:56 1.12 @@ -18,7 +18,7 @@ INCLUDE += -I $(top_srcdir)/include RESOURCES=fs.sh service.sh ip.sh nfsclient.sh nfsexport.sh \ - script.sh netfs.sh clusterfs.sh smb.sh + script.sh netfs.sh clusterfs.sh smb.sh xenvm.sh TARGETS=${RESOURCES} ocf-shellfuncs svclib_nfslock