diff options
author | Simon Rettberg | 2016-01-14 00:05:18 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-01-14 00:05:18 +0100 |
commit | 9c14140ec9d487aac7be949beabe957e9684959a (patch) | |
tree | 0c64a2afe5b6f44d7f1cbda5d26674762a2b8de9 | |
parent | [kdm*] Don't use hard reboot/poweroff as it's not necessary (diff) | |
download | tm-scripts-9c14140ec9d487aac7be949beabe957e9684959a.tar.gz tm-scripts-9c14140ec9d487aac7be949beabe957e9684959a.tar.xz tm-scripts-9c14140ec9d487aac7be949beabe957e9684959a.zip |
[idleaction] Warn user about scheduled reboot/poweroff and delay by 5 minutes
4 files changed, 80 insertions, 15 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 b0e67e4f..b7617940 100755 --- a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script +++ b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-cron_script @@ -29,7 +29,7 @@ if [ -n "${SLX_LOGOUT_TIMEOUT}" ] && [ "${SLX_LOGOUT_TIMEOUT}" -gt 0 ]; then if [ -n "$DISPLAY" ]; then # Seems to be x11 IDLE= - export XAUTHORITY=$(ps a | grep -v grep | grep -o -- '-auth.*$' | awk '{print $2}') + export XAUTHORITY=$(ps a | grep " $DISPLAY " | grep -o -- '-auth.*$' | grep -m1 -v grep | awk '{print $2}') [ -n "$XAUTHORITY" ] && [ -f "$XAUTHORITY" ] && IDLE=$(xprintidle) # Now that we have DISPLAY and XAUTHORITY set, xprintidle should work if [ -z "$IDLE" ]; then @@ -122,7 +122,7 @@ if [ -n "$SLX_SHUTDOWN_SCHEDULE" -o -n "$SLX_REBOOT_SCHEDULE" ] && [ ! -e "$CRON [ -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" + echo "$MINUTE $HOUR * * * root /opt/openslx/scripts/idleaction-scheduled_action poweroff" >> "$CRONFILE" done # do it again for SLX_REBOOT_SCHEDULE for time in $SLX_REBOOT_SCHEDULE; do @@ -131,7 +131,7 @@ if [ -n "$SLX_SHUTDOWN_SCHEDULE" -o -n "$SLX_REBOOT_SCHEDULE" ] && [ ! -e "$CRON [ -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_reboot" >> "$CRONFILE" + echo "$MINUTE $HOUR * * * root /opt/openslx/scripts/idleaction-scheduled_action reboot" >> "$CRONFILE" done touch "/etc/cron.d" # Aufs bug where it won't update dir mtime when creating the file within fi diff --git a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action new file mode 100755 index 00000000..6ef6969c --- /dev/null +++ b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_action @@ -0,0 +1,77 @@ +#!/bin/ash + +if [ "$(whoami)" != "root" ]; then + echo "Only root can call this" + exit 1 +fi + +if [ $# -ne 1 ]; then + echo "$0 <reboot|poweroff>" + exit 1 +fi + +MODE=$1 + +if [ "$MODE" != "reboot" ] && [ "$MODE" != "poweroff" ]; then + slxlog "idleaction-failed-call" "Invalid call to idleaction-scheduled_action. Mode '$MODE' unknown." + exit 1 +fi + +NUM=$(who | wc -l) +[ "$NUM" = "0" ] && $MODE # Easy way out - machine is idle + +# Someone logged in +for MINUTES in 5 X X X X X X X 3 X X X 2 X X X 1 X X X; do + NUM=$(who | wc -l) + [ "$NUM" = "0" ] && break + if [ "$MINUTES" != "X" ]; then + USERS=0 + if [ "$MODE" = "reboot" ]; then + MESSAGE="Das System wird in $MINUTES Minute(n) neugestartet, bitte beenden Sie Ihre Sitzung. +The system will reboot in $MINUTES minute(s). Please save your work and end the session." + else + MESSAGE="Dieser Rechner wird in $MINUTES Minute(n) abgeschaltet, bitte beenden Sie Ihre Sitzung. +The system will power off in $MINUTES minute(s). Please save your work and end the session." + fi + for d in $(who | awk '{print $2}' | sort -u); do + if [ "${d:0:1}" = ":" ]; then + # X11 + export DISPLAY=$d + export XAUTHORITY=$(ps a | grep " $DISPLAY " | grep -o -- '-auth.*$' | grep -m1 -v grep | awk '{print $2}') + # TODO: Don't look... We need to pick a proper util for this + /opt/openslx/cups/printergui --error "$MESSAGE" & + unset DISPLAY XAUTHORITY + USERS=$(( $USERS + 1 )) + elif [ "${d:0:3}" = "tty" ]; then + # Regular tty + cat > "/dev/$d" <<-EOF + * + *************************** + $MESSAGE + *************************** + * + EOF + USERS=$(( $USERS + 1 )) + elif [ "${d:0:3}" = "pts" ]; then + # pts - xterm or ssh session + cat > "/dev/pts/${d:3}" <<-EOF + * + *************************** + $MESSAGE + *************************** + * + EOF + USERS=$(( $USERS + 1 )) + fi + done + FILE=$(mktemp) + who > "$FILE" + slxlog "idleaction-busy" "Postponed $MODE ($MINUTES minutes max.) - $USERS user(s) still active" + sleep 1 + rm -- "$FILE" + fi + sleep 15 +done + +$MODE + diff --git a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff deleted file mode 100755 index 742189db..00000000 --- a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_poweroff +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/ash - -# TODO: Warn user, wait 5 minutes, etc... - -poweroff - diff --git a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_reboot b/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_reboot deleted file mode 100755 index 6c13601f..00000000 --- a/remote/modules/idleaction/data/opt/openslx/scripts/idleaction-scheduled_reboot +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/ash - -# TODO: Warn user, wait 5 minutes, etc... - -reboot - |