[Nut-upsuser] Running script right before primary shuts down

Bruce Pleat bpleat at gmail.com
Wed Jul 30 16:11:16 BST 2025


As a fellow Unifi user and starting to use NUT more thoroughly, I'm
following you here.

Background for others: Unifi routers, UDM and UDR and others, are Linux but
complex and optimized for their environment; the hardware may vary, the
software/OS is intended to run across their entire product line. It's
generally secured, but allows ssh access with special config. Far more
capable than most routers, it's "prosumer". I upgraded when my Orbi 960
setup wouldn't handle all my IoT devices and other high-end consumer gear
couldn't either - Asus etc. Unifi gear handles several hundred devices
easily, has Enterprise grade capabilities, and supports diverse and complex
deployments.

Erik,

How and where are you triggering this? Are you running this on the UDR or ?

If on UDR, I recall it's a custom Linux distro/deployment, so it prob has
idiosyncrasies.
Also, be aware of (lack of) persistence between updates.

Thinking you could run NUT monitoring on another box (Pi/similar) then ssh
in to shut the UDR down.  (This is a great use case for a Pi Zero with its
own battery backup.)


On Fri, Jun 13, 2025, 07:51 Erik De Boeck via Nut-upsuser <
nut-upsuser at alioth-lists.debian.net> wrote:

> Dear all,
>
> I would like to gracefully shut down my router (Unifi Dream Router (UDR))
> after my secondary has shut off, and before my primary shuts off (or in any
> case, before the UPS powers down). Unfortunately, the router doesn't seem
> to support NUT, but I've written a bash script, with which I can shut it
> down as user *nut*, running command *sudo -H -u nut bash -c 'bash
> /var/lib/nut/NUT-scripts/shutdownrouter.sh'*). (I assume that if any
> script is to be run, it would be run as user *nut*.)
>
> But now I'm trying to figure out how to call it, and I'm not sure...
>
>    - I assume in *upsmon.conf* there should be a line *NOTIFYFLAG FSD
>     SYSLOG+WALL+EXEC*)
>    But then I wondered whether *FSD* was maybe too late a flag?
>    - Then I assume *upssched.conf* plays a role. This is the current
>    setup:
>
>    CMDSCRIPT /etc/nut/upssched-cmd.sh
>    PIPEFN /etc/nut/upssched.pipe
>    LOCKFN /etc/nut/upssched.lock
>    AT ONBATT * START-TIMER shutdown_timer 1200
>    AT ONLINE * CANCEL-TIMER shutdown_timer
>    AT LOWBATT * EXECUTE immediate_shutdown
>    AT COMMBAD * START-TIMER commbad_timer 1200
>    AT COMMOK * CANCEL-TIMER commbad_timer
>    AT NOCOMM * EXECUTE commbad_shutdown
>    AT SHUTDOWN * EXECUTE powerdown
>
>    - Then I assume *upssched-cmd.sh* plays a role. This is the current
>    setup:
>    #!/bin/sh
>
>    case $1 in
>        shutdown_timer)
>            logger -t upssched-cmd "UPS running on battery for too long,
>    initiating shutdown"
>            /usr/sbin/upsmon -c fsd
>            ;;
>
>        immediate_shutdown)
>            logger -t upssched-cmd "UPS on battery critical, forced
>    shutdown"
>            /usr/sbin/upsmon -c fsd
>            ;;
>
>        commbad_timer)
>            logger -t upssched-cmd "UPS communication failure persists,
>    initiating shutdown"
>            /usr/sbin/upsmon -c fsd
>            ;;
>
>        commbad_shutdown)
>            logger -t upssched-cmd "UPS communication failed, initiating
>    shutdown"
>            /usr/sbin/upsmon -c fsd
>            ;;
>
>        powerdown)
>            logger -t upssched-cmd "Executing powerdown command"
>            ;;
>
>        *)
>            logger -t upssched-cmd "Unrecognized command: $1"
>            ;;
>    esac
>
> Where should I squeeze in */var/lib/nut/NUT-scripts/**shutdownrouter.*sh?
>
> Thanks for anyone's help!
>
> Kind regards,
>
> Erik
> _______________________________________________
> Nut-upsuser mailing list
> Nut-upsuser at alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsuser
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/nut-upsuser/attachments/20250730/053bfb08/attachment.htm>


More information about the Nut-upsuser mailing list