diff options
| author | Jonathan Bauer | 2016-01-08 14:28:46 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2016-01-08 14:28:46 +0100 |
| commit | 7106ee223592a0591e267daa7f71162e4ad658b0 (patch) | |
| tree | 490d793b56807918cbd6197086b5251d08a18145 /remote/modules/run-virt | |
| parent | [exam] renamed safe-mode service to 'exam.service' and removed unneeded code (diff) | |
| parent | [run-virt] openslx.exe: Hide console, re-set logoff caption periodically (diff) | |
| download | tm-scripts-7106ee223592a0591e267daa7f71162e4ad658b0.tar.gz tm-scripts-7106ee223592a0591e267daa7f71162e4ad658b0.tar.xz tm-scripts-7106ee223592a0591e267daa7f71162e4ad658b0.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/tm-scripts
Diffstat (limited to 'remote/modules/run-virt')
8 files changed, 50 insertions, 30 deletions
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc index b71d43fc..11a21832 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc @@ -7,13 +7,6 @@ writelog "Detecting current/legacy mode ..." -TMPDIR=$(mktemp -d -p /tmp/virt) -ERR=$? -if "$ERR"; then - writelog "Could not mkdir tempdir, using /tmp." - TMPDIR=/tmp -fi - # First, let's try to extract an imguuid from xmlfile: IMGUUID=$(grep -io '<uuid param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') 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..5215eb2d 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" +USER="$(whoami)" +TMPDIR="/tmp/virt/${USER}/$$" + +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): diff --git a/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe b/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe Binary files differindex eec60c3a..a1616798 100755 --- a/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe +++ b/remote/modules/run-virt/data/opt/openslx/vmchooser/data/openslx.exe diff --git a/remote/modules/run-virt/winres.c b/remote/modules/run-virt/winres.c index 1af91d33..a9037b61 100644 --- a/remote/modules/run-virt/winres.c +++ b/remote/modules/run-virt/winres.c @@ -18,7 +18,12 @@ static int setResolution(); static int muteSound(); static int setShutdownText(); -int main(int argc, char ** argv) +static void CALLBACK resetShutdown(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) +{ + setShutdownText(); +} + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { int ret; /* @@ -41,14 +46,34 @@ int main(int argc, char ** argv) OSVERSIONINFO version; version.dwOSVersionInfoSize = sizeof(version); BOOL retVer = GetVersionEx(&version); + // Set resolution to what HOSTRES.TXT says setResolution(); + // Mute sound by default if (retVer && version.dwMajorVersion >= 6) muteSound(); - ret = setShutdownText(); - char buffer[100]; - snprintf(buffer, 100, "Returned %d", ret); - if (ret != 0) - MessageBoxA(0, buffer, "Set caption", 0); + // Shutdown button label + if (retVer && version.dwMajorVersion == 6 && version.dwMinorVersion == 1) { + // Only on Windows 7 + char buffer[100]; + ret = setShutdownText(); + if (ret != 0) { + snprintf(buffer, 100, "Returned %d", ret); + MessageBoxA(0, buffer, "Set caption", 0); + } + // Repeatedly set caption + UINT_PTR tRet = SetTimer(NULL, 0, 5000, (TIMERPROC)&resetShutdown); + if (tRet == 0) { + snprintf(buffer, 100, "Could not create timer: %d", (int)tRet); + MessageBoxA(0, buffer, "SetTimer", 0); + return 0; + } + // Message pump + MSG Msg; + while(GetMessage(&Msg, NULL, 0, 0) > 0) { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } + } return 0; } |
