git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitcce49946cfaf89f7e9a57758bc21844de5181680
parentb67e39ff01
authorLucas Galante <[email protected]>
date2026-07-05 19:32
Add gpu-watcher script and systemd service to main repo install target

 Makefile                    |  3 +++
 scripts/gpu-watcher         | 26 ++++++++++++++++++++++++++
 scripts/gpu-watcher.service | 11 +++++++++++
 3 files changed, 40 insertions(+)

diff --git a/Makefile b/Makefile
index e774cca..b467b97 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,9 @@ install: build
 	fi
 	install -m 755 scripts/cce-desktop-menu ~/.local/bin/cce-desktop-menu
 	install -m 755 scripts/cce-app-menu ~/.local/bin/cce-app-menu
+	install -m 755 scripts/gpu-watcher ~/.local/bin/gpu-watcher
+	mkdir -p ~/.config/systemd/user
+	install -m 644 scripts/gpu-watcher.service ~/.config/systemd/user/gpu-watcher.service
 
 run:
 	cargo run --bin cce-fx
diff --git a/scripts/gpu-watcher b/scripts/gpu-watcher
new file mode 100644
index 0000000..076ebfe
--- /dev/null
+++ b/scripts/gpu-watcher
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+# Make sure we have a log of the startup
+echo "NVIDIA GPU Wedge Watcher started at $(date)"
+
+# Ensure DBus connection is available for notify-send when run under systemd
+if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
+    export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
+fi
+
+# Watch kernel logs event-driven
+journalctl --follow -k -o cat | while read -r line; do
+    if [[ "$line" == *"fallen off the bus"* ]]; then
+        echo "ALERT: GPU fell off the bus: $line"
+        notify-send -u critical -i "dialog-error" \
+            "NVIDIA GPU Failure" \
+            "GPU has fallen off the PCIe bus. A system reboot is required."
+    elif [[ "$line" == *"NVRM: Xid"* ]]; then
+        # Try to extract the Xid number
+        xid=$(echo "$line" | grep -o 'Xid [0-9]\+' | cut -d' ' -f2)
+        echo "ALERT: GPU Xid error detected: Xid $xid"
+        notify-send -u critical -i "dialog-warning" \
+            "NVIDIA GPU Xid $xid Error" \
+            "Driver reported a critical error.\nDetails: $line"
+    fi
+done
diff --git a/scripts/gpu-watcher.service b/scripts/gpu-watcher.service
new file mode 100644
index 0000000..25e1b3d
--- /dev/null
+++ b/scripts/gpu-watcher.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=NVIDIA GPU Wedge and Xid Error Watcher
+After=graphical-session.target
+
+[Service]
+ExecStart=%h/.local/bin/gpu-watcher
+Restart=always
+RestartSec=5
+
+[Install]
+WantedBy=default.target