From: Martin Lucina Date: Fri, 14 Nov 2014 12:40:09 +0000 (+0100) Subject: xr: Rename to rumprun-xen X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=4ec432c654bd0935ea8cff525aac98c104765dcd;p=rumpuser-xen.git xr: Rename to rumprun-xen Rename the "xr" driver script to "rumprun-xen" to better reflect it's purpose and scope. Signed-off-by: Martin Lucina --- diff --git a/app-tools/rumprun-xen b/app-tools/rumprun-xen new file mode 100755 index 0000000..bb36bb2 --- /dev/null +++ b/app-tools/rumprun-xen @@ -0,0 +1,237 @@ +#!/bin/sh +# +# Copyright (c) 2014 Martin Lucina. All Rights Reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# +# rumprun-xen: "driver" script for running rumprun-xen application stacks +# + +err() { + echo rumprun-xen: error: "$@" 1>&2 + exit 1 +} + +usage() { + cat <>${xenstore} + echo net/${nindex}/method dhcp >>${xenstore} + ;; + static) + ifaddr=${3%/*} + ifmask=$(cidr2mask ${3#*/}) + ifgw=$4 + echo net/${nindex}/type inet >>${xenstore} + echo net/${nindex}/method static >>${xenstore} + echo net/${nindex}/addr ${ifaddr} >>${xenstore} + echo net/${nindex}/netmask ${ifmask} >>${xenstore} + [ -n "${ifgw}" ] && + echo net/${nindex}/gw ${ifgw} >>${xenstore} + ;; + *) + return 1 + ;; + esac + return 0 +} + +# run: Generate configuration and run application stack. +run() { + conf=/tmp/xr.conf.$$ + xenstore=/tmp/xr.store.$$ + >${conf} + >${xenstore} + OPTIND=1 + nindex=0 + bindex=0 + conf_disk= + conf_vif= + opt_pause= + opt_interactive= + opt_destroy='on_poweroff="preserve"' + opt_mem=16 + opt_name= + while getopts "n:b:pidN:M:" opt; do + case "$opt" in + # -n: NETSPEC: type:method + n) + parse_netspec "${OPTARG}" || usage + nindex=$(expr $nindex + 1) + ;; + # -b: BLKSPEC: hostpath:mountpoint + b) + image=${OPTARG%:*} + mountpoint=${OPTARG#*:} + [ -n "$image" ] || usage + [ -n "$mountpoint" ] || usage + [ -f "$image" ] || err File $image does not exist + fstype=$(detect_fstype $image) + [ $? -ne 0 ] && err File $image: unknown fstype + vdev=hd$(echo $bindex | tr '[0-9]' '[a-j]') + conf_disk="${conf_disk}'file:$image,$vdev,rw'," + echo blk/${bindex}/type etfs >>${xenstore} + echo blk/${bindex}/fstype $fstype >>${xenstore} + echo blk/${bindex}/mountpoint $mountpoint\ + >>${xenstore} + bindex=$(expr $bindex + 1) + ;; + # -p: Leave the domain paused after creation. + p) + opt_pause=1 + ;; + # -i: Attach to domain console on startup. + i) + opt_interactive=1 + ;; + # -d: Destroy domain on poweroff instead of preserving it. + d) + opt_destroy='on_poweroff="destroy"' + ;; + # -N: Override domain name. + N) + opt_name=${OPTARG} + ;; + # -M: Set domain memory. + M) + opt_mem=${OPTARG} + ;; + *) + usage + ;; + esac + done + # Clean up vif and disk, xl does not like trailing commas. + conf_vif=$(echo ${conf_vif} | sed -e s/,\$//) + [ -n ${conf_vif} ] && conf_vif="vif=[${conf_vif}]" + conf_disk=$(echo ${conf_disk} | sed -e s/,\$//) + [ -n ${conf_disk} ] && conf_disk="disk=[${conf_disk}]" + # Remaining arguments belong to the application. + shift $((OPTIND-1)) + [ "$1" = "--" ] && shift + name=${opt_name:-rumprun-$(basename $1)} + app=$(realpath $1) + shift + # Generate xl configuration file. + cat </tmp/xr.conf.$$ +kernel="${app}" +name="${name}" +vcpus=1 +memory=${opt_mem} +on_crash="preserve" +${opt_destroy} +extra="$@" +${conf_vif} +${conf_disk} +EOM + # Create the domain and leave it paused so that we can get its domid. + if ! xl create -p ${conf} >/dev/null; then + err xl create failed + fi + rm ${conf} + domid=$(xl domid ${name}) + # Write provisioning information for domain to xenstore. + prefix=/local/domain/${domid}/rumprun + cat ${xenstore} | while read line; do + xenstore-write ${prefix}/${line} + done + rm ${xenstore} + # Go go go! + [ -z "$opt_pause" ] && xl unpause ${domid} + if [ -n "$opt_interactive" ]; then + exec xl console $domid + else + echo ${domid} + fi +} + +if [ $# -lt 1 ]; then + usage +fi +if [ $(id -u) -ne 0 ]; then + err Must be root +fi + +run "$@" diff --git a/app-tools/xr b/app-tools/xr deleted file mode 100755 index dd8724a..0000000 --- a/app-tools/xr +++ /dev/null @@ -1,251 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2014 Martin Lucina. All Rights Reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# - -# -# xr: rumprun-xen stack "driver" script for running application stacks -# - -err() { - echo xr: error: "$@" 1>&2 - exit 1 -} - -usage() { - cat <>${xenstore} - echo net/${nindex}/method dhcp >>${xenstore} - ;; - static) - ifaddr=${3%/*} - ifmask=$(cidr2mask ${3#*/}) - ifgw=$4 - echo net/${nindex}/type inet >>${xenstore} - echo net/${nindex}/method static >>${xenstore} - echo net/${nindex}/addr ${ifaddr} >>${xenstore} - echo net/${nindex}/netmask ${ifmask} >>${xenstore} - [ -n "${ifgw}" ] && - echo net/${nindex}/gw ${ifgw} >>${xenstore} - ;; - *) - return 1 - ;; - esac - return 0 -} - -# xr run: Generate configuration and run application stack. -xr_run() { - conf=/tmp/xr.conf.$$ - xenstore=/tmp/xr.store.$$ - >${conf} - >${xenstore} - OPTIND=1 - nindex=0 - bindex=0 - conf_disk= - conf_vif= - opt_pause= - opt_interactive= - opt_destroy='on_poweroff="preserve"' - opt_mem=16 - opt_name= - while getopts "n:b:pidN:M:" opt; do - case "$opt" in - # -n: NETSPEC: type:method - n) - parse_netspec "${OPTARG}" || usage - nindex=$(expr $nindex + 1) - ;; - # -b: BLKSPEC: hostpath:mountpoint - b) - image=${OPTARG%:*} - mountpoint=${OPTARG#*:} - [ -n "$image" ] || usage - [ -n "$mountpoint" ] || usage - [ -f "$image" ] || err File $image does not exist - fstype=$(detect_fstype $image) - [ $? -ne 0 ] && err File $image: unknown fstype - vdev=hd$(echo $bindex | tr '[0-9]' '[a-j]') - conf_disk="${conf_disk}'file:$image,$vdev,rw'," - echo blk/${bindex}/type etfs >>${xenstore} - echo blk/${bindex}/fstype $fstype >>${xenstore} - echo blk/${bindex}/mountpoint $mountpoint\ - >>${xenstore} - bindex=$(expr $bindex + 1) - ;; - # -p: Leave the domain paused after creation. - p) - opt_pause=1 - ;; - # -i: Attach to domain console on startup. - i) - opt_interactive=1 - ;; - # -d: Destroy domain on poweroff instead of preserving it. - d) - opt_destroy='on_poweroff="destroy"' - ;; - # -N: Override domain name. - N) - opt_name=${OPTARG} - ;; - # -M: Set domain memory. - M) - opt_mem=${OPTARG} - ;; - *) - usage - ;; - esac - done - # Clean up vif and disk, xl does not like trailing commas. - conf_vif=$(echo ${conf_vif} | sed -e s/,\$//) - [ -n ${conf_vif} ] && conf_vif="vif=[${conf_vif}]" - conf_disk=$(echo ${conf_disk} | sed -e s/,\$//) - [ -n ${conf_disk} ] && conf_disk="disk=[${conf_disk}]" - # Remaining arguments belong to the application. - shift $((OPTIND-1)) - [ "$1" = "--" ] && shift - name=${opt_name:-rumprun-$(basename $1)} - app=$(realpath $1) - shift - # Generate xl configuration file. - cat </tmp/xr.conf.$$ -kernel="${app}" -name="${name}" -vcpus=1 -memory=${opt_mem} -on_crash="preserve" -${opt_destroy} -extra="$@" -${conf_vif} -${conf_disk} -EOM - # Create the domain and leave it paused so that we can get its domid. - if ! xl create -p ${conf} >/dev/null; then - err xl create failed - fi - rm ${conf} - domid=$(xl domid ${name}) - # Write provisioning information for domain to xenstore. - prefix=/local/domain/${domid}/rumprun - cat ${xenstore} | while read line; do - xenstore-write ${prefix}/${line} - done - rm ${xenstore} - # Go go go! - [ -z "$opt_pause" ] && xl unpause ${domid} - if [ -n "$opt_interactive" ]; then - exec xl console $domid - else - echo ${domid} - fi -} - -if [ $# -lt 2 ]; then - usage -fi -if [ $(id -u) -ne 0 ]; then - err Must be root -fi - -cmd="$1" -shift -case "$cmd" in - run) - xr_run "$@" - ;; - *) - usage - ;; -esac -