From d33d8148768f97c627cd2f077a9b713e0c54f9e4 Mon Sep 17 00:00:00 2001 From: ergosteur <1992147+ergosteur@users.noreply.github.com> Date: Thu, 6 Aug 2026 16:50:42 +0000 Subject: [PATCH] Retire nut-udev-restart.sh to unused/ It was meant to restart the NUT driver from a udev RUN+= when the UPS re-enumerates on USB, but was never wired up: 50-nut-ups.rules only sets MODE and GROUP. systemd already covers the case. nut-driver@ups.service is Restart=always with RestartUSec=15s, so the driver is retried indefinitely and reattaches to a new device node unaided. It would also not have worked reliably. systemd-udevd kills RUN+= handlers still alive when the event completes, so the backgrounded subshell could be killed mid-sleep, and upsdrvctl would run the driver outside the unit's supervision, competing with systemd's own restarts. Kept with a header recording the rule-based alternative if faster recovery is ever wanted. Co-Authored-By: Claude Opus 5 --- nut-udev-restart.sh | 14 -------------- unused/nut-udev-restart.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) delete mode 100755 nut-udev-restart.sh create mode 100755 unused/nut-udev-restart.sh diff --git a/nut-udev-restart.sh b/nut-udev-restart.sh deleted file mode 100755 index 6d97808..0000000 --- a/nut-udev-restart.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# nut-udev-restart.sh - safely restart NUT UPS driver on USB event -# Location: /opt/ergosteur/nut-udev-restart.sh - -( - # small delay so the USB device is fully settled before restarting driver - sleep 2 - - # stop and start the driver - /sbin/upsdrvctl stop - /sbin/upsdrvctl start -) & - -exit 0 diff --git a/unused/nut-udev-restart.sh b/unused/nut-udev-restart.sh new file mode 100755 index 0000000..fe93ef0 --- /dev/null +++ b/unused/nut-udev-restart.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# RETIRED. Kept for reference only. +# +# Intended to be called from a udev RUN+= when the UPS re-enumerates on USB, to +# restart the NUT driver so it reattaches to the new device node. It was never +# wired up: /etc/udev/rules.d/50-nut-ups.rules only sets MODE and GROUP. +# +# Superseded by systemd. nut-driver@ups.service is Restart=always with +# RestartUSec=15s, so the driver is already retried indefinitely and picks up a +# new device node on its own. This script would only save about 13 seconds. +# +# It would also not work reliably as written: +# +# - systemd-udevd runs RUN+= handlers in a cgroup and kills whatever is still +# alive when the event completes, so the backgrounded subshell can be killed +# mid-sleep and the restart never happens. Long-running work belongs in +# ENV{SYSTEMD_WANTS}= or RUN+="systemctl --no-block ...". +# - upsdrvctl starts the driver outside nut-driver@ups.service's supervision, +# while stopping it makes systemd spawn a competing replacement. +# +# If faster recovery is ever wanted, drop the script and put the trigger in the +# rule instead: +# +# SUBSYSTEM=="usb", ATTR{idVendor}=="0764", ATTR{idProduct}=="0601", \ +# ACTION=="add", RUN+="/usr/bin/systemctl --no-block restart nut-driver@ups.service" + +( + # small delay so the USB device is fully settled before restarting driver + sleep 2 + + # stop and start the driver + /sbin/upsdrvctl stop + /sbin/upsdrvctl start +) & + +exit 0