From af09a5cf8ad76b156e4a48d77ecfada9c6402325 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 14 Dec 2023 12:11:16 +0100 Subject: [idleaction] Log shutdown/reboot/.. details in exam mode We have a report about spurious reboots of machines in exam mode while in use, so try to rule out that this was caused by idle-daemon logic by logging any such action it would perform through a wrapper script. --- .../data/opt/openslx/scripts/idle-daemon-launcher | 1 + .../openslx/scripts/idle-daemon-trigger-wrapper | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-trigger-wrapper diff --git a/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-launcher b/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-launcher index 640ef9fb..62a919ee 100755 --- a/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-launcher +++ b/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-launcher @@ -29,6 +29,7 @@ if [ -z "${SLX_EXAM}" ]; then else # Exam mode active CMD="$CMD --min-idle 7200" # Ignore schedule if idle time is lower than 2h + CMD="$CMD --cmd /opt/openslx/scripts/idle-daemon-trigger-wrapper" # Use wrapper for slxlog # Add additional times -- We might miss tightly scheduled ones because of --min-idle if [ -n "$SLX_SHUTDOWN_SCHEDULE" ]; then SLX_SHUTDOWN_SCHEDULE="$SLX_SHUTDOWN_SCHEDULE 23:00 4:00" diff --git a/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-trigger-wrapper b/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-trigger-wrapper new file mode 100755 index 00000000..0aa681ff --- /dev/null +++ b/core/modules/idleaction/data/opt/openslx/scripts/idle-daemon-trigger-wrapper @@ -0,0 +1,41 @@ +#!/bin/bash + +# Executed by the idle-daemon with the desired action: +# reboot, poweroff, kexec, suspend +# Normally this is done directly by the idle-daemon, but +# we use this wrapper script in exam mode so we can report +# to slx-admin what is happening, and provide idle-daemon +# logs so we can reconstruct why, hopefully. + +[ "$UID" != 0 ] && exit 1 + +action="$1" + +case "$action" in +reboot|poweroff|suspend|kexec) + sleep 1 + conf=$( mktemp || echo "/tmp/id-$RANDOM-$RANDOM" ) + { + echo "Command:" + ps aux | grep -F idle-daemon + echo "Config:" + grep -F -e TIMEOUT= -e SCHEDULE= /opt/openslx/config + echo "Journal:" + journalctl -u idle-daemon.service --no-pager + echo "Now:" + date + } &> "$conf" + slxlog -s "exam-idledaemon" "Exam mode: Executing action '$action'" "$conf" + if [ "$action" = kexec ]; then + systemctl --no-block isolate kexec.target + else + systemctl --no-block "$action" + fi + ;; +*) + slxlog "exam-idledaemon" "Exam mode: Unknown action '$action' from idle-daemon" + exit 1 + ;; +esac + +exit 0 -- cgit v1.2.3-55-g7522