Connect your macOS system via a NUT client to the Synology NAS running NUT to shutdown your macOS system when a power failure occurs.
Prerequisites:
- Make sure you have rights to connect to the Synology NAS
Synology NAS:
control panel, Hardware & Power,UPS
Select Enable Network UPS Server, Permitted Disk Station Devices.
Select the devices who are allowed to connect.
Installation NUT client:
The configuration files :
/sw/etc/nut
upsmon.conf:
RUN_AS_USER root
MONITOR <name ups, see synology ups.conf>@<ip address> 1 <user, see synology upsd.users> <password, see synology upsd.users> slave
MINSUPPLIES 1
SHUTDOWNCMD “/sbin/shutdown -u -h +0”
NOTIFYCMD /sw/sbin/upssched
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYFLAG ONLINE EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG LOWBATT EXEC
NOTIFYFLAG NOCOMM EXEC
NOTIFYFLAG COMMBAD IGNORE
NOTIFYFLAG COMMOK IGNORE
NOTIFYFLAG SHUTDOWN IGNORE
NOTIFYFLAG FSD EXEC
NOTIFYFLAG NOPARENT SYSLOG
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
upssched.conf
CMDSCRIPT /sw/bin/upssched-cmd
PIPEFN /sw/var/run/ups/upssched/upssched.pipe
LOCKFN /sw/var/run/ups/upssched/upssched.lock
AT ONBATT <name ups, see synology ups.conf>@<ip address> EXECUTE on-battery
/sw/bin/upssched-cmd:
case $1 in
upsgone)
logger -t upssched-cmd “The UPS has been gone for awhile”
;;
on-battery)
osascript -e ‘tell app “System Events” to display dialog “Power failure. Save your work” giving up after 20 buttons {“OK”} default button 1 with icon caution’
;;
*)
logger -t upssched-cmd “Unrecognized command: $1”
;;
esac
To start upsmon manually:
sudo upsmon -D (/sw/sbin/upsmon)
-D Raise the debugging level. upsmon will run in the foreground and
prints information on stdout about the monitoring process. Use this
multiple times for more details.
upsmon -c stop ( stop monitoring and exit)
upsmon -c reload ( reread upsmon.conf)
To start upsmon automatically on a macOS Sierra :
/Library/LaunchDaemons
-rw-r–r– 1 root wheel org.networkupstools.upsmon.plist
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>org.networkupstools.upsmon</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/sw/sbin/upsmon</string>
<string>-D</string> <!– “-D” keeps upsmon from going into the background –>
</array>
<key>KeepAlive</key>
<true/>
<key>SuccessfulExit</key>
<false/> <!– Do not respawn at shutdown time –>
</dict>
</plist>
To load manually:
sudo launchctl load /Library/LaunchDaemons/org.networkupstools.upsmon.plist
system.log:
com.apple.xpc.launchd[1] (org.networkupstools.upsmon): Unknown key for Boolean: SuccessfulExit
com.apple.xpc.launchd[1] (org.networkupstools.upsmon): This service is defined to be constantly running and is inherently inefficient.
To see if it is running:
sudo launchctl list|fgrep -v com.app
PID Status Label
…
<PID> 0 org.networkupstools.upsmon
ps -ef |grep upsmon
0 88 1 0 9:52AM 0:00.01 /sw/sbin/upsmon -D
0 167 88 0 9:52AM 0:00.50 /sw/sbin/upsmon -D