summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc
blob: cc204d538f799a892b3f625dd6974e15fd0bdda2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
################################################
# Include: Sets core variables and directories #
################################################

# Check if the path to the logfile was given externally (by the wrapper)
unset WRAPPED
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"
ln -sf "$LOGFILE" "/var/log/openslx/run-virt.latest.log"

# Create temporary directory for current invocation
if check_dep mkdir && ! mkdir -p "$TMPDIR" "$CONFDIR"; then
	writelog "Could not create temporary directories for session"
	EXIT_TYPE="internal" EXIT_REASON="Konnte kein Arbeitsverzeichnis für die VM-Sitzung anlegen." cleanexit 1
fi

# Check that /tmp/virt is not in RAM.
# Either mounted directly (e.g. NFS) or backed by hdd mounted /tmp.
# This variable is empty (but set!) if /tmp/virt isn't backed at all
# else it will be non-empty (check with helper function 'notempty').
declare -g TMPDIR_NOT_RAM=
if ! dir_on_tmpfs /tmp/virt ; then
	writelog "/tmp/virt is not in RAM, will allocate more RAM to VMs."
	TMPDIR_NOT_RAM=1
	readonly TMPDIR_NOT_RAM
fi

# Get a unique VM_ID for the current invocation
get_vm_id