From 7797ba470cd68af17ad73ca097c84ca0d9d3b957 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 22 Dec 2013 13:13:08 +0100 Subject: [idleaction] Add scheduled shutdown functionality (still WIP) --- .../opt/openslx/scripts/idleaction-cron_script | 24 ++++++++++++++++++++-- .../openslx/scripts/idleaction-scheduled_poweroff | 6 ++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff (limited to 'remote/modules') diff --git a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script index c59d0f3b..9c3f2d83 100755 --- a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script +++ b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script @@ -4,6 +4,7 @@ # If existent, no session is open. Will contain timestamp of last activity. # If not existent, at least one user is logged in +CRONFILE="/etc/cron.d/idleaction-shutdown_schedule" IDLEHINT="/dev/shm/idlehint" NOW=$(date +%s) @@ -16,7 +17,7 @@ if [ -n "${SLX_LOGOUT_TIMEOUT}" ]; then # get all sessions SESSIONS=$(loginctl | awk '{print $1}') if [ -n "$SESSIONS" ]; then - TMP=$(/dev/shm/idlecheck.tmp) + TMP="/dev/shm/idlecheck.tmp" # Iterate over sessions for ses in $SESSIONS; do # Get information @@ -93,5 +94,24 @@ fi # # 3) Check for hard scheduled shutdown # -# TODO +# A cron file is created dynamically here so there's everything +# in one module and you don't need to repack config.tgz + +invalid_time () +{ + slxlog "idleaction-schedule" "Invalid shutdown time: '$time'. Expected HH:MM format." + return 0 +} + +if [ -n "$SLX_SHUTDOWN_SCHEDULE" ] && [ ! -e "$CRONFILE" ]; then + echo "# OpenSLX: Trigger poweroff at certain time of day" > "$CRONFILE" + for time in $SLX_SHUTDOWN_SCHEDULE; do + HOUR=${time%%:*} + MINUTE=${time##*:} + [ -z "$HOUR$MINUTE" ] && invalid_time && continue + [ "$HOUR" -lt 0 -o "$HOUR" -gt 23 ] && invalid_time && continue + [ "$MINUTE" -lt 0 -o "$MINUTE" -gt 59 ] && invalid_time && continue + echo "$MINUTE $HOUR * * * root /opt/openslx/scripts/idleaction-scheduled_poweroff" >> "$CRONFILE" + done +fi diff --git a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff new file mode 100755 index 00000000..5b5acda2 --- /dev/null +++ b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff @@ -0,0 +1,6 @@ +#!/bin/ash + +# TODO: Warn user, wait 5 minutes, etc... + +poweroff -nf + -- cgit v1.2.3-55-g7522