Skip to content

Instantly share code, notes, and snippets.

@smagoun
Forked from 2b/nut_osx.txt
Last active May 25, 2023 04:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smagoun/7e976ae43d5e64a81e26d55ef3f94b44 to your computer and use it in GitHub Desktop.
Save smagoun/7e976ae43d5e64a81e26d55ef3f94b44 to your computer and use it in GitHub Desktop.
Network UPS Tools on OS X Catalina for Synology client
# Tested with nut 2.7.4_2 from homebrew
# Configure OSX Energy Saver UPS tab for the UPS
#install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#install network ups tools
brew install nut
# Set permissions on state dirs to allow running as daemon
sudo mkdir -p /usr/local/var/state/ups/
sudo chown -R `whoami`:nobody /usr/local/var/state/ups
sudo chmod 775 /usr/local/var/state/ups
sudo chmod 664 /usr/local/var/state/ups/*
cd /usr/local/etc/nut/
cp nut.conf.sample nut.conf
vi nut.conf
MODE=netserver
:wq
# The default.ups.* vars are required for the Synology to see the UPS;
# The Synology DSM software doesn't look for device.mfr/device.model
# Values can be whatever you want. Default mfr for the macosx-ups driver
# is '(unknown)'. Get the model from the 'Shutdown Options' button in
# MacOS Preferences -> Energy Saver -> UPS tab -> 'Shutdown Options'
cp ups.conf.sample ups.conf
vi ups.conf
[ups]
driver = macosx-ups
port = auto
desc = "MacOS Energy Saver"
default.ups.mfr = "<ups manufacturer>"
default.ups.model = "<ups model>"
:wq
cp upsd.conf.sample upsd.conf
vi upsd.conf
LISTEN 127.0.0.1 3493
LISTEN <computer IP address> 3493
:wq
cp upsd.users.sample upsd.users
vi upsd.users
[monuser]
password = secret
upsmon slave
:wq
cp upsmon.conf.sample upsmon.conf
vi uspmon.conf
MONITOR ups@localhost 1 monuser secret slave
:wq
#for autostart and control purposes
#change to your own driver - check http://www.networkupstools.org/stable-hcl.html
sudo vi /Library/LaunchDaemons/org.networkupstools.macosx-ups.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.networkupstools.macosx-ups</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/macosx-ups</string>
<string>-a</string>
<string>ups</string>
<string>-D</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
:wq
sudo vi /Library/LaunchDaemons/org.networkupstools.upsd.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.networkupstools.upsd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/upsd</string>
<string>-D</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
:wq
sudo launchctl load /Library/LaunchDaemons/org.networkupstools.macosx-ups.plist
sudo launchctl load /Library/LaunchDaemons/org.networkupstools.upsd.plist
#it's done
#check status and watch some info
upsc ups
#to debug
/usr/local/bin/macosx-ups -a ups -DDD
upsd -DDD
upsmon -DDD
#or add
<key>StandardOutPath</key>
<string>/Users/Username/Desktop/upsmon.log</string>
<key>StandardErrorPath</key>
<string>/Users/Username/Desktop/upsmon.log</string>
#to each LaunchAgent/LaunchDaemon plist
#and change debug level from -D to -DDD at least - <string>-DDD</string>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment