How to shutdown macOS / mac OSX from Network UPS Tools client - NUT

1

1

I’m looking for help in shutting down my iMac on detecting a power failure while running from a UPS.

My setup is an APC SMT750i UPS, powering two Synology NASs, and iMac plus the network kit (router, switch etc.). This is all fine. Synology runs a variant of Linux and NUT. I have installed NUT (v 2.6.5) on the iMac (High Sierra 10.13.6) using MacPorts. One NAS is connected directly to the UPS via USB and acts as the ‘master’ in the NUT network, the other NAS and the iMac are ‘slaves’.

On power failure, the master detects the state of the UPS and broadcasts it to the slaves, which both receive it OK. The NASs both go into ‘safe mode’ correctly as they are configured to do. The iMac receives the state change OK and repeatedly alerts the logged in user, but does NOT in fact shut down, as I want and believe I have configured it to do.

I have followed all the advice I can find online, especially at:

https://networkupstools.org/

How to Automatically Launch NUT Client at Boot on MacOS

https://diktiosolutions.eu/en/synology/synology-ups-nut-en/

What am I doing wrong?

Mac NUT config files:

etc/upsmon.conf

RUN_AS_USER root
MONITOR ups@xxx.xxx.xxx.xxx 1 monuser ****** slave
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -u -h +1"
NOTIFYCMD /opt/local/sbin/upssched
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYFLAG ONLINE   EXEC+SYSLOG+WALL
NOTIFYFLAG ONBATT   EXEC+SYSLOG+WALL
NOTIFYFLAG LOWBATT  EXEC+SYSLOG+WALL
NOTIFYFLAG FSD      EXEC+SYSLOG+WALL
NOTIFYFLAG COMMOK   EXEC+SYSLOG
NOTIFYFLAG COMMBAD  EXEC+SYSLOG
NOTIFYFLAG SHUTDOWN EXEC+SYSLOG+WALL
NOTIFYFLAG REPLBATT EXEC+SYSLOG+WALL
NOTIFYFLAG NOCOMM   EXEC+SYSLOG+WALL
NOTIFYFLAG NOPARENT EXEC+SYSLOG+WALL
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5

etc/upssched.conf

CMDSCRIPT /opt/local/bin/upssched-cmd
PIPEFN /opt/local/var/db/ups/upssched/upssched.pipe
LOCKFN /opt/local/var/db/ups/upssched/upssched.lock
AT ONBATT  ups@xxx.xxx.xxx.xxx EXECUTE      on-battery
AT ONLINE  ups@xxx.xxx.xxx.xxx EXECUTE      ups-back-on-line
AT COMMBAD ups@xxx.xxx.xxx.xxx START-TIMER  upsgone 75
AT COMMOK  ups@xxx.xxx.xxx.xxx CANCEL-TIMER upsgone

bin/upssched-cmd

#! /bin/sh

case $1 in
    upsgone)
        logger -t upssched-cmd "Lost communication with UPS"
        /usr/bin/osascript -e 'tell app (path to frontmost application as text) to display dialog "Lost contact with UPS server" buttons {"OK"} default button 1 with icon note'
        ;;
    on-battery)
        logger -t upssched-cmd "UPS is running on battery"
        /usr/bin/osascript -e 'tell app "System Events"                         to display dialog "Power failure. Save your work" buttons {"OK"} default button 1'
        ;;
    ups-back-on-line)
        logger -t upssched-cmd "UPS is running on utility power"
        /usr/bin/osascript -e 'tell app (path to frontmost application as text) to display dialog "Power restored to UPS" giving up after 600 buttons {"OK"} default button 1 with icon note'
        ;;
    *)
        logger -t upssched-cmd "Unrecognized command: $1"
        /usr/bin/osascript -e "tell app (path to frontmost application as text) to display dialog \"upssched-cmd: unsupported command $1\" buttons {\"OK\"} default button 1 with icon caution"
        ;;
esac

SonwyJoey

Posted 2019-05-25T16:06:18.830

Reputation: 11

Answers

0

Just a thought, as I am currently attempting a similar setup, but with a ReadyNAS and Mac mini.

Reading the upsmon.config.sample that is present at install, it seems that the root user is required to issue the shutdown command. What version of OS X are you running? All releases since El Capitan introduced a rootless mode (i.e. SIP). It follows that all the monitoring is working correctly but the system won't shutdown, since it's issuing a shutdown command to a user that doesn't exist.

If you want, try disabling SIP (google "disabling SIP [your version of OS X here]") and then retest. I think long term you would need to see if you could set up another user and issue the command to them vs. root, as leaving SIP disabled is undesirable.

I'm still messing with my config, but will try once I finish and update you here if it works.

wolfy659

Posted 2019-05-25T16:06:18.830

Reputation: 1

0

My solution to this headache that actually worked for my setup.

UPS1 - cyberpower 800 watt UPS with the following connected devices

  • List item Synology diskstation
  • List item 8 switch/hub
  • List item gateway

UPS2 - Cyber-power 300 watt ups with the following connected devices

  • List item Time-machine external hard drive
  • List item Mac Mini

Here is the Idea.

UPS1 will be connected to the Synology diskstation with the Enable UPS Support options - Then time before disk station enter safe mode which I put 5 minutes by default - then on the second UPS2 which is connected to the UPS1 to my Mac mini with the options set to if UPS1 exhausts batteries then USP2 battery will kick on then set the mac mini to shut down ect. or you can just plus in USP1 and UPS2 in its on independent socket then dictate the settings from there also.

martin izzo

Posted 2019-05-25T16:06:18.830

Reputation: 1