diff options
Diffstat (limited to 'os-plugins/plugins/vmgrid')
-rw-r--r-- | os-plugins/plugins/vmgrid/XX_vmgrid.sh | 4 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 6 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/vmgrid | 55 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh | 54 |
4 files changed, 57 insertions, 62 deletions
diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh index 1d0c76be..f75c895d 100644 --- a/os-plugins/plugins/vmgrid/XX_vmgrid.sh +++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh @@ -30,8 +30,8 @@ if [ -f $CONFFILE ]; then # load needed variables . $CONFFILE - if [ $vmgrid_active -ne 0 ] ; then - [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..." + if [ ${vmgrid_active} -ne 0 ] ; then + [ ${DEBUGLEVEL} -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..." # load general configuration . /etc/initramfs-setup diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index 5e64b4cd..1501749e 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -53,19 +53,19 @@ writelog () { ### Get XML file and dir ################################################################################ -# check if forcemem or graphical mode set +# check if mem or graphical mode set headless=1 while [ $# -gt 0 ]; do case "$1" in -h|--help) - echo -e "Usage: run-vmgrid.sh [-g] [--forcemem <memorysize in MB>] \c" + echo -e "Usage: run-vmgrid.sh [-g] [--mem <memorysize in MB>] \c" echo -e "[/path/]filename[.xml]" exit ;; -g) headless=0 ;; - --forcemem) + --mem) # get a result which can be divided through 4 forcemem=$2 echo $2 | grep -q '[1-9][0-9]\{2,3\}$' && forcemem=$(expr $2 / 4 \* 4) diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid index ef86cb5a..d8ccd938 100644 --- a/os-plugins/plugins/vmgrid/files/vmgrid +++ b/os-plugins/plugins/vmgrid/files/vmgrid @@ -24,7 +24,7 @@ if [ -n "$1" ]; then if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then - echo -e "Usage: vmgrid [[-g] [--forcemem <memorysize in MB>] \c" + echo -e "Usage: vmgrid [[-g] [--mem <memorysize in MB>] \c" echo -e "[/path/]filename[.xml]]" exit 0 else @@ -47,9 +47,6 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share # load general virtualization information [ -f ${PLUGINCONFROOT}/virtualization/virtualization.conf ] && \ . ${PLUGINCONFROOT}/virtualization/virtualization.conf -# get the vmchooser_active var -[ -f ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ] && \ - . ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ################################################################################ ### Functions used throughout the script @@ -69,48 +66,35 @@ writelog () { ### Configure VMs for autostart and set RAM ################################################################################ -# start to log, create shrare log dir +# start to log, create share log dir mkdir -m 1777 -p ${vmgrid_rwmnt}/logs mkdir -m 1777 -p /tmp/vmgrid mkdir -p /tmp/vmgrid/${USER} echo "Starting to log at $(date)" \ >${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log +if [ -z "${hostratio}" ]; then + writelog "There has been an error in the memory configuration in stage 3" + writelog "Please check your memory ratio settings, exiting!" + exit 1 +fi + # remove blanks -vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s, *,,g") vmgrid_startvms=$(echo ${vmgrid_startvms} | sed -e "s, *,,g") +vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s, *,,g") -# get hostmem, totalmem from stage 3 -hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') -hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) -if [ ${hostmem} -lt 256 2>/dev/null ]; then - hostmem=256 - writelog "${hostmem} MB RAM reserved for host" -fi - -# get other vm mem -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 - othervmmem=512 - writelog "${othervmmem} MB RAM reserved for other virtualization solutions" - fi -else - othervmratio=0 - othervmmem=0 -fi +# hostmem, mainvirt from virtualization plugin +# ratio minus other vms and host +restratio=$(expr 100 - ${hostratio} - ${mainvirtratio}) +# hostmem, totalmem, mainvirtmem from virtualization plugin # calculate freemem -freemem=$(expr ${totalmem} - ${hostmem} - ${othervmmem} 2>/dev/null) +freemem=$(expr ${totalmem} - ${hostmem} - ${mainvirtmem} 2>/dev/null) if [ ${freemem} -lt 512 2>/dev/null ]; then writelog "Not enough free RAM for this plugin, free: ${freemem} MB" exit 1 fi -# ratio minus other vms and host -restratio=$(expr 100 - ${hostratio} - ${othervmratio}) - # get clients mem ratio vmsumratios=0 for i in {1..4}; do @@ -123,15 +107,8 @@ for i in {1..4}; do vmsumratios=$(expr ${vmsumratios} + ${vmratio[$i]} 2>/dev/null) done -# ratio test: 100 - host - other vm + grid ratios -ratiotest=$(expr 100 - ${restratio} + ${vmsumratios} 2>/dev/null) -if [ ${ratiotest} -gt 100 ]; then - #writelog "you managed to get over 100% in ratio Einstein: ${ratiotest}%" - exit 1 -fi - for i in {1..4}; do - # calculate vms mem: mem = $freemem * $vmratio/100 * 100/$restratio + # calculate VMs mem: mem = $freemem * $vmratio/100 * 100/$restratio # multiple of 4 vmmem[$i]=$(expr ${freemem} \* ${vmratio[$i]} / ${restratio} / 4 \* 4 \ 2>/dev/null) @@ -155,7 +132,7 @@ 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]} 2>/dev/null & + run-vmgrid.sh --mem ${vmmem[$i]} ${vm[$i]} 2>/dev/null & echo $! > /tmp/vmgrid/${USER}/vmgrid.pids # wait 5 secs for the next vm to start sleep 10 diff --git a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh index 5fa046d9..400075cd 100644 --- a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh +++ b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh @@ -25,9 +25,9 @@ PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization # check if plugins available active=0 [ -f ${CONFFILEVMCHOOSER} ] && . ${CONFFILEVMCHOOSER} -[ -n "${CONFFILEVMCHOOSER}" ] && active=1 +[ ${vmchooser_active} -ne 0 ] && active=1 [ -f ${CONFFILEVMGRID} ] && . ${CONFFILEVMGRID} -[ -n "${CONFFILEVMGRID}" ] && active=1 +[ ${vmgrid_active} -ne 0 ] && active=1 [ $DEBUGLEVEL -gt 0 ] \ && echo -e "Executing the virtual 'virtualization' plugin ... \c" @@ -45,27 +45,45 @@ if [ ${active} -ne 0 ] ; then totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ | awk '{print $2}') / 1024) echo "totalmem=${totalmem}" >> ${PLUGINCONFDIR}/virtualization.conf + if [ ${vmgrid_active} -ne 0 ]; then + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + + # not more than 100% memory assigned 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 "freemem=${freemem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf - else - # more than 100% memory assigned stupid! - # vmgrid will get this as well and exit! - # so we have theoretically 100% free - echo "freemem=${totalmem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf + + # host mem + hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') + hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) + if [ ${hostmem} -lt 256 2>/dev/null ]; then + # min. 256 MB for host + hostmem=256 + fi + + # main vm mem (vmchooser) + if [ ${vmchooser_active} -ne 0 ]; then + mainvirtratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $5}') + mainvirtmem=$(expr ${totalmem} \* ${mainvirtratio} / 100 2>/dev/null) + if [ ${mainvirtmem} -lt 512 2>/dev/null ]; then + # min. 512 for vmchooser + mainvirtmem=512 + fi + else + mainvirtratio=0 + mainvirtmem=0 + fi + + cat << EOF >> ${PLUGINCONFDIR}/virtualization.conf +hostratio=${hostratio} +hostmem=${hostmem} +mainvirtratio=${mainvirtratio} +mainvirtmem=${mainvirtmem} +EOF + fi - else - echo "freemem=${totalmem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf -fi + fi # cpu cores CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l) |