diff options
| author | Simon Rettberg | 2016-01-07 16:19:27 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2016-01-07 16:19:27 +0100 |
| commit | 3467aef515acaac01760c3e92cc3db09dc474d96 (patch) | |
| tree | 7085c113d6c35079d804728e0399f83846275d97 /remote/modules/run-virt/data/opt | |
| parent | [beamergui,udhcpc] Don't create pointless files in /tmp (diff) | |
| download | tm-scripts-3467aef515acaac01760c3e92cc3db09dc474d96.tar.gz tm-scripts-3467aef515acaac01760c3e92cc3db09dc474d96.tar.xz tm-scripts-3467aef515acaac01760c3e92cc3db09dc474d96.zip | |
[run-virt,vmware,vbox] Unify directory layout in /tmp, better cleanup
Diffstat (limited to 'remote/modules/run-virt/data/opt')
5 files changed, 19 insertions, 17 deletions
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc index 9525a290..f0aae889 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_variables.inc @@ -5,6 +5,10 @@ VMCHOOSER_DIR="/opt/openslx/vmchooser" VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config" LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" +TMPDIR="/tmp/virt/$(whoami)" +USER="$(whoami)" + +readonly VMCHOOSER_DIR VMCHOOSER_CONF_DIR LOGFILE TMPDIR USER # include general configuration from vmchooser [ -f "$VMCHOOSER_CONF_DIR/vmchooser.conf" ] && . "$VMCHOOSER_CONF_DIR/vmchooser.conf" @@ -12,3 +16,6 @@ LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" [ -f "$VMCHOOSER_CONF_DIR/virtualization.conf" ] && . "$VMCHOOSER_CONF_DIR/virtualization.conf" # Load general openslx config [ -f "/opt/openslx/config" ] && . "/opt/openslx/config" +# Create temp dir +mkdir -p "$TMPDIR" # TODO error out if failed + diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc index 806423cc..e84486cf 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_image_access.inc @@ -14,13 +14,11 @@ elif [ -z "$SLX_DNBD3_SERVERS" ] || [ "x$SLX_VM_DNBD3" != "xyes" ]; then writelog "Can't use dnbd3 as no servers are given in config, or SLX_VM_DNBD3 is not set to yes" else # Mount path for images mounted with dnbd3-fuse - dnbd3_fuse_mount_point="/tmp/virt/${USER}.fuse" + dnbd3_fuse_mount_point="$TMPDIR/dnbd3fuse.mnt" mkdir -p "${dnbd3_fuse_mount_point}" - # try to unmount first - fusermount -u "${dnbd3_fuse_mount_point}" # start dnbd3-fuse in subshell ( - tmplog="$(mktemp)" + tmplog="$TMPDIR/dnbd3fuse.log" [ -z "$tmplog" ] && tmplog="/tmp/dnbd3-fuse.$$.$RANDOM.$USER" dnbd3-fuse -f -o allow_other,max_readahead=262144 -h "$SLX_DNBD3_SERVERS" -i "${imgrelpath}" "${dnbd3_fuse_mount_point}" > "$tmplog" 2>&1 RET=$? diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc index ab010722..ee0b2c70 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc @@ -3,7 +3,6 @@ ##################################### QUEUE="STANDARD" # This has to match the queue you configured in your VM -USER="$(whoami)" SPOOLDIR= ### Disabled: 100megs is not enough, some jobs are HUGE, try to use temp which should be on disk @@ -15,7 +14,7 @@ SPOOLDIR= # If failed, try to fall back to /tmp if [ -z "${SPOOLDIR}" ] || [ ! -w "${SPOOLDIR}/${QUEUE}" ]; then - SPOOLDIR="/tmp/printergui-${USER}-$$-${RANDOM}" + SPOOLDIR="${TMPDIR}/printergui-${RANDOM}" rm -rf -- "${SPOOLDIR}" if ! mkdir -p "${SPOOLDIR}/${QUEUE}"; then slxlog "virt-spooldir" "Could not create spool directory ($SPOOLDIR) for $USER - printing will not work!" diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc index f20b799f..b85bb32c 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/vmchooser_runvirt_functions.inc @@ -14,24 +14,22 @@ writelog() { # Clean exit will be called at the end of vmchooser-run_virt cleanexit() { sleep 1 - # remove config dirs when exit - if echo "${RMDIRS}" 2>/dev/null | grep -q "${xmlvirt}"; then - writelog "${xmlvirt} exited. Cleaning up... \c" -# rm -rf -- ${RMDIRS} >/dev/null 2>&1 - writelog "done" - fi # Ummount dnbd3-fuse if [ -n "$dnbd3_fuse_mount_point" ] && [ -e "$dnbd3_fuse_mount_point/img" ]; then - for timeout in 1 1 2; do + for timeout in 1 1 1 FAIL; do fusermount -u "$dnbd3_fuse_mount_point" && break writelog "dnbd3 still busy...." + [ "$timeout" = "FAIL" ] && break sleep "$timeout" done fi # Kill LPD - [ -n "$PID_LPD" ] && kill "$PID_LPD" - # Remove spool directory for printjobs from VM - [ -n "${SPOOLDIR}" ] && rm -rf -- "${SPOOLDIR}" + [ -n "${PID_LPD}" ] && kill "${PID_LPD}" + + # If we're not in debug mode, remove all temporary files + if [ -n "${TMPDIR}" -a -z "$SLX_DEBUG" ]; then + rm -rf -- "${TMPDIR}" + fi [ $# -gt 0 ] && exit "$1" exit 129 # No exit code was given :/ diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt b/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt index 7d83844e..8e1bbd0d 100755 --- a/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt +++ b/remote/modules/run-virt/data/opt/openslx/scripts/vmchooser-run_virt @@ -23,7 +23,7 @@ RUNVIRTINCLUDEDIR=/opt/openslx/scripts/includes xmlfile="$1" # Functions needed by vmchooser-run_virt (writelog(), cleanexit(), rv_clean_string()) -source ${RUNVIRTINCLUDEDIR}/vmchooser_runvirt_functions.inc && trap cleanexit SIGINT SIGTERM +source ${RUNVIRTINCLUDEDIR}/vmchooser_runvirt_functions.inc && trap 'trap "" SIGINT SIGTERM; cleanexit' SIGINT SIGTERM # Define default dirs / get configs source ${RUNVIRTINCLUDEDIR}/set_runvirt_variables.inc # Function to detect whether we can use the new way (vmx via http) or the old way (legacy): |
