summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-10 16:16:41 +0200
committerSimon Rettberg2019-07-10 16:16:41 +0200
commit23dc3416970c1825eff72599e807f08501fcad0a (patch)
tree1fe329fac0074f761e641d49a00f64e586942653 /core
parent[run-virt] improve signal traps handling (diff)
downloadmltk-23dc3416970c1825eff72599e807f08501fcad0a.tar.gz
mltk-23dc3416970c1825eff72599e807f08501fcad0a.tar.xz
mltk-23dc3416970c1825eff72599e807f08501fcad0a.zip
[run-virt] Tweak init and handling of some constants; add documentation
Diffstat (limited to 'core')
-rw-r--r--core/modules/run-virt/README86
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc4
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc17
-rwxr-xr-xcore/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt23
4 files changed, 112 insertions, 18 deletions
diff --git a/core/modules/run-virt/README b/core/modules/run-virt/README
index d3368ede..f009f55a 100644
--- a/core/modules/run-virt/README
+++ b/core/modules/run-virt/README
@@ -1,4 +1,86 @@
-Configuring run-virt:
+Attempt at documenting run-virt.
+
+Note that lecture and VM are often used interchangeably here and in the
+actual run-virt scripts.
+
+--------------------
+### Global constants
+--------------------
+
+These constants are globally defined in the run-virt environment and are read-only.
+
+# $CONFDIR
+This is where the downloaded metadata for the VM to be run is located.
+Contains the VM hw description (virtualizer specific), network shares to
+mount, startup scripts, ...
+
+# $DEBUG
+Set to either "true" or "false" so it can simply be used like this:
+if $DEBUG; then ....
+
+# $IMGUUID
+The UUID of this VM/lecture, extracted from the passed $XMLFILE.
+Used to fetch meta data for the VM, like vmx, netrules, netshares, etc.
+
+# $LOGFILE
+Log file for run-virt. You shouldn't need to access this file directly but
+rather use the "writelog" function.
+
+# $PLUGIN_ID
+Name of the virtualizer plugin required to run the current VM, e.g.
+vmware or virtualbox. This is used to source the according scripts
+from $VMCHOOSER_DIR/plugins/$PLUGIN_ID/*
+
+# $SELF
+Absolute path to the main run-virt script. Should usually be
+/opt/openslx/vmchooser/vmchooser-run_virt
+
+# $SRC_IMG_ABSOLUTE
+Absolute path to the VMs HDD image. When using DNBD3, which requires
+$SRC_IMG_RELATIVE to be set, this file might not actually exist.
+This can be empty if $SRC_IMAGE_RELATIVE is given.
+
+# $SRC_IMG_RELATIVE
+Relative path to the VMs HDD image. Used for DNBD3, or for constructing
+the absolute path in case it's not supplied via the $XMLFILE, but
+$VMSTORE_PATH is known.
+This can be empty if $SRC_IMG_ABSOLUTE is given.
+
+# $TMPDIR
+Temporary directory to work in. Create single files, or if you feel like you
+need a bunch of them, group within a subdirectory. This will be wiped on exit.
+
+# $USER
+Name of the currently logged in user. This doesn't necessarily match the
+name on the auth server (LDAP/AD) but rather what the running Linux system sees.
+
+# $VMCHOOSER_CONF_DIR
+Config dir of run-virt, where several (sourcable) files are located.
+
+# $VMCHOOSER_DIR
+Base directory of run-virt/vmchooser, usually /opt/openslx/vmchooser
+
+# $VMSTORE_PATH
+Currently hard-coded to /mnt/vmstore via run-virt-includes/get_xml_file_variables.inc.
+In case VMs are read via CIFS/NFS, this is where it should be mounted.
+
+# $VM_CLEANNAME
+"Clean" version of $VM_DISPLAYNAME, no spaces or special chars except
+'_', '-' and '.', 32 chars max.
+
+# $VM_DISPLAYNAME
+Name of the VM as shown to the user, and displayed in vmchooser.
+
+# $VM_OS_TYPE
+Name of the VMs operating system as known to the virtualizer in use.
+This should not exist but does for complicated reasons.
+
+# $XMLFILE
+XML description file of VM session to be run. Passed via command line.
+
+------------------------
+### Configuring run-virt
+------------------------
## /opt/openslx/vmchooser/config/resource_urls.conf
@@ -56,4 +138,4 @@ Note that this is a floppy, not the cloud, so you're limited to 1.44MB of storag
# image-access.d/
Hook to set up read or write access to image. Here, only *.inc type hooks make sense, since they're
-expected to set either VM_DISKFILE_RO or VM_DISKFILE_RW, depending on desired access. \ No newline at end of file
+expected to set either VM_DISKFILE_RO or VM_DISKFILE_RW, depending on desired access.
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc
index 7bf07458..ff5c736c 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc
@@ -37,7 +37,9 @@ parse_xml() {
EXIT_TYPE="user" EXIT_REASON="Ungültiger asboluter Pfad zur virtuellen Maschine!" cleanexit 1
fi
- notempty SRC_IMG_ABSOLUTE || SRC_IMG_ABSOLUTE="${VMSTORE_PATH}/${SRC_IMG_RELATIVE}"
+ if isempty SRC_IMG_ABSOLUTE && notempty VMSTORE_PATH; then
+ SRC_IMG_ABSOLUTE="${VMSTORE_PATH}/${SRC_IMG_RELATIVE}"
+ fi
readonly SRC_IMG_ABSOLUTE
declare -rg IMG_BASENAME=$(basename "$SRC_IMG_ABSOLUTE")
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
index f049642d..abf66842 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
@@ -29,15 +29,19 @@ get_vm_id() {
################# LOGGING FUNCTIONS ##################
# Helper function to write to stdout and logfile
writelog() {
- local DATE=$(date +%Y-%m-%d-%H-%M-%S)
+ local DATE="$(date +%Y-%m-%d-%H-%M-%S)"
# write to stdout?
if [ "x$1" = "x--quiet" ]; then
shift
else
- echo -e "$DATE: $@"
+ echo -e "$DATE: $*"
fi
# log into file
- echo -e "$DATE: ${SLX_DEBUG:+(${FUNCNAME[1]}) }$@" >> "${LOGFILE}"
+ if $DEBUG; then
+ echo -e "$DATE: (${FUNCNAME[1]}) $*" >> "${LOGFILE}"
+ else
+ echo -e "$DATE: $*" >> "${LOGFILE}"
+ fi
}
# Helper function to notify the user.
@@ -122,7 +126,7 @@ add_cleanup() {
cleanexit() {
trap "" SIGHUP SIGINT SIGTERM EXIT
writelog "Cleanexit '$1' triggered by '${BASH_SOURCE[1]}:${FUNCNAME[1]}'"
- sleep 1
+ usleep 250000
while isset CLEANUP_TASKS; do
local TASK=${CLEANUP_TASKS[-1]}
unset -v CLEANUP_TASKS[-1]
@@ -134,12 +138,13 @@ cleanexit() {
writelog "Failed to run cleanup function '$TASK'! Exit code: $RET"
fi
done
+ usleep 250000
# kill potential remaining background jobs
kill $(jobs -p)
# If we're not in debug mode, remove all temporary files
- if notempty SLX_DEBUG && isset TMPDIR; then
+ if ! $DEBUG && notempty TMPDIR; then
rm -rf -- "${TMPDIR}"
fi
@@ -226,7 +231,7 @@ translate() {
run_hooks() {
local dir file retval r
declare -a files
- dir="$BASEDIR/hooks/${1}.d"
+ dir="$VMCHOOSER_DIR/hooks/${1}.d"
[ -d "$dir" ] || return 100
shift
files=( "${dir}"/* )
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
index aef4ba79..9d7020ed 100755
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
@@ -29,17 +29,22 @@ if [ -z "$SELF" ] || ! [ -f "$SELF" ]; then
fi
readonly SELF
-# Useless without this
-. /opt/openslx/config
-. /opt/openslx/bin/slx-tools
-
# Global variables needed for the core functionality
-declare -rg VMCHOOSER_DIR="/opt/openslx/vmchooser"
+declare -rg VMCHOOSER_DIR="$( dirname "$SELF" )"
declare -rg VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config"
declare -rg USER="$(whoami)"
declare -rg TMPDIR="/tmp/virt/${USER}/$$"
declare -rg CONFDIR="${TMPDIR}/metadata"
+if ! [ -d "$VMCHOOSER_DIR" ]; then
+ slxlog "run-virt" "$SELF is not in a directory!?"
+ exit 1
+fi
+
+# Useless without this
+. /opt/openslx/config
+. /opt/openslx/bin/slx-tools
+
# Debug mode?
if [ "x$1" = "x--debug" ]; then
shift
@@ -49,6 +54,7 @@ elif [ "$SLX_DEBUG_MODE" = "ON" ] || grep -qE '\bdebug\b' "/proc/cmdline"; then
else
DEBUG=false
fi
+readonly DEBUG
# Check for existence of plugin
if [ "x$1" = "x--query" ]; then
@@ -73,15 +79,14 @@ declare -rg XML_FILE="$1"
# A path to the logfile can be given as second argument
declare -g LOGFILE="$2"
if [ -z "$LOGFILE" ] || ! touch "$LOGFILE" || ! [ -f "$LOGFILE" ]; then
- LOGFILE="/var/log/openslx/run-virt.$(whoami).$$.log"
+ LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log"
touch "$LOGFILE" || LOGFILE="$(mktemp)"
fi
+readonly LOGFILE
main() {
# Functions needed by vmchooser-run_virt (writelog(), cleanexit(), safesource())
- BASEDIR="$( dirname "${SELF}" )"
- RUN_VIRT_INCLUDE_DIR="${BASEDIR}/run-virt-includes"
- readonly BASEDIR RUN_VIRT_INCLUDE_DIR
+ declare -rg RUN_VIRT_INCLUDE_DIR="${VMCHOOSER_DIR}/run-virt-includes"
if ! source "${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc"; then
slxlog "run-virt" "Could not source ${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc"
exit 1