Skip to content

Commit b3b73de

Browse files
authored
Add idle-logout hook (#40)
* also use loginctl to terminate idle user sessions
1 parent 6178919 commit b3b73de

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

systemd/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ fi
3131
/usr/bin/cp "$ROOT_DIR/system/codam-web-greeter-fetcher.sh" /usr/share/codam/codam-web-greeter-fetcher.sh
3232
/usr/bin/cp "$ROOT_DIR/system/codam-web-greeter-idler.sh" /usr/share/codam/codam-web-greeter-idler.sh
3333
/usr/bin/chmod 700 /usr/share/codam/codam-web-greeter-idler.sh
34+
/usr/bin/cp "$ROOT_DIR/system/codam-web-greeter-idler-hook.sh" /usr/share/codam/codam-web-greeter-idler-hook.sh
35+
/usr/bin/chmod 500 /usr/share/codam/codam-web-greeter-idler-hook.sh
3436
/usr/bin/cp "$ROOT_DIR/user/codam-web-greeter-init.sh" /usr/share/codam/codam-web-greeter-init.sh
3537
/usr/bin/cp "$ROOT_DIR/user/codam-web-greeter-cleanup.sh" /usr/share/codam/codam-web-greeter-cleanup.sh
3638

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
#
3+
# This script is executed after a user has been logged out due to inactivity by the codam-web-greeter-idler.sh script.
4+
# It receives the following arguments:
5+
# $1: username of the user that was logged out
6+
# $2: idle time in milliseconds
7+
# $3: time since screen was locked in milliseconds
8+
# $4: max idle time in milliseconds
9+
#
10+
# You can use this script to perform custom actions, such as logging, notifications, coalition system integration, etc.
11+
# It can be easily customized using the Ansible codam.webgreeter role.
12+
#
13+
# Example: Log the logout event to a file
14+
# LOGFILE="/var/log/codam-web-greeter-idle-logout.log"
15+
# echo "$(date): User '$1' was logged out due to inactivity (idletime: $2 ms, time_since_lock: $3 ms, max_idle_time: $4 ms)" >> "$LOGFILE"

systemd/system/codam-web-greeter-idler.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ while IFS= read -r line; do
4343
MAX_IDLE_TIME_MINUTES=$((42))
4444
MAX_IDLE_TIME=$((MAX_IDLE_TIME_MINUTES * 60 * 1000))
4545
if [ "$IDLE_TIME" -gt "$MAX_IDLE_TIME" ] || [ "$TIME_SINCE_LOCK" -gt "$MAX_IDLE_TIME" ]; then
46-
/usr/bin/echo "Session for user $USERNAME has been idle for over 42 minutes (idletime $IDLE_TIME ms, time_since_lock $TIME_SINCE_LOCK ms), forcing logout now by restarting lightdm"
47-
/usr/bin/systemctl restart lightdm
46+
/usr/bin/echo "Session for user $USERNAME has been idle for over 42 minutes (idletime $IDLE_TIME ms, time_since_lock $TIME_SINCE_LOCK ms), forcing logout now"
47+
/usr/bin/loginctl terminate-user "$USERNAME" && /usr/bin/systemctl restart lightdm
48+
# Run the hook script
49+
if [ -f "/usr/share/codam/codam-web-greeter-idler-hook.sh" ]; then
50+
/usr/bin/echo "Running custom codam-web-greeter post-idle logout hook script for user $USERNAME"
51+
if ! /bin/bash /usr/share/codam/codam-web-greeter-idler-hook.sh "$USERNAME" "$IDLE_TIME" "$TIME_SINCE_LOCK" "$MAX_IDLE_TIME"; then
52+
/usr/bin/echo "Warning: custom codam-web-greeter post-idle logout hook script failed for user $USERNAME" >&2
53+
fi
54+
fi
4855
else
4956
/usr/bin/echo "Session for $USERNAME has been idle for $((IDLE_TIME / 1000)) seconds, screen locked for $((TIME_SINCE_LOCK / 1000)) seconds"
5057
fi

0 commit comments

Comments
 (0)