From 9a95c0c2d4a6382683725d5be0ab9171f9aed828 Mon Sep 17 00:00:00 2001 From: Michael Janczyk Date: Tue, 30 Mar 2010 20:11:25 +0200 Subject: diskless boot + minor modifications, virtualization.conf /w freemem --- .../plugins/virtualbox/files/machine.include | 2 +- .../plugins/virtualbox/files/run-virt.include | 61 ++++++++--------- os-plugins/plugins/vmgrid/XX_vmgrid.sh | 23 ++++++- os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 78 +++++++++++++--------- os-plugins/plugins/vmgrid/files/vmgrid | 8 +-- 5 files changed, 100 insertions(+), 72 deletions(-) (limited to 'os-plugins/plugins') diff --git a/os-plugins/plugins/virtualbox/files/machine.include b/os-plugins/plugins/virtualbox/files/machine.include index 125e45cd..78c4bee8 100644 --- a/os-plugins/plugins/virtualbox/files/machine.include +++ b/os-plugins/plugins/virtualbox/files/machine.include @@ -111,7 +111,7 @@ cat << EOF > "${machconfig}" - + /d" ${machconfig} +fi + # add ssh port if linux and NAT if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then vmsshport="220${VM_ID}" @@ -322,33 +331,17 @@ fi # wait for a certain command to settle # get the PID of the right process -# TODO: not very good! But seems to work -# TODO: not needed? KILL!!! +# kill PID, seems to work VBMANPID=$(pstree -p | grep VBoxXPCOMIPCD | grep -ivE "VirtualBox|VBoxHeadless"\ | sed -e "s/.*VBoxXPCOMIPCD(\(.*\)).*/\1/") for i in $(echo ${VBMANPID}); do kill -9 ${VBMANPID} >/dev/null 2>&1 done -# TODO: OLD Version, NOW: KILL process -#VBMANPID=$(pstree -p | grep VBoxXPCOMIPCD | grep -ivE "VirtualBox|VBoxHeadless"\ -# | sed -e "s/.*VBoxXPCOMIPCD(\(.*\)).*/\1/" | tail -n 1) -#for i in {0..999}; do -# ps aux | grep -v grep | grep VBoxXPCOMIPCD | grep -q " ${VBMANPID} " || break -# if [ $i -eq 999 ]; then -# kill -9 ${VBMANPID} >/dev/null 2>&1 -# writelog "Process ID ${VBMANPID} did not finish, killing!" -# fi -#done # set the variables appropriately (several interfaces with different names) VIRTCMD=$(which VirtualBox 2>/dev/null) VIRTCMDOPTS="--startvm ${machineuuid} --start-running" -# SDL tests -#VIRTCMDSDL=$(which VBoxSDL 2>/dev/null) -#VIRTCMDOPTSSDL="--startvm ${machineuuid} --fullscreen --hwvirtex --memory 1024 \ -# --fixedmode 1680 1050 24 --hostkey 302 0" - # set headless mode VIRTCMDHL=$(which VBoxHeadless 2>/dev/null) VIRTCMDOPTSHL="-s ${machineuuid}" diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh index 3cac7c12..d9e35dfb 100644 --- a/os-plugins/plugins/vmgrid/XX_vmgrid.sh +++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh @@ -39,8 +39,6 @@ if [ -f $CONFFILE ]; then . /etc/functions testmkd ${PLUGINCONFDIR} - # create folder for virtual virtualization plugin - testmkd ${VIRTUALIZATIONPLUGIN} testmkd ${VIRTDIR} cp $CONFFILE ${PLUGINCONFDIR}/vmgrid.conf # create link to binpath @@ -98,7 +96,26 @@ if [ -f $CONFFILE ]; then chmod 1777 ${RWSHARE} echo "vmgrid_rwmnt=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf - # TODO: virtual virtualization plugin + # virtual virtualization plugin + testmkd ${VIRTUALIZATIONPLUGIN} + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ + | awk '{print $2}') / 1024) + if [ ${totalmemtest} -le 100 2>/dev/null ]; then + # get hostmem + freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) + freemem=$(expr ${totalmem} \* ${freememper} / 100) + echo "virt_freemem=${freemem}" \ + >> ${VIRTUALIZATIONPLUGIN}/virtualization.conf + else + # more than 100% memory assigned stupid! + # vmgrid will get this as well and exit! + # so we have theoretically 100% free + echo "virt_freemem=${totalmem}" \ + >> ${VIRTUALIZATIONPLUGIN}/virtualization.conf + fi # finished ... [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmgrid' os-plugin ..." diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index 21d7cbf8..e1b2ffe6 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -52,6 +52,7 @@ writelog () { ################################################################################ # check if forcemem or graphical mode set +headless=1 while [ $# -gt 0 ]; do case "$1" in -h|--help) @@ -109,7 +110,7 @@ if [ $runningvms -le 0 ]; then exit 1 fi # check if vmchooser plugin installed -if [ ${vmchooser_active} -eq 1 2>/dev/null ] && [ ${runningvms} -gt 1 ]; then +if [ -n "${vmchooser_active}" ] && [ ${runningvms} -gt 1 ]; then # only allow one instance of vmgrid writelog "Already 1 VMs running and vmchooser plugin is active." writelog "Can't start ${xmlfile}, exiting!" @@ -151,8 +152,7 @@ writelog "\tVM-ID:\t\t\t${VM_ID}" writelog "\tLogfile:\t\t${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log" writelog "\t/tmp info:\t\t$(df -h | grep " /tmp$" | awk '{print $2}') \c" writelog "$(grep "/tmp " /proc/mounts | awk '{print $1" "$2" "$3" "$4}')" -writelog "\tVM XML dir:\t\t${vmgrid_xmlpath}" -writelog "\tVM Image dir:\t\t${vmgrid_imgpath}" +writelog "\tVM XML dir:\t\t$(dirname ${xmlfile})" if ! grep '/dev/null 2>&1; then writelog \ @@ -167,45 +167,66 @@ writelog "VM config:" imgname=$(grep -io '/dev/null | grep '/' >/dev/null 2>&1; then +# diskless boot +elif [ "${boot}" = "n" ] && [ -z "${imgname}" ]; then + diskless=1 + vmpath="{diskless boot}" +# imagename /w full path +elif echo ${imgname} 2>/dev/null | grep -q '/' >/dev/null 2>&1; then imgpath=$(dirname ${imgname}) imgname=$(basename ${imgname}) vmpath=${imgpath}/${imgname} +# get path from var else imgpath=${vmgrid_imgpath} vmpath=${imgpath}/${imgname} fi # check if virtual machine container file exists, only if not rwimg -if ! [ -e "${vmpath}" ] && [ "${imgmode}" != "rwimg" ]; then +if ! [ -e "${vmpath}" ] && [ "${imgmode}" != "rwimg" ] && [ ${diskless} -eq 0 ]; +then writelog "\tVirtual machine image or directory ${vmpath} not found!" exit 1 fi +# name of the virt machine, sed because of Windows formatting +vm_name=$(grep -o 'short_description param=.*"' ${xmlfile} | \ + sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') + +# define vm_shortname since vm_name can be very long +if [ -n "${imgname}" ]; then + # if ${vm_name} not defined use ${imgname} + vm_name=${vm_name:-"${imgname%.*}"} + vm_shortname=$(basename ${imgname%.*} | sed -e "s, ,-,g") +elif [ -n "${vm_name}" ]; then + vm_shortname=$(echo ${vm_name} | awk '{print $1" "$2" "$3}' \ + | sed -e "s, ,-,g;s,-$,,;s,-$,,") +else + vm_name=$(date | md5sum | awk '{print $1}') + vm_shortname=${vm_name} +fi +# vm_name = displayname, define for old scripts +displayname=${vm_name} + +[ "${imgmode}" != "rwimg" ] && [ ${diskless} -eq 0 ] \ + && writelog "\tVM Image dir:\t\t${imgpath}" writelog "\tVM file/dir:\t\t$vmpath" # is there an additional configuration provided? @@ -253,7 +274,7 @@ elif [ -z "${xmlvirt}" ]; then writelog "result:\t${xmlvirt}" fi -# TODO: confs von openvz lesen? +# check for virt if [ "${vmgrid_virt}" != "${xmlvirt}" ]; then writelog "\tThe virtual machine specified in ${xmlfile}" writelog "\tdoes not match the virtualization used here (${vmgrid_virt})" @@ -269,9 +290,6 @@ network_kind=$(grep -io 'network param=.*"' ${xmlfile} | \ network_card=$(grep -io 'netcard param=.*"' ${xmlfile} | \ awk -F '"' '{ print $2 }') -# get boot attr -boot=$(grep -io 'boot param=.*"' ${xmlfile} | awk -F '"' '{ print $2 }') - writelog "\tVirtualization:\t\t$xmlvirt" writelog "\tVM name:\t\t$vm_name" writelog "\tVM short name:\t\t$vm_shortname" @@ -342,24 +360,24 @@ else fi # start graphical mode -if [ ${headless} -eq 0 2>/dev/null ]; then +if [ ${headless} -eq 0 ]; then if [ -z "${VIRTCMD}" ]; then - writelog "Grapical mode not available, exiting" + writelog "Grapical mode not available, exiting!" exit 1 fi writelog "Starting ${vmgrid_virt} in graphical mode..." - ${VIRTCMD} ${VIRTCMDOPTS} + ${VIRTCMD} ${VIRTCMDOPTS} 2>/dev/null # start headless elif [ -n "${VIRTCMDHL}" ]; then writelog "Starting ${vmgrid_virt} in headless mode..." - ${VIRTCMDHL} ${VIRTCMDOPTSHL} + ${VIRTCMDHL} ${VIRTCMDOPTSHL} 2>/dev/null else writelog "${vmgrid_virt}: No headless mode defined, exiting!" exit 1 fi -if echo "${RMDIRS}" 2>/dev/null | grep ${vmgrid_virt} >/dev/null 2>&1; then - writelog "${vmgrid_virt} exited. Cleanning up...\c" +if echo "${RMDIRS}" 2>/dev/null | grep -q ${vmgrid_virt}; then + writelog "${vmgrid_virt} exited. Cleanning up... \c" rm -rf ${RMDIRS} >/dev/null 2>&1 writelog "done" fi diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid index d93f4fbd..b75b5341 100644 --- a/os-plugins/plugins/vmgrid/files/vmgrid +++ b/os-plugins/plugins/vmgrid/files/vmgrid @@ -29,7 +29,7 @@ if [ -n "$1" ]; then exit 0 else echo "Starting run-vmgrid.sh with options '$@'" - run-vmgrid.sh $@ + run-vmgrid.sh $@ 2>/dev/null exit fi fi @@ -90,7 +90,7 @@ if [ ${hostmem} -lt 256 2>/dev/null ]; then fi # get other vm mem -if [ ${vmchooser_active} -eq 1 ]; then +if [ -n "${vmchooser_active}" ]; then othervmratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $5}') othervmmem=$(expr ${totalmem} \* ${othervmratio} / 100 2>/dev/null) if [ ${othervmmem} -lt 512 2>/dev/null ]; then @@ -156,10 +156,10 @@ for i in {1..4}; do writelog "${vm[$i]} already running, skipping!" else writelog "Starting ${vm[$i]} via run-vmgrid.sh with ${vmmem[$i]} MB RAM" - run-vmgrid.sh --forcemem ${vmmem[$i]} ${vm[$i]} & + run-vmgrid.sh --forcemem ${vmmem[$i]} ${vm[$i]} 2>/dev/null & echo $! > /tmp/vmgrid/${USER}/vmgrid.pids # wait 5 secs for the next vm to start - sleep 5 + sleep 10 fi fi done -- cgit v1.2.3-55-g7522