From b41f05f8bfdd0cb232d70dd0f4f6820cbfa3af91 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 29 Jan 2024 12:28:01 +0100 Subject: [run-virt] Split mounting of /tmp/virt into own service --- .../data/etc/systemd/system/gather-hw-info.service | 3 +- .../data/etc/systemd/system/run-virt-env.service | 2 ++ .../etc/systemd/system/run-virt-tmpdir.service | 9 +++++ .../data/opt/openslx/scripts/systemd-run_virt_env | 31 ------------------ .../opt/openslx/scripts/systemd-run_virt_tmpdir | 38 ++++++++++++++++++++++ 5 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 core/modules/run-virt/data/etc/systemd/system/run-virt-tmpdir.service create mode 100755 core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_tmpdir (limited to 'core') diff --git a/core/modules/hardware-stats/data/etc/systemd/system/gather-hw-info.service b/core/modules/hardware-stats/data/etc/systemd/system/gather-hw-info.service index 4d782252..1d7d1ff8 100644 --- a/core/modules/hardware-stats/data/etc/systemd/system/gather-hw-info.service +++ b/core/modules/hardware-stats/data/etc/systemd/system/gather-hw-info.service @@ -3,7 +3,8 @@ Description=Gather hardware information about this machine Wants=tmp.target After=tmp.target # Because we might mount something to /tmp/virt there, which we use for ID44 calculation -After=run-virt-env.service +After=run-virt-tmpdir.service +DefaultDependencies=no [Service] Type=oneshot diff --git a/core/modules/run-virt/data/etc/systemd/system/run-virt-env.service b/core/modules/run-virt/data/etc/systemd/system/run-virt-env.service index 2c602076..285fffb4 100644 --- a/core/modules/run-virt/data/etc/systemd/system/run-virt-env.service +++ b/core/modules/run-virt/data/etc/systemd/system/run-virt-env.service @@ -3,6 +3,8 @@ Description=Sets up the virtualization environment Before=graphical.target system-check.service After=systemd-tmpfiles-setup.service bridge-additional-nics.service Wants=systemd-tmpfiles-setup.service system-check.service bridge-additional-nics.service +Wants=run-virt-tmpdir.service +After=run-virt-tmpdir.service DefaultDependencies=no [Service] diff --git a/core/modules/run-virt/data/etc/systemd/system/run-virt-tmpdir.service b/core/modules/run-virt/data/etc/systemd/system/run-virt-tmpdir.service new file mode 100644 index 00000000..0b2fecfc --- /dev/null +++ b/core/modules/run-virt/data/etc/systemd/system/run-virt-tmpdir.service @@ -0,0 +1,9 @@ +[Unit] +Description=Sets up /tmp/virt virtualization scratch space +After=tmp.target network.target +DefaultDependencies=no + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/opt/openslx/scripts/systemd-run_virt_tmpdir diff --git a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env index c3fc378e..04c1aff5 100755 --- a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env +++ b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_env @@ -41,37 +41,6 @@ for DIR in /tmp/virt /var/log/samba /run/samba; do fi done -# check if a fallback share is set as SLX_VM_TMP_SOURCE -if [ -n "${SLX_VM_TMP_SOURCE}" ]; then - LOG=$(mktemp) - # use SLX_VM_TMP_TYPE and SLX_VM_TMP_OPTS, if set - for TRY in 1 2 3 STOP; do - [ "x$TRY" = "xSTOP" ] && break - if [ -n "${SLX_VM_TMP_TYPE}" ] && [ -n "${SLX_VM_TMP_OPTS}" ]; then - mount -t "${SLX_VM_TMP_TYPE}" -o "${SLX_VM_TMP_OPTS}" "${SLX_VM_TMP_SOURCE}" /tmp/virt - elif [ -n "${SLX_VM_TMP_TYPE}" ]; then - mount -t "${SLX_VM_TMP_TYPE}" "${SLX_VM_TMP_SOURCE}" /tmp/virt - elif [ -n "${SLX_VM_TMP_OPTS}" ]; then - mount -o "${SLX_VM_TMP_OPTS}" "${SLX_VM_TMP_SOURCE}" /tmp/virt - else - mount "${SLX_VM_TMP_SOURCE}" /tmp/virt - fi - RET=$? - [ "$RET" = "0" ] && break - sleep $TRY - done > "$LOG" 2>&1 - if [ "$RET" -ne "0" ]; then - if [ -s "$LOG" ]; then - slxlog --delete "mount-vm-tmp-fail" "Mounting of '${SLX_VM_TMP_SOURCE}' failed." "$LOG" - else - slxlog "mount-vm-tmp-fail" "Mounting of '${SLX_VM_TMP_SOURCE}' failed." - rm -f -- "$LOG" - fi - fi -fi - -chmod a+rwxt /tmp/virt - ################################################################################ echo "Determine host's hardware configuration" ################################################################################ diff --git a/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_tmpdir b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_tmpdir new file mode 100755 index 00000000..e5fb324a --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/scripts/systemd-run_virt_tmpdir @@ -0,0 +1,38 @@ +#!/bin/ash + +mkdir -p "/tmp/virt" + +. /opt/openslx/config + +# check if a fallback share is set as SLX_VM_TMP_SOURCE +RET=0 +if [ -n "${SLX_VM_TMP_SOURCE}" ]; then + LOG=$(mktemp) + # use SLX_VM_TMP_TYPE and SLX_VM_TMP_OPTS, if set + for TRY in 1 2 3 STOP; do + [ "$TRY" = "STOP" ] && break + if [ -n "${SLX_VM_TMP_TYPE}" ] && [ -n "${SLX_VM_TMP_OPTS}" ]; then + mount -t "${SLX_VM_TMP_TYPE}" -o "${SLX_VM_TMP_OPTS}" "${SLX_VM_TMP_SOURCE}" /tmp/virt + elif [ -n "${SLX_VM_TMP_TYPE}" ]; then + mount -t "${SLX_VM_TMP_TYPE}" "${SLX_VM_TMP_SOURCE}" /tmp/virt + elif [ -n "${SLX_VM_TMP_OPTS}" ]; then + mount -o "${SLX_VM_TMP_OPTS}" "${SLX_VM_TMP_SOURCE}" /tmp/virt + else + mount "${SLX_VM_TMP_SOURCE}" /tmp/virt + fi + RET=$? + [ "$RET" = "0" ] && break + sleep $TRY + done > "$LOG" 2>&1 + if [ "$RET" -ne "0" ]; then + if [ -s "$LOG" ]; then + slxlog --sync --delete "mount-vm-tmp-fail" "Mounting of '${SLX_VM_TMP_SOURCE}' failed." "$LOG" + else + slxlog --sync "mount-vm-tmp-fail" "Mounting of '${SLX_VM_TMP_SOURCE}' failed." + rm -f -- "$LOG" + fi + fi +fi + +chmod a+rwxt /tmp/virt +exit "$RET" -- cgit v1.2.3-55-g7522