Skip to content

sudo upscmd -u <admin_user> <ups> test.battery.start.quick doesn't fire shutdown handler script #3431

@LoZZoL

Description

@LoZZoL

To be clear early doors, I'm sure this is a user setup issue rather than an actual bug. The problem may be that I've ended up grabbing bits of configuration from various sources on the internet, some of which may be out of date.

High level: I am expecting, when nut server detects an ONBATT signal from the USB attached UPS, that a script is executed. When the script is executed manually it works fine, but I understand that the best way to simulate the ONBATT status is to run sudo upscmd -u <admin_user> <ups> test.battery.start.quick. This gives me an OK message but never seems to run the script.

I should say that the UPS is detected and sudo upsc <ups> gives me back the status.

I've been searching around the internet on and off for a number of days/weeks but haven't yet found a way to get this resolved. I'll paste as much information as I understand to be useful below, and would be grateful for any pointers!

/etc/os-release:

PRETTY_NAME="Ubuntu 24.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.4 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

uname -a:
Linux rpiupsdns 6.8.0-1052-raspi #56-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 27 03:58:47 UTC 2026 aarch64 aarch64 aarch64 GNU/Linux

/etc/nut/ups.conf:

[<ups>]
driver = usbhid-ups
desc = "<desc>"
port = auto
vendorid = 051d
productid = 0002
override.battery.charge.low=75

/etc/nut/nut.conf:
MODE=standalone

/etc/nut/upsd.conf:

LISTEN 127.0.0.1 [3493]
MAXCONN 15

/etc/nut/upsd.users:

[admin]
    password = <secret>
    actions = set
    actions = fsd
    instcmds = ALL
    upsmon primary
[monuser]
    password = <secret>
    upsmon slave

/etc/nut/upsmon.conf:

MINSUPPLIES 1
SHUTDOWNCMD "/usr/sbin/shutdown -h +0"
NOTIFYCMD /bin/upssched-cmd
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYMSG ONLINE        "UPS %s on line power"
NOTIFYMSG ONBATT        "UPS %s on battery"
NOTIFYMSG LOWBATT       "UPS %s battery is low"
NOTIFYMSG FSD           "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK        "Communications with UPS %s established"
NOTIFYMSG COMMBAD       "Communications with UPS %s lost"
NOTIFYMSG SHUTDOWN      "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT      "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM        "UPS %s is unavailable"
NOTIFYMSG NOPARENT      "upsmon parent process died - shutdown impossible"
NOTIFYMSG CAL           "UPS %s: calibration in progress"
NOTIFYMSG OFF           "UPS %s: administratively OFF or asleep"
NOTIFYMSG NOTOFF        "UPS %s: no longer administratively OFF or asleep"
NOTIFYMSG BYPASS        "UPS %s: on bypass (powered, not protecting)"
NOTIFYMSG NOTBYPASS     "UPS %s: no longer on bypass"
NOTIFYFLAG ONLINE     EXEC+SYSLOG+WALL
NOTIFYFLAG ONBATT     EXEC+SYSLOG+WALL
NOTIFYFLAG LOWBATT    EXEC+SYSLOG+WALL
NOTIFYFLAG REPLBATT   EXEC+SYSLOG+WALL
OFFDURATION 30
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
MONITOR qnapups@localhost 1 <user> <password> primary

/etc/nut/upssched.conf:

CMDSCRIPT /bin/upssched-cmd
PIPEFN /run/nut/upssched.pipe
LOCKFN /run/nut/upssched.lock
AT ONBATT * EXECUTE shutdown_onbatt
AT ONBATT * EXECUTE info_onbatt
AT ONLINE * CANCEL-TIMER shutdown_onbatt
AT ONLINE * EXECUTE ups-back-on-power
AT LOWBATT * EXECUTE shutdown_lowbatt
AT REPLBATT * EXECUTE replace_batt

/bin/upssched-cmd:

case $1 in
    shutdown_onbatt)
        touch /home/lozlocal/ran
        logger -t upsmon[upssched] "shutdown_onbatt): Triggering shutdown after 2 minutes on battery"
        <other code>
        ;;

    shutdown_lowbatt)
        logger -t upsmon[upssched] "shutdown_lowbatt): Triggering shutdown when battery.charge.low is under 75%"
        <other code>
        ;;

    info_onbatt)
        logger -t upsmon[upssched] "info_onbatt): Now on battery"
        <other>
        ;;

    ups-back-on-power)
        logger -t upsmon[upssched] "ups-back-on-power): UPS back on power"
        <code>
        ;;

    replace_batt)
        message="Quick self-test indicates battery requires replacement"
        logger -t upsmon[upssched] "replace_batt): $message"
        <code>
        ;;

    *)
        logger -t upsmon[upssched] "*) = Unrecognized command: $1"
        ;;
esac

Metadata

Metadata

Assignees

No one assigned

    Labels

    LinuxSome issues are specific to Linux as a platformShutdowns and overrides and battery level triggersIssues and PRs about system shutdown, especially if battery charge/runtime remaining is involvedquestionservice/daemon start/stopGeneral subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions