diff options
author | Simon Rettberg | 2019-07-10 16:16:41 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-07-10 16:16:41 +0200 |
commit | 23dc3416970c1825eff72599e807f08501fcad0a (patch) | |
tree | 1fe329fac0074f761e641d49a00f64e586942653 /core/modules/run-virt/data/opt/openslx/vmchooser | |
parent | [run-virt] improve signal traps handling (diff) | |
download | mltk-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/modules/run-virt/data/opt/openslx/vmchooser')
3 files changed, 28 insertions, 16 deletions
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 |