summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc')
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc54
1 files changed, 15 insertions, 39 deletions
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 aaace562..08ab4f72 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.
@@ -120,8 +124,9 @@ add_cleanup() {
# EXIT_REASON should contain a user-friendly message to print to the user.
# it can be prefixed with err.\S+, which will serve as a translation identifier
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]
@@ -133,9 +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
@@ -174,12 +183,6 @@ cleanexit() {
ERR_TEXT="Unbekannter Fehler"
fi
- # first send the logfile (in case the user does not close the error before using magic keys e.g.)
- # for any other error types besides 'user'. Do no slxlog if we run wrapped (from /opt/openslx/scripts/vmchooser-run_virt)
- if [ "x${EXIT_TYPE}" != "xuser" ]; then
- writelog "Critical error happened in '${BASH_SOURCE[1]}:${FUNCNAME[1]}'"
- fi
-
# finally display the error
error_user "${ERR_TITLE}" "
${ERR_TEXT}
@@ -228,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}"/* )
@@ -496,33 +499,6 @@ clean_string() {
fi
}
-# Helper to check whether given directory resides in RAM, either
-# by being mounted as tmpfs or not mounted at all in which case
-# we assume the same. Returns 0 if so, 1 otherwise.
-dir_on_tmpfs() {
- local current_dir="$1"
- while [ -n "$current_dir" ]; do
- local mount_line="$(awk -v dir="$current_dir" '$2 == dir' /proc/mounts)"
- if [ -z "$mount_line" ]; then
- # check its parent directory
- current_dir="${current_dir%/*}"
- continue
- fi
- [ "x$(cut -d' ' -f3 <<< ${mount_line})" == "xtmpfs" ]
- return $?
- done
- # NG: check if / is fully backed by hard drive
- local dmsetup_state="/run/openslx/dmsetup.state"
- if [ -s "$dmsetup_state" ]; then
- local dnbd3_cow_dev="$SLX_DNBD3_DEVICE_COW"
- [ -z "$dnbd3_cow_dev" ] && dnbd3_cow_dev="/dev/mapper/root"
- grep -qE "^${dnbd3_cow_dev}\s+/\s+type=0" "$dmsetup_state"
- return $?
- fi
- # else assume old-gen were / was in RAM
- return 0
-}
-
# Helper to detect given cpu flags.
# If more than one flag is given, assume that matching
# any of them is sufficient.