diff options
author | Jonathan Bauer | 2017-02-15 12:35:52 +0100 |
---|---|---|
committer | Jonathan Bauer | 2017-02-15 12:35:52 +0100 |
commit | fc740d39fa8069c3a47b5f58e2ce16b67adbf7ed (patch) | |
tree | 51e2fd12526bfe571888aa531b0dd4c332c20766 /core/modules/run-virt | |
parent | [runvirt] introduced wrapper script to start ... (diff) | |
download | mltk-fc740d39fa8069c3a47b5f58e2ce16b67adbf7ed.tar.gz mltk-fc740d39fa8069c3a47b5f58e2ce16b67adbf7ed.tar.xz mltk-fc740d39fa8069c3a47b5f58e2ce16b67adbf7ed.zip |
[runvirt] reworked wrapper log handling
Diffstat (limited to 'core/modules/run-virt')
3 files changed, 53 insertions, 27 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt b/core/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt index 8f6da0bf..96a47ea6 100755 --- a/core/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt +++ b/core/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt @@ -3,39 +3,57 @@ launch_runvirt() { if [ $# -ne 1 ]; then # we except 1 arg only! This case is weird, so lets just not do weird things... - slxlog "run-virt-wrapper" "Runvirt expects only 1 argument! $# given: $@" - exit 1 + log "Runvirt (wrapper) expects 1 argument! $# given: $@" + return 1 fi local RUNVIRT_SCRIPT="/opt/openslx/vmchooser/vmchooser-run_virt" if [ ! -s "${RUNVIRT_SCRIPT}" ]; then - slxlog "run-virt-wrapper" "Missing/empty main run-virt script expected at $RUNVIRT_SCRIPT!" - exit 1 + log "Missing/empty main run-virt script expected at '${RUNVIRT_SCRIPT}'!" + return 1 fi if ! bash -n "${RUNVIRT_SCRIPT}"; then - slxlog "run-virt-wrapper" "Syntax error in '${RUNVIRT_SCRIPT}'!" - exit 1 - fi - # we now manage the logfile externally - # create it at the expected place, namely: - local LOGFILE="/var/log/openslx/run-virt.$(whoami).$$.log" - if ! echo "$(date +%Y-%m-%d-%H-%M-%S): ## Wrapper init ##" >> "${LOGFILE}"; then - slxlog "run-virt-wrapper" "Failed to create '${LOGFILE}'." - # fallback: runvirt will create it itself + log "Syntax error in '${RUNVIRT_SCRIPT}'!" + return 1 fi + # start the main runvirt script "${RUNVIRT_SCRIPT}" "$1" "${LOGFILE}" & - - wait "$!" + local RUNVIRT_PID="$!" + usleep 50000 + # from now on, check if the LOGFILE still exists before writing to it + # if its not, runvirt deleted it and handles the logfile on its own + if ! kill -0 "${RUNVIRT_PID}"; then + [ -f "${LOGFILE}" ] && log "Failed to start main runvirt script. Seems that it exited early?." + return 1 + fi + wait "${RUNVIRT_PID}" # script exited here, check for exit code and send logfile to sat if appropriate local RUNVIRT_RET="$?" if [ ${RUNVIRT_RET} -ne 0 ]; then - slxlog "run-virt-failed" "Runvirt failed with '${RUNVIRT_RET}'. See attached log." "${LOGFILE}" - exit ${RUNVIRT_RET} + [ -f "${LOGFILE}" ] && log "Runvirt failed with '${RUNVIRT_RET}'." + return 1 fi - echo "$(date +%Y-%m-%d-%H-%M-%S): ## Wrapper exit ##" >> "${LOGFILE}" - + return 0 +} +# Log helper +log() { + echo "$(date +%Y-%m-%d-%H-%M-%S): ## WRAPPER ## $@" >> "${LOGFILE}" } -launch_runvirt $@ +## Main part +# logfile is now managed by this wrapper and given as argument to runvirt +declare -rg LOGFILE="/var/log/openslx/run-virt.$(whoami).$$.log" +if ! touch "${LOGFILE}"; then + # this should practically never happen, log it just in case + slxlog "run-virt-wrapper" "Failed to create '${LOGFILE}'." + # fallback: runvirt will try to handle it itself +fi +log "Launching runvirt with arguments '$@'..." +if ! launch_runvirt $@; then + [ -f "${LOGFILE}" ] && slxlog "run-virt-wrapper" "Failed to launch runvirt!" "${LOGFILE}" + exit 1 +fi +log "Runvirt exited as expected." +exit 0 diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc index e551e5e8..b49488cb 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc @@ -9,12 +9,20 @@ declare -rg TMPDIR="/tmp/virt/${USER}/$$" # Check if the path to the logfile was given externally (by the wrapper) unset WRAPPED -if isset LOGFILE; then - # given by wrapper - declare -rg WRAPPED=aye -else - declare -rg LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" +if notempty LOGFILE; then + if [ ! -w "${LOGFILE}" ]; then + # given logfile is not writeable or non-existant + # so handle it ourself (so do not set WRAPPED) + rm -f "${LOGFILE}" + unset LOGFILE + else + # given logfile was ok, mark that we are wrapped + # (for cleanexit to not slxlog the log since + # the wrapper is handling that for us) + declare -rg WRAPPED=aye + fi fi +isset LOGFILE || declare -rg LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" # Create temporary directory for current invocation if check_dep mkdir && ! mkdir -p "$TMPDIR"; then 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 c4c053af..b0832aa3 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 @@ -24,7 +24,7 @@ SELF=$(readlink -f "$0") declare -rg XML_FILE="$1" # A path to the logfile can be given as second argument -declare -rg LOGFILE="$2" +declare -g LOGFILE="$2" # Functions needed by vmchooser-run_virt (writelog(), cleanexit(), safesource()) declare -rg RUN_VIRT_INCLUDE_DIR="$(dirname $SELF)/run-virt-includes" @@ -78,7 +78,7 @@ if ! isset PLUGIN_FEATURES || ! is_function run_plugin; then writelog "Bad plugin '$PLUGIN_ID': either it did not set PLUGIN_FEATURES or did not define 'run_plugin'." EXIT_TYPE="internal" EXIT_REASON="Fehlerhaftes vmchooser plugin: '$PLUGIN_ID'." cleanexit 1 fi -writelog "Requested features:\t\t${PLUGIN_FEATURES}" +writelog "Requested features:\t${PLUGIN_FEATURES}" # Source the *.inc files in run-virt.d for FILE in ${VMCHOOSER_DIR}/run-virt.d/*.inc; do |