More updates to the watchdog.
This commit is contained in:
+28
-5
@@ -19,6 +19,7 @@ timeoutSeconds=2 # Consider i3 locked if it doesn't respond within 2 seconds
|
|||||||
pidFile="${HOME}/.config/i3/i3_watchdog.pid"
|
pidFile="${HOME}/.config/i3/i3_watchdog.pid"
|
||||||
logFile="/tmp/i38-i3-watchdog-${UID}.log"
|
logFile="/tmp/i38-i3-watchdog-${UID}.log"
|
||||||
maxLogBytes=262144
|
maxLogBytes=262144
|
||||||
|
displayFailureLimit=3
|
||||||
|
|
||||||
rotate_log() {
|
rotate_log() {
|
||||||
local logSize
|
local logSize
|
||||||
@@ -53,6 +54,20 @@ check_health() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_x_display() {
|
||||||
|
timeout 1 xdotool getmouselocation > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_pid_file() {
|
||||||
|
local recordedPid
|
||||||
|
|
||||||
|
[[ -r "$pidFile" ]] || return 0
|
||||||
|
read -r recordedPid < "$pidFile"
|
||||||
|
if [[ "$recordedPid" == "$$" ]]; then
|
||||||
|
rm -f -- "$pidFile"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Kill any existing watchdog instances
|
# Kill any existing watchdog instances
|
||||||
if [[ -f "$pidFile" ]]; then
|
if [[ -f "$pidFile" ]]; then
|
||||||
oldPid=$(cat "$pidFile")
|
oldPid=$(cat "$pidFile")
|
||||||
@@ -64,20 +79,28 @@ fi
|
|||||||
|
|
||||||
# Write our PID
|
# Write our PID
|
||||||
echo "$$" > "$pidFile"
|
echo "$$" > "$pidFile"
|
||||||
|
trap cleanup_pid_file EXIT
|
||||||
|
|
||||||
log_message "I38 Watchdog started (PID: $$)"
|
log_message "I38 Watchdog started (PID: $$)"
|
||||||
|
|
||||||
lastSuccessTime=$(date +%s)
|
lastSuccessTime=$(date +%s)
|
||||||
consecutiveFailures=0
|
consecutiveFailures=0
|
||||||
|
consecutiveDisplayFailures=0
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
sleep "$checkInterval"
|
sleep "$checkInterval"
|
||||||
|
|
||||||
# Check if i3 is still running
|
# An i3 restart leaves X available and launches a replacement watchdog via
|
||||||
if ! pgrep -x i3 > /dev/null; then
|
# exec_always. Only exit when the X session itself is no longer available.
|
||||||
log_message "i3 process not found - exiting watchdog"
|
if check_x_display; then
|
||||||
rm -f "$pidFile"
|
consecutiveDisplayFailures=0
|
||||||
exit 0
|
else
|
||||||
|
((consecutiveDisplayFailures++))
|
||||||
|
if [[ $consecutiveDisplayFailures -ge $displayFailureLimit ]]; then
|
||||||
|
log_message "X display unavailable for $consecutiveDisplayFailures consecutive checks - exiting watchdog"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to communicate with i3 IPC AND check X focus
|
# Try to communicate with i3 IPC AND check X focus
|
||||||
|
|||||||
Reference in New Issue
Block a user