-
-
Save fabrizziosoares/28a25b884b37b4118eaefaac49dcaae2 to your computer and use it in GitHub Desktop.
Revisions
-
hdml revised this gist
Oct 7, 2017 . 2 changed files with 47 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,11 +64,6 @@ sudo vi /Library/LaunchDaemons/org.networkupstools.upsmon.plist </plist> :wq mv upssched.conf.sample upssched.conf #configuring for shutdown after 2min vi upssched.conf @@ -117,49 +112,55 @@ vi /usr/local/Cellar/nut/2.7.3/bin/shutdown.applescript :wq vi /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd #! /bin/sh case $1 in ONLINE) logger -t upssched-cmd "UPS on line power" ;; ONBATT) logger -t upssched-cmd "UPS on battery" ;; LOWBATT) logger -t upssched-cmd "UPS battery is low" ;; FSD) logger -t upssched-cmd "UPS forced shutdown in progress. System is going down!" /usr/bin/osascript -e 'tell app \"System Events\" to shut down' ;; COMMOK) logger -t upssched-cmd "Communications with UPS established" ;; COMMBAD) logger -t upssched-cmd "Communications with UPS lost" ;; SHUTDOWN) logger -t upssched-cmd "Auto logout and shutdown proceeding. Executing graceful shutdown." /usr/local/sbin/upsmon -c fsd ;; REPLBATT) logger -t upssched-cmd "UPS battery needs to be replaced" ;; NOCOMM) logger -t upssched-cmd "UPS is unavailable" ;; NOPARENT) logger -t upssched-cmd "upsmon parent process died - shutdown impossible" ;; *) logger -t upssched-cmd "Unrecognized UPS command: $1" ;; esac :wq #launch daemon sudo launchctl load /Library/LaunchDaemons/org.networkupstools.upsmon.plist #it's done #check status in Console.app, under /Library/Logs #to debug #change debug level from -D to -DDD at least - <string>-DDD</string> #if you want to log your UPS voltages, create the org.networkupstools.upslog.plist LaunchAgent in this gist. #replace your remote UPS host and user path in the output log "/Users/youruser" #and 300 for the interval in seconds of the logging frequency (default 300 seconds = 5 mins) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ <?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>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin</string> </dict> <key>Label</key> <string>org.networkupstools.upsmon</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/upslog</string> <string>-s</string> <string>ups@remote-ups-host:3493</string> <string>-l</string> <string>/Users/youruser/Library/Logs/upslog.log</string> <string>-i</string> <string>300</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> -
hdml revised this gist
Oct 3, 2017 . 1 changed file with 0 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -99,17 +99,6 @@ vi uspmon.conf #SHUTDOWNCMD "/usr/bin/osascript -e 'tell app \"System Events\" to shut down'" NOTIFYCMD "/usr/local/sbin/upssched" NOTIFYFLAG ONLINE SYSLOG+EXEC NOTIFYFLAG ONBATT SYSLOG+EXEC NOTIFYFLAG LOWBATT SYSLOG+EXEC -
hdml revised this gist
Oct 3, 2017 . 3 changed files with 42 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,21 +72,22 @@ cd /usr/local/Cellar/nut/2.7.4/etc/ mv upssched.conf.sample upssched.conf #configuring for shutdown after 2min vi upssched.conf CMDSCRIPT /usr/local/Cellar/nut/2.7.4/bin/upssched-cmd PIPEFN /var/state/ups/upssched/upssched.pipe LOCKFN /var/state/ups/upssched/upssched.lock AT NOCOMM * EXECUTE NOCOMM AT COMMBAD * START-TIMER COMMBAD 10 AT COMMOK * CANCEL-TIMER COMMBAD COMMOK AT FSD * EXECUTE FSD AT LOWBATT * EXECUTE LOWBATT AT LOWBATT * START-TIMER FSD 5 AT ONBATT * EXECUTE ONBATT AT ONBATT * START-TIMER SHUTDOWN 60 AT ONLINE * EXECUTE ONLINE AT ONLINE * CANCEL-TIMER SHUTDOWN AT REPLBATT * EXECUTE REPLBATT AT SHUTDOWN * EXECUTE SHUTDOWN AT NOPARENT * EXECUTE NOPARENT :wq This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +1,38 @@ #! /bin/sh case $1 in ONLINE) logger -t upssched-cmd "UPS on line power" ;; ONBATT) logger -t upssched-cmd "UPS on battery" ;; LOWBATT) logger -t upssched-cmd "UPS battery is low" ;; FSD) logger -t upssched-cmd "UPS forced shutdown in progress. System is going down!" /usr/bin/osascript -e 'tell app \"System Events\" to shut down' ;; COMMOK) logger -t upssched-cmd "Communications with UPS established" ;; COMMBAD) logger -t upssched-cmd "Communications with UPS lost" ;; SHUTDOWN) logger -t upssched-cmd "Auto logout and shutdown proceeding. Executing graceful shutdown." /usr/local/sbin/upsmon -c fsd ;; REPLBATT) logger -t upssched-cmd "UPS battery needs to be replaced" ;; NOCOMM) logger -t upssched-cmd "UPS is unavailable" ;; NOPARENT) logger -t upssched-cmd "upsmon parent process died - shutdown impossible" ;; *) logger -t upssched-cmd "Unrecognized UPS command: $1" ;; esac This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ CMDSCRIPT /usr/local/Cellar/nut/2.7.4/bin/upssched-cmd PIPEFN /var/state/ups/upssched/upssched.pipe LOCKFN /var/state/ups/upssched/upssched.lock AT NOCOMM * EXECUTE NOCOMM AT COMMBAD * START-TIMER COMMBAD 10 AT COMMOK * CANCEL-TIMER COMMBAD COMMOK AT FSD * EXECUTE FSD AT LOWBATT * EXECUTE LOWBATT AT LOWBATT * START-TIMER FSD 5 AT ONBATT * EXECUTE ONBATT AT ONBATT * START-TIMER SHUTDOWN 60 AT ONLINE * EXECUTE ONLINE AT ONLINE * CANCEL-TIMER SHUTDOWN AT REPLBATT * EXECUTE REPLBATT AT SHUTDOWN * EXECUTE SHUTDOWN AT NOPARENT * EXECUTE NOPARENT -
hdml revised this gist
Oct 3, 2017 . 2 changed files with 11 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,27 +27,16 @@ vi uspmon.conf SHUTDOWNCMD "sudo -u localuser osascript /usr/local/Cellar/nut/2.7.4/bin/shutdown.applescript" NOTIFYCMD "/usr/local/sbin/upssched" NOTIFYFLAG ONLINE SYSLOG+EXEC NOTIFYFLAG ONBATT SYSLOG+EXEC NOTIFYFLAG LOWBATT SYSLOG+EXEC NOTIFYFLAG FSD SYSLOG+EXEC NOTIFYFLAG COMMOK SYSLOG+EXEC NOTIFYFLAG COMMBAD SYSLOG+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+EXEC NOTIFYFLAG REPLBATT SYSLOG+EXEC NOTIFYFLAG NOCOMM SYSLOG+EXEC NOTIFYFLAG NOPARENT SYSLOG+EXEC :wq #create LaunchDaemon that will fire up upsmon This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,6 +35,4 @@ case $1 in *) MSG="Unrecognized command: $1" ;; esac -
hdml revised this gist
Oct 3, 2017 . 3 changed files with 69 additions and 115 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ #install homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" #install network ups tools brew update brew install nut #create directories and change permissions @@ -9,94 +10,47 @@ sudo chown -R `whoami`:nobody /var/state/ups sudo chmod 775 /var/state/ups/ sudo chmod 664 /var/state/ups/* sudo chmod 775 /var/state/ups/upssched/ sudo chmod 640 /usr/local/Cellar/nut/2.7.4/etc/* sudo chmod o+r /usr/local/Cellar/nut/2.7.4/etc/upssched.conf cd /usr/local/Cellar/nut/2.7.4/etc/ mv nut.conf.sample nut.conf vi nut.conf MODE=netclient :wq mv upsmon.conf.sample upsmon.conf vi uspmon.conf # Set your remote server host and password MONITOR ups@remotehost:3493 1 upsmon remotepassword slave # Set your admin user that will execute the shutdown script SHUTDOWNCMD "sudo -u localuser osascript /usr/local/Cellar/nut/2.7.4/bin/shutdown.applescript" NOTIFYCMD "/usr/local/sbin/upssched" 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" NOTIFYFLAG ONLINE SYSLOG+EXEC+WALL NOTIFYFLAG ONBATT SYSLOG+EXEC+WALL NOTIFYFLAG LOWBATT SYSLOG+EXEC+WALL NOTIFYFLAG FSD SYSLOG+EXEC+WALL NOTIFYFLAG COMMOK SYSLOG+EXEC+WALL NOTIFYFLAG COMMBAD SYSLOG+EXEC+WALL NOTIFYFLAG SHUTDOWN SYSLOG+EXEC+WALL NOTIFYFLAG REPLBATT SYSLOG+EXEC+WALL NOTIFYFLAG NOCOMM SYSLOG+EXEC+WALL NOTIFYFLAG NOPARENT SYSLOG+EXEC+WALL :wq #create LaunchDaemon that will fire up upsmon sudo vi /Library/LaunchDaemons/org.networkupstools.upsmon.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"> @@ -113,45 +67,18 @@ sudo vi /Library/LaunchDaemons/org.networkupstools.upsmon.plist </array> <key>RunAtLoad</key> <true/> <key>StandardOutPath</key> <string>/Library/Logs/upsmon.log</string> <key>StandardErrorPath</key> <string>/Library/Logs/upsmon.log</string> </dict> </plist> :wq #launch daemon sudo launchctl load /Library/LaunchDaemons/org.networkupstools.upsmon.plist cd /usr/local/Cellar/nut/2.7.4/etc/ mv upssched.conf.sample upssched.conf #configuring for shutdown after 2min @@ -249,7 +176,11 @@ vi /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd MSG="Unrecognized command: $1" ;; esac :wq #it's done #check status in Console.app, under /Library/Logs #to debug #change debug level from -D to -DDD at least - <string>-DDD</string> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ <?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.upsmon</string> <key>ProgramArguments</key> <array> <string>/usr/local/sbin/upsmon</string> <string>-D</string> </array> <key>RunAtLoad</key> <true/> <key>StandardOutPath</key> <string>/Library/Logs/upsmon.log</string> <key>StandardErrorPath</key> <string>/Library/Logs/upsmon.log</string> </dict> </plist> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ #!/usr/bin/osascript tell application "loginwindow" to «event aevtrsdn» -
2b revised this gist
Oct 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -148,7 +148,7 @@ upsmon -DDD #additional - Growl notifications #install GrowlNotify - http://growl.info/extras.php#growlnotify #then configure Growl to listen for incoming notifications and set pass #test with command growlnotify -s -n "TEST" -m "test" -P "PA$$W0RD" cd /usr/local/Cellar/nut/2.7.3/etc/ -
2b revised this gist
Oct 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -138,7 +138,7 @@ upsmon -DDD #to each LaunchAgent/LaunchDaemon plist #and change debug level from -D to -DDD at least - <string>-DDD</string> #fyi - "upsdrvctl start" doesnt work properly with blazer_usb - getting Error: Data stale -
2b revised this gist
Oct 22, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -148,10 +148,9 @@ upsmon -DDD #additional - Growl notifications #install GrowlNotify - http://growl.info/extras.php#growlnotify #then configure it to listen for incoming notifications and set pass #test with command growlnotify -s -n "TEST" -m "test" -P "PA$$W0RD" cd /usr/local/Cellar/nut/2.7.3/etc/ mv upssched.conf.sample upssched.conf -
2b revised this gist
Oct 22, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -95,7 +95,7 @@ vi ~/Library/LaunchAgents/org.networkupstools.upsd.plist </plist> :wq #upsmon splits into two processes, one with PPID 1, cuz it need root permissions to shutdown OS #so create LaunchDaemon instead of LaunchAgent sudo vi /Library/LaunchDaemons/org.networkupstools.upsmon.plist <?xml version="1.0" encoding="UTF-8"?> @@ -121,7 +121,7 @@ launchctl load ~/Library/LaunchAgents/org.networkupstools.blazer_usb.plist launchctl load ~/Library/LaunchAgents/org.networkupstools.upsd.plist sudo launchctl load /Library/LaunchDaemons/org.networkupstools.upsmon.plist #it's done #check status and watch some info upsc upsname @@ -132,9 +132,9 @@ 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> -
2b revised this gist
Oct 22, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -207,8 +207,8 @@ vi uspmon.conf :wq vi /usr/local/Cellar/nut/2.7.3/bin/shutdown.applescript #!/usr/bin/osascript tell application "loginwindow" to «event aevtrsdn» :wq vi /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd -
2b revised this gist
Oct 22, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -176,7 +176,9 @@ vi upssched.conf :wq vi uspmon.conf #unfortunately, we can't use SHUTDOWNCMD "/usr/bin/osascript -e 'tell app \"loginwindow\" to «event aevtrsdn»'" #because of angle brakets (upsmon filtering them), so we'll create shutdown.applescript #but if you don't need additional time for cancel shutdown - use second SHUTDOWNCMD SHUTDOWNCMD "sudo -u Username /usr/local/Cellar/nut/2.7.3/bin/shutdown.applescript" #SHUTDOWNCMD "/usr/bin/osascript -e 'tell app \"System Events\" to shut down'" NOTIFYCMD "/usr/local/sbin/upssched" -
2b revised this gist
Oct 22, 2015 . No changes.There are no files selected for viewing
-
2b revised this gist
Oct 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ case $1 in ;; SHUTDOWN) MSG="Auto logout and shutdown proceeding" upscmd -u Username -p Password upsname@localhost shutdown.return ;; REPLBATT) MSG="UPS battery needs to be replaced" -
2b revised this gist
Oct 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -148,7 +148,7 @@ upsmon -DDD #additional - Growl notifications #install GrowlNotify - http://growl.info/extras.php#growlnotify #then configure it to listen for incomming notification and set pass #test with command growlnotify -s -n "TEST" -m "test" -P "PA$$W0RD" -
2b revised this gist
Oct 22, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -146,7 +146,7 @@ upsmon -DDD #additional - Growl notifications #install GrowlNotify - http://growl.info/extras.php#growlnotify #then confugure it to listen for incomming notification and set pass #test with command growlnotify -s -n "TEST" -m "test" -P "PA$$W0RD" @@ -161,11 +161,11 @@ vi upssched.conf PIPEFN /var/state/ups/upssched/upssched.pipe LOCKFN /var/state/ups/upssched/upssched.lock AT ONLINE * EXECUTE ONLINE AT ONLINE * CANCEL-TIMER SHUTDOWN AT ONBATT * EXECUTE ONBATT AT ONBATT * START-TIMER SHUTDOWN 120 AT LOWBATT * EXECUTE LOWBATT AT LOWBATT * START-TIMER FSD 5 AT FSD * EXECUTE FSD AT COMMOK * EXECUTE COMMOK AT COMMBAD * EXECUTE COMMBAD -
2b revised this gist
Oct 22, 2015 . 1 changed file with 40 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ case $1 in ONLINE) MSG="UPS on line power" upscmd -u Username -p Password upsname@localhost shutdown.stop ;; ONBATT) MSG="UPS on battery" ;; LOWBATT) MSG="UPS battery is low" ;; FSD) MSG="UPS forced shutdown in progress" /usr/local/sbin/upsmon -c fsd ;; COMMOK) MSG="Communications with UPS established" ;; COMMBAD) MSG="Communications with UPS lost" ;; SHUTDOWN) MSG="Auto logout and shutdown proceeding" upscmd -u User -p pass upsname@localhost shutdown.return ;; REPLBATT) MSG="UPS battery needs to be replaced" ;; NOCOMM) MSG="UPS is unavailable" ;; NOPARENT) MSG="upsmon parent process died - shutdown impossible" ;; *) MSG="Unrecognized command: $1" ;; esac /usr/local/bin/growlnotify -s -n "UPSNAME" -m "$MSG" -P "PA$$W0RD" -
2b revised this gist
Oct 22, 2015 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ cd /usr/local/Cellar/nut/2.7.3/etc/ mv nut.conf.sample nut.conf vi nut.conf MODE=standalone :wq mv ups.conf.sample ups.conf vi ups.conf @@ -29,12 +29,12 @@ vi ups.conf default.battery.voltage.high = 15.00 default.battery.voltage.nominal = 14.00 default.battery.voltage.low = 13.00 :wq mv upsd.conf.sample upsd.conf vi upsd.conf LISTEN 127.0.0.1 3493 :wq mv upsd.users.sample upsd.users vi upsd.users @@ -43,12 +43,12 @@ vi upsd.users actions = SET instcmds = ALL upsmon master :wq mv upsmon.conf.sample upsmon.conf vi uspmon.conf MONITOR upsname@localhost 1 Username Password master :wq #for autostart and control purposes #change to your own driver - check http://www.networkupstools.org/stable-hcl.html @@ -73,7 +73,7 @@ vi ~/Library/LaunchAgents/org.networkupstools.blazer_usb.plist <true/> </dict> </plist> :wq vi ~/Library/LaunchAgents/org.networkupstools.upsd.plist <?xml version="1.0" encoding="UTF-8"?> @@ -93,7 +93,7 @@ vi ~/Library/LaunchAgents/org.networkupstools.upsd.plist <true/> </dict> </plist> :wq #upsmon splits into two processes, one with PPID 1, cuz it need root permissions to shutdown os #so create LaunchDaemon instead of LaunchAgent @@ -115,7 +115,7 @@ sudo vi /Library/LaunchDaemons/org.networkupstools.upsmon.plist <true/> </dict> </plist> :wq launchctl load ~/Library/LaunchAgents/org.networkupstools.blazer_usb.plist launchctl load ~/Library/LaunchAgents/org.networkupstools.upsd.plist @@ -138,7 +138,7 @@ upsmon -DDD #to each LaunchAgent/LaunchDaemon plist #and change debug level from -D to -DDD at least - <string>-DDD</string> #fyi - upsdrvctl start doesnt work with blazer_usb - getting Error: Data stale @@ -173,7 +173,7 @@ vi upssched.conf AT REPLBATT * EXECUTE REPLBATT AT NOCOMM * EXECUTE NOCOMM AT NOPARENT * EXECUTE NOPARENT :wq vi uspmon.conf #unfortunately, we can't use SHUTDOWNCMD "/usr/bin/osascript -e 'tell app \"loginwindow\" to «event aevtrsdn»'" because of angle brakets (upsmon filtering them), so we'll create shutdown.applescript, but if you don't need additional time for cancel shutdown - use second SHUTDOWNCMD @@ -202,12 +202,12 @@ vi uspmon.conf NOTIFYFLAG REPLBATT SYSLOG+EXEC NOTIFYFLAG NOCOMM SYSLOG+EXEC NOTIFYFLAG NOPARENT SYSLOG+EXEC :wq vi /usr/local/Cellar/nut/2.7.3/bin/shutdown.applescript #!/usr/bin/osascript tell application "loginwindow" to «event aevtrsdn» :wq vi /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd case $1 in @@ -251,4 +251,4 @@ vi /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd #change to your growl pass /usr/local/bin/growlnotify -s -n "UPSNAME" -m "$MSG" -P "PA$$W0RD" :wq -
2b created this gist
Oct 22, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,254 @@ #install homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" #install network ups tools brew install nut #create directories and change permissions sudo mkdir -p /var/state/ups/upssched/ sudo chown -R `whoami`:nobody /var/state/ups sudo chmod 775 /var/state/ups/ sudo chmod 664 /var/state/ups/* sudo chmod 775 /var/state/ups/upssched/ sudo chmod 640 /usr/local/Cellar/nut/2.7.3/etc/* sudo chmod o+r /usr/local/Cellar/nut/2.7.3/etc/upssched.conf cd /usr/local/Cellar/nut/2.7.3/etc/ mv nut.conf.sample nut.conf vi nut.conf MODE=standalone :wq mv ups.conf.sample ups.conf vi ups.conf [upsname] #in my case - its blazer_usb driver. Check here http://www.networkupstools.org/stable-hcl.html driver=blazer_usb port=auto desc = "SVEN UPS 650VA" #set your own battery.voltage values. Check with command "upsc upsname" default.battery.voltage.high = 15.00 default.battery.voltage.nominal = 14.00 default.battery.voltage.low = 13.00 :wq mv upsd.conf.sample upsd.conf vi upsd.conf LISTEN 127.0.0.1 3493 :wq mv upsd.users.sample upsd.users vi upsd.users [Username] password = Password actions = SET instcmds = ALL upsmon master :wq mv upsmon.conf.sample upsmon.conf vi uspmon.conf MONITOR upsname@localhost 1 Username Password master :wq #for autostart and control purposes #change to your own driver - check http://www.networkupstools.org/stable-hcl.html vi ~/Library/LaunchAgents/org.networkupstools.blazer_usb.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.blazer_usb</string> <key>ProgramArguments</key> <array> <string>/usr/local/Cellar/nut/2.7.3/bin/blazer_usb</string> <string>-a</string> <string>upsname</string> <string>-D</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> :wq vi ~/Library/LaunchAgents/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 #upsmon splits into two processes, one with PPID 1, cuz it need root permissions to shutdown os #so create LaunchDaemon instead of LaunchAgent sudo vi /Library/LaunchDaemons/org.networkupstools.upsmon.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.upsmon</string> <key>ProgramArguments</key> <array> <string>/usr/local/sbin/upsmon</string> <string>-D</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> :wq launchctl load ~/Library/LaunchAgents/org.networkupstools.blazer_usb.plist launchctl load ~/Library/LaunchAgents/org.networkupstools.upsd.plist sudo launchctl load /Library/LaunchDaemons/org.networkupstools.upsmon.plist #its done #check status and watch some info upsc upsname #to debug /usr/local/Cellar/nut/2.7.3/bin/blazer_usb -a upsname -DDD upsd -DDD upsmon -DDD #or add <key>StandardOutPath</key> <string>/Users/User/Desktop/upsmon.log</string> <key>StandardErrorPath</key> <string>/Users/User/Desktop/upsmon.log</string> #to each LaunchAgent/LaunchDaemon plist #and change debug level from -D to -DDD at least - <string>-DDD</string> #fyi - upsdrvctl start doesnt work with blazer_usb - Error: Data stale --------- #additional - Growl notification #install GrowlNotify - http://growl.info/extras.php#growlnotify #then confugure it to listen for incomming notification and set pass #test with command growlnotify -s -n "TEST" -m "test" -P "PA$$W0RD" cd /usr/local/Cellar/nut/2.7.3/etc/ mv upssched.conf.sample upssched.conf #configuring for shutdown after 2min vi upssched.conf CMDSCRIPT /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd PIPEFN /var/state/ups/upssched/upssched.pipe LOCKFN /var/state/ups/upssched/upssched.lock AT ONLINE * EXECUTE ONLINE AT ONLINE * CANCEL-TIMER FSD AT ONBATT * EXECUTE ONBATT AT ONBATT * START-TIMER FSD 120 AT LOWBATT * EXECUTE LOWBATT AT LOWBATT * START-TIMER FSD 10 AT FSD * EXECUTE FSD AT COMMOK * EXECUTE COMMOK AT COMMBAD * EXECUTE COMMBAD AT SHUTDOWN * EXECUTE SHUTDOWN AT REPLBATT * EXECUTE REPLBATT AT NOCOMM * EXECUTE NOCOMM AT NOPARENT * EXECUTE NOPARENT :wq vi uspmon.conf #unfortunately, we can't use SHUTDOWNCMD "/usr/bin/osascript -e 'tell app \"loginwindow\" to «event aevtrsdn»'" because of angle brakets (upsmon filtering them), so we'll create shutdown.applescript, but if you don't need additional time for cancel shutdown - use second SHUTDOWNCMD SHUTDOWNCMD "sudo -u Username /usr/local/Cellar/nut/2.7.3/bin/shutdown.applescript" #SHUTDOWNCMD "/usr/bin/osascript -e 'tell app \"System Events\" to shut down'" NOTIFYCMD "/usr/local/sbin/upssched" 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" NOTIFYFLAG ONLINE SYSLOG+EXEC NOTIFYFLAG ONBATT SYSLOG+EXEC NOTIFYFLAG LOWBATT SYSLOG+EXEC NOTIFYFLAG FSD SYSLOG+EXEC NOTIFYFLAG COMMOK SYSLOG+EXEC NOTIFYFLAG COMMBAD SYSLOG+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+EXEC NOTIFYFLAG REPLBATT SYSLOG+EXEC NOTIFYFLAG NOCOMM SYSLOG+EXEC NOTIFYFLAG NOPARENT SYSLOG+EXEC :wq vi /usr/local/Cellar/nut/2.7.3/bin/shutdown.applescript #!/usr/bin/osascript tell application "loginwindow" to «event aevtrsdn» :wq vi /usr/local/Cellar/nut/2.7.3/bin/upssched-cmd case $1 in ONLINE) MSG="UPS on line power" upscmd -u Username -p Password upsname@localhost shutdown.stop ;; ONBATT) MSG="UPS on battery" ;; LOWBATT) MSG="UPS battery is low" ;; FSD) MSG="UPS forced shutdown in progress" /usr/local/sbin/upsmon -c fsd ;; COMMOK) MSG="Communications with UPS established" ;; COMMBAD) MSG="Communications with UPS lost" ;; SHUTDOWN) MSG="Auto logout and shutdown proceeding" upscmd -u User -p pass upsname@localhost shutdown.return ;; REPLBATT) MSG="UPS battery needs to be replaced" ;; NOCOMM) MSG="UPS is unavailable" ;; NOPARENT) MSG="upsmon parent process died - shutdown impossible" ;; *) MSG="Unrecognized command: $1" ;; esac #change to your growl pass /usr/local/bin/growlnotify -s -n "UPSNAME" -m "$MSG" -P "PA$$W0RD" :wq