diff options
author | Simon Rettberg | 2013-12-22 13:13:08 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-12-22 13:13:08 +0100 |
commit | 7797ba470cd68af17ad73ca097c84ca0d9d3b957 (patch) | |
tree | 3f64fd1a64c4115eb7c9097faac7205212119a9c | |
parent | [rfs-stage31] init: Remove LD_LIBRARY_PATH, set up and clean some other vars ... (diff) | |
download | tm-scripts-7797ba470cd68af17ad73ca097c84ca0d9d3b957.tar.gz tm-scripts-7797ba470cd68af17ad73ca097c84ca0d9d3b957.tar.xz tm-scripts-7797ba470cd68af17ad73ca097c84ca0d9d3b957.zip |
[idleaction] Add scheduled shutdown functionality (still WIP)
-rwxr-xr-x | remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script | 24 | ||||
-rwxr-xr-x | remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff | 6 |
2 files changed, 28 insertions, 2 deletions
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 + |