summaryrefslogtreecommitdiffstats
path: root/remote/modules/vmchooser
diff options
context:
space:
mode:
authorSimon Rettberg2013-11-27 17:37:16 +0100
committerSimon Rettberg2013-11-27 17:37:16 +0100
commit7f75f14a06255fad86151a5273bee619a313a594 (patch)
treedf43aa899f4c929480bf67d5afd30460cca975e4 /remote/modules/vmchooser
parent[dnbd3] Add slxlog (diff)
downloadtm-scripts-7f75f14a06255fad86151a5273bee619a313a594.tar.gz
tm-scripts-7f75f14a06255fad86151a5273bee619a313a594.tar.xz
tm-scripts-7f75f14a06255fad86151a5273bee619a313a594.zip
[vmchooser] Add slxlog to run-virt
Diffstat (limited to 'remote/modules/vmchooser')
-rwxr-xr-xremote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt94
1 files changed, 51 insertions, 43 deletions
diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt
index 5c85dfcd..0030eda1 100755
--- a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt
+++ b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt
@@ -180,18 +180,22 @@ DO_PROFILE="$(grep -c -E -i '<\s*profile\s*param="?(true|yes)"?' "$xmlfile")"
# test if the xml file is valid
if ! [ -r "${xmlfile}" ]; then
writelog "${xmlfile} not a readable XML file!"
+ slxlog "virt-nonreadable-xml" "XML file not readable: $xmlfile"
exit 1
fi
# test if XML file
-if ! grep '<?xml' "${xmlfile}" >/dev/null 2>&1; then
+if ! grep -q '<?xml' "${xmlfile}"; then
writelog "Submitted configuration file ${xmlfile} seems to have wrong XML format"
+ slxlog "virt-invalid-xml" "Malformed XML file: $xmlfile" "$xmlfile"
exit 1
fi
# check for running in graphical environment otherwise no much use here
-[ -z "$DISPLAY" ] && echo -e "\n\tStart only within a graphical desktop!\n" \
-&& exit 1
+if [ -z "$DISPLAY" ]; then
+ echo -e "\n\tStart only within a graphical desktop!\n"
+ exit 1
+fi
################################################################################
### Logo for console
@@ -219,8 +223,8 @@ writelog "\tXML file:\t\t${xmlfile}"
writelog "VM config:"
# Name of the virt image
-imgname=$(grep -io '<image_name param=.*"' "${xmlfile}" \
-| sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')
+imgname=$(grep -io '<image_name param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')
+
## Added for persistent support.
if [[ "$userBranchFilePath" ]]; then
imgname="$userBranchFilePath"
@@ -228,13 +232,13 @@ fi
##
# Imagename /w full path
-if echo "${imgname}" 2>/dev/null | grep -q '^/' >/dev/null 2>&1; then
+if echo "${imgname}" | grep -q '^/'; then
imgpath="$(dirname "${imgname}")"
imgname="$(basename "${imgname}")"
vmpath="${imgpath}/${imgname}"
# If old vmchooser binary stuff
# We do not need folder name as it is already included by vmchooser
-elif echo "${xmlfile}" 2>/dev/null | grep -q '^/tmp/' >/dev/null 2>&1; then
+elif echo "${xmlfile}" | grep -q '^/tmp/'; then
vmpath="$imgname"
imgname="$(basename "${imgname}")"
## Added for persistent support.
@@ -265,9 +269,7 @@ xmlvirt=$(grep -o 'virtualmachine param=.*"' "${xmlfile}" \
| sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}')
# choose the proper virtualization/emulator plugin
-[ "x${xmlvirt}" != "x" -a "x${xmlvirt}" != "xqemukvm" -a \
-"x${xmlvirt}" != "xvirtualbox" -a "x${xmlvirt}" != "xvmware" ] && \
-xmlvirt="emufe"
+[ "x${xmlvirt}" != "x" -a "x${xmlvirt}" != "xqemukvm" -a "x${xmlvirt}" != "xvirtualbox" -a "x${xmlvirt}" != "xvmware" ] && xmlvirt="emufe"
# make a guess from the filename extension if ${xmlvirt} is empty
# (not set within the XML file)
@@ -308,23 +310,18 @@ if [ -z "${xmlvirt}" ] && [ -n "${additional_config}" ]; then
fi
# Definition of the client system
-vmostype=$(grep -io '<os param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }' |\
-tr "[A-Z]" "[a-z]")
+vmostype=$(grep -io '<os param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }' | tr "[A-Z]" "[a-z]")
# Definition of the networking the client system is connected to
-network_kind=$(grep -io '<network param=.*"' "${xmlfile}" \
-| awk -F '"' '{ print $2 }' | tr "[A-Z]" "[a-z]")
-network_card=$(grep -io '<netcard param=.*"' "${xmlfile}" \
-| awk -F '"' '{ print $2 }'| tr "[A-Z]" "[a-z]")
+network_kind=$(grep -io '<network param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }' | tr "[A-Z]" "[a-z]")
+network_card=$(grep -io '<netcard param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }'| tr "[A-Z]" "[a-z]")
# Set redirects to 0, see vmgrid if you want to define some
redirects=0
# Serial/parallel ports defined (e.g. "ttyS0" or "autodetect")
-serial=$(grep -io '<serialport param=.*"' "${xmlfile}" \
-| awk -F '"' '{ print $2 }')
-parallel=$(grep -io '<parport param=.*"' "${xmlfile}" \
-| awk -F '"' '{ print $2 }')
+serial=$(grep -io '<serialport param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }')
+parallel=$(grep -io '<parport param=.*"' "${xmlfile}" | awk -F '"' '{ print $2 }')
writelog "\tVirtualization:\t\t$xmlvirt"
writelog "\tVM name:\t\t$vm_name"
@@ -367,30 +364,31 @@ if [ -n "$mainvirtmem" ]; then
fi
hostmem="$[ $totalmem - $mem ]"
-# Configuring ethernet mac address: first 3 bytes are fixed (00:50:56)
-# 4th byte is the VM-ID (0D)
-# last two bytes are taken from the bridge of the host
-# define one MAC per guest
+# TODO: We should only generate the suffix here (last 3 octets) as the first 3 are
+# dependant on the virtualizer/emulator. Check if any run-virt.include still relies on
+# $macguestpart/$macaddr. If so, fix it to use its specific first 3 bytes
+# and append $macaddrssuffix
macguestpart="00:50:56:${VM_ID}"
machostpart=$(echo "${hostmacaddr}" | awk -F ":" '{print $(NF-1)":"$NF}')
macaddr=$(echo "${macguestpart}:${machostpart}" | tr "[a-z]" "[A-Z]")
macaddrsuffix=$(echo "${VM_ID}:${machostpart}" | tr "[a-z]" "[A-Z]")
+if ! echo "$macaddrsuffix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then
+ slxlog "virt-mac" "Could not properly generate mac address suffix (got $macaddrsuffix)"
+fi
+
# Virtual fd/cd/dvd and drive devices, floppy b: for configuration
# if $floppy_0 from run-virt.include set then fdtest="TRUE"
-fdtest=
fdtest=${floppy_0:+"TRUE"}
# if $fdtest not set floppy0="FALSE", else "TRUE"
floppy0=${fdtest:-"FALSE"}
floppy1="TRUE"
floppy1name="$VMCHOOSER_DIR/data/loopimg/fd.img"
# if $cdrom_0 from run-virt.include set then cdtest="TRUE"
-cdtest=
cdtest=${cdrom_0:+"TRUE"}
# if $cdtest not set cdrom0="FALSE", else "TRUE"
cdrom0=${cdtest:-"FALSE"}
# if $cdrom_1 from run-virt.include set then cdtest="TRUE"
-cdtest=
cdtest=${cdrom_1:+"TRUE"}
# if $cdtest not set cdrom1="FALSE", else "TRUE"
cdrom1=${cdtest:-"FALSE"}
@@ -405,8 +403,7 @@ remotedesktopport="590${VM_ID}"
# Enable 3D
-enable3d=$(grep -i "<enable3d param=.*" ${xmlfile} 2>/dev/null | \
-awk -F '=' {'print $2'} | tr "[A-Z]" "[a-z]")
+enable3d=$(grep -i "<enable3d param=.*" ${xmlfile} 2>/dev/null | awk -F '=' '{print $2}' | tr "[A-Z]" "[a-z]")
# Add rw share
sharepath="${HOME}/PERSISTENT"
@@ -427,19 +424,12 @@ else
VOL="80%"
fi
# Adjust sound volume
-#writelog "Unmuting sound...\c "
amixer -q sset Master "$VOL" unmute 2>/dev/null
amixer -q sset PCM "$VOL" unmute 2>/dev/null
amixer -q sset CD "$VOL" unmute 2>/dev/null
amixer -q sset Headphone "$VOL" unmute 2>/dev/null
amixer -q sset Front "$VOL" unmute 2>/dev/null # in SUSE 11.0 it's headphone
amixer -q sset Speaker "$VOL" unmute 2>/dev/null # annoying built-in speaker
-#writelog "finished\n"
-
-# Load kvm modules
-if [ "$vtflag" = "1" -a -n "$kvm_module" ]; then
- modprobe "$kvm_module"
-fi
# # # # # # Start printer daemon # # # # # # #
@@ -449,13 +439,12 @@ QUEUE="STANDARD"
# Start the lpdaemon listening on the given port
tcpsvd -E 0.0.0.0 5515 \
- lpd "$SPOOLDIR" \
- sh -c "printergui $USER $SPOOLDIR/$QUEUE/\$DATAFILE" &
+ lpd "$SPOOLDIR" \
+ sh -c "printergui $USER $SPOOLDIR/$QUEUE/\$DATAFILE" &
# PID to kill the process
PID_LPD="$!"
-
# Copy guest configuration (with added information) config.xml to be accessed
# via virtual floppy
cp "$xmlfile" "$VMCHOOSER_DIR/fd-loop/config.xml"
@@ -483,7 +472,10 @@ if [ -n "$SLX_DNBD3_SERVERS" -o -n "$SLX_DNBD3_PRIO_SERVERS" ] && [ "x$SLX_VM_DN
break
fi
done
- [ -z "$vm_diskfile" ] && writelog "No working dnbd3 server found :-("
+ if [ -z "$vm_diskfile" ]; then
+ slxlog "virt-dnbd3" "No dnbd3 server for ${vmpath#/mnt/vmstore/} found ($SLX_DNBD3_PRIO_SERVERS $TMP_SERVERS), trying NFS..."
+ writelog "No working dnbd3 server found :-("
+ fi
else
writelog "Won't use dnbd3 as it's not loaded, or the daemon is not running..."
fi
@@ -499,20 +491,27 @@ fi
# Check if virtual machine container file exists
if ! [ -e "${vmpath}" ]; then
+ slxlog "virt-missing-image" "VM image $vmpath not found!"
writelog "Virtual machine image ${vmpath} not found!"
- exit 1
+ cleanexit 1
fi
writelog "Used diskfile: $vm_diskfile"
# Get all virtual machine specific stuff from the respective include file
if [ ! -e "$VMCHOOSER_DIR/$xmlvirt/run-virt.include" ] ; then
+ # TODO: Tell user
+ slxlog "virt-plugin-missing" "Could not find run-virt.include for $xmlvirt"
writelog "Failed because of missing ${xmlvirt} plugin."
cleanexit 1
fi
self="${xmlvirt}"
-. "$VMCHOOSER_DIR/$xmlvirt/run-virt.include" || writelog "Erroneous run-virt.include for $xmlvirt"
+if ! . "$VMCHOOSER_DIR/$xmlvirt/run-virt.include"; then
+ slxlog "virt-plugin-error" "run-virt.include for $xmlvirt could not be sourced (contains syntax errors?)" "$xmlvirt"
+ writelog "Erroneous run-virt.include for $xmlvirt"
+fi
+
# start a windowmanager for easier handling
# (expect problems w/ windows opening in background w/ vmware without wm)
for dm in openbox kwin xfwm4 metacity blackbox twm fvwm2 ; do
@@ -526,13 +525,22 @@ for dm in openbox kwin xfwm4 metacity blackbox twm fvwm2 ; do
break
fi
done
+
# Start poolvideoswitch if we find the autostarter file
#if [ -e /etc/xdg/autostart/pvsgui.desktop ]; then
# /usr/local/bin/pvsgui -p 2 -b >/dev/null 2>&1 &
#fi
+
if [[ "$DO_PROFILE" -ge "1" ]]; then
- wget "http://132.230.8.113/profile/do.php?action=start"
+ wget "http://132.230.8.113/profile/do.php?action=start" &
+fi
+
+# Check if tcpsvd is running. Do this down here so we do not check immediately after trying to spawn it,
+# as this could result in success even if it's not really working
+if ! kill -0 "$PID_LPD"; then
+ slxlog "virt-lpd" "Could not start tcpsvd/lpd for virtual machine session"
fi
+
# This will start the VM
eval ${VIRTCMD} ${VIRTCMDOPTS}
#