diff options
Diffstat (limited to 'remote/modules/idleaction/data/opt/openslx')
4 files changed, 82 insertions, 20 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 9a9bdf1c..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 @@ -95,7 +95,7 @@ if [ -n "${SLX_SHUTDOWN_TIMEOUT}" ] && [ "${SLX_SHUTDOWN_TIMEOUT}" -gt 0 ] && [ [ "$IDLE" -gt "$NOW" ] && IDLE="$NOW" IDLE=$(( $NOW - $IDLE )) if [ "$IDLE" -gt "$SLX_SHUTDOWN_TIMEOUT" ]; then - poweroff -nf # TODO: Do proper shutdown once it works reliably + poweroff fi fi @@ -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,11 +131,8 @@ 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 - ( - sleep 20 - systemctl restart cron - ) & + 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 5b5acda2..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 -nf - 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 fa3adf65..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... - -echo 'b' > /proc/sysrq-trigger - |
