Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nut (network ups tools) conf and scripts
- Loading branch information
Showing
7 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MODE=standalone |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Refer to hardware compatibility list | ||
# http://www.networkupstools.org/stable-hcl.html | ||
|
||
[myups] | ||
driver=usbhid-ups | ||
port=auto | ||
desc="Some generic USB UPS" | ||
|
||
#[serial] | ||
#driver=genericups | ||
#upstype=7 | ||
#port=/dev/ttyS0 | ||
#desc="Some generic serial UPS" | ||
|
||
#[specific] | ||
#driver=megatec_usb | ||
#port=/dev/usb/hiddev0 | ||
#desc="A specific model" |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
LISTEN 127.0.0.1 | ||
LISTEN ::1 |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[USER] | ||
password = PASS | ||
upsmon master |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# upsmon.conf(8) second arg is powervalue: 1 if it powers this system else 0 | ||
# use 1 when this system needs shutdown, 0 when just monitoring | ||
MONITOR myups 1 USER PASS master | ||
|
||
SHUTDOWNCMD "/sbin/shutdown -h now" | ||
|
||
NOTIFYCMD /sbin/upssched | ||
|
||
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC | ||
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC | ||
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC | ||
NOTIFYFLAG FSD SYSLOG+WALL+EXEC | ||
NOTIFYFLAG COMMOK SYSLOG+EXEC | ||
NOTIFYFLAG COMMBAD SYSLOG+EXEC | ||
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC | ||
NOTIFYFLAG REPLBATT SYSLOG+EXEC | ||
NOTIFYFLAG NOCOMM SYSLOG+EXEC | ||
NOTIFYFLAG NOPARENT SYSLOG+EXEC |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
# Dispatch actions on UPS events. | ||
|
||
main() { | ||
local ups timer host to | ||
ups=${1%%_*} | ||
timer=${1#*_} | ||
host=$(hostname) | ||
to=root | ||
|
||
case "$timer" in | ||
"fsd") | ||
date | mail -s "[$ups@$host] Forced shutdown" $to | ||
shutdown ;; | ||
"onbatt") | ||
date | mail -s "[$ups@$host] Power lost, running on battery" $to | ||
touch /var/run/nut/onbatt ;; | ||
"onbatt-toolong") | ||
date | mail -s "[$ups@$host] Too long on battery, forcing shutdown" $to | ||
touch /var/run/nut/onbatt-toolong | ||
shutdown ;; | ||
"online") | ||
date | mail -s "[$ups@$host] Power is back" $to | ||
rm -f /var/run/nut/onbatt /var/run/nut/onbatt-toolong ;; | ||
"lowbatt") | ||
date | mail -s "[$ups@$host] Low battery" $to ;; | ||
"commok") | ||
date | mail -s "[$ups@$host] Communications OK" $to ;; | ||
"commbad") | ||
date | mail -s "[$ups@$host] Communications lost" $to ;; | ||
"shutdown") | ||
date | mail -s "[$ups@$host] System being shutdown" $to ;; | ||
"replbatt") | ||
date | mail -s "[$ups@$host] Bad battery, replace it" $to ;; | ||
"nocomm") | ||
date | mail -s "[$ups@$host] UPS unavailable" $to ;; | ||
"noparent") | ||
date | mail -s "[$ups@$host] Shutdown impossible, parent died" $to ;; | ||
*) | ||
logger -t upssched-cmd "Unrecognized command: $timer ($1)" ;; | ||
esac | ||
} | ||
|
||
shutdown() { | ||
ssh -i /etc/nut/shutdown.key root@othermachine halt | ||
/sbin/upsmon -c fsd | ||
} | ||
|
||
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then | ||
main "$@" | ||
fi |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CMDSCRIPT /etc/nut/upssched-cmd.sh | ||
|
||
PIPEFN /var/run/nut/upssched.pipe | ||
LOCKFN /var/run/nut/upssched.lock | ||
|
||
# Syntax: AT notifytype upsname command | ||
|
||
# We choose command format: <upsname>_<triggername> | ||
# so it can be parsed in CMDSCRIPT. | ||
|
||
# myups | ||
AT ONLINE myups EXECUTE myups_online | ||
AT ONBATT myups EXECUTE myups_onbatt | ||
AT LOWBATT myups EXECUTE myups_lowbatt | ||
AT FSD myups EXECUTE myups_fsd | ||
AT COMMOK myups EXECUTE myups_commok | ||
AT COMMBAD myups EXECUTE myups_commbad | ||
AT SHUTDOWN myups EXECUTE myups_shutdown | ||
AT REPLBATT myups EXECUTE myups_replbatt | ||
AT NOCOMM myups EXECUTE myups_nocomm | ||
AT NOPARENT myups EXECUTE myups_noparent | ||
# Start a timer that will execute when UPS is on battery for 30 seconds. | ||
AT ONBATT myups START-TIMER myups_onbatt-toolong 30 | ||
# Stop if power is back. | ||
AT ONLINE myups CANCEL-TIMER myups_onbatt-toolong | ||
|
||
# repeat for other UPSes |