Difference between revisions of "Install a UPS (nut)"
Downlalaway (Talk | contribs) m (→Edit upsmon.conf) |
(→Prerequisites) |
||
(25 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | {{Articles|USB|Debian|FreeLink|General|HG}} | + | {{Articles|USB|Debian|FreeLink|General|HG|LSPro}} |
<table align=right><tr><td>http://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/UPSFrontView.jpg/180px-UPSFrontView.jpg</td></tr></table> | <table align=right><tr><td>http://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/UPSFrontView.jpg/180px-UPSFrontView.jpg</td></tr></table> | ||
= Connecting a UPS to your Linkstation (USB models)= | = Connecting a UPS to your Linkstation (USB models)= | ||
Line 10: | Line 10: | ||
Install the 2.6 kernel to get the new USB HID modules | Install the 2.6 kernel to get the new USB HID modules | ||
− | http:// | + | http://nas-central.org/index.php?title=Category:Kernel |
+ | (the LS-Pro (arm9) FreeLink is already using a 2.6 kernel) | ||
Setup your system to accept packages from the unstable branch | Setup your system to accept packages from the unstable branch | ||
(follow instructions for everything except the last step to "apt-get -t install xyz" ) | (follow instructions for everything except the last step to "apt-get -t install xyz" ) | ||
− | http://www. | + | http://www.nas-central.org/index.php?title=Get_access_to_packages_from_the_Debian_unstable_branch#Unstable_Packages |
− | Fix your localhost entry if applicable. This is a current bug with freelink 1.11 HG: | + | Fix your localhost entry if applicable. This is a current bug with freelink 1.11 HG (and the LSPro/Live arm9 version): |
Modify /etc/hosts | Modify /etc/hosts | ||
Line 56: | Line 57: | ||
==== Edit ups.conf ==== | ==== Edit ups.conf ==== | ||
− | + | Use the nut documentation to identify the appropriate nut driver for your UPS. If, for example, it is the newhidups driver, | |
+ | add this anywhere inside the file: | ||
[myups] | [myups] | ||
driver = newhidups | driver = newhidups | ||
port = auto | port = auto | ||
pollinterval = 10 | pollinterval = 10 | ||
− | desc = "My APC 1000 UPS": | + | desc = "My APC 1000 UPS" |
+ | |||
+ | If you have a cheaper UPS with a serial interface connected to the LinkStation using a serial-to-usb cable, you may need | ||
+ | to use the genericups driver,and specify the upstype (see man genericups for how to configure ups.conf in this case), and | ||
+ | also explicitly specify the port (probably /dev/ttyUSB0 in this case; check the output of dmesg for clues): | ||
+ | |||
+ | You will also need to make sure that the user "nut" can write to the port used to communicate with the UPS (e.g., | ||
+ | add user "nut" to the group identified as allowed to access it by ls -l /dev/xxx , where /dev/xxx is the port, or | ||
+ | temporarily add a line "user=root" at the top of ups.conf, so nut runs as root, until you have identifed the port) | ||
==== Edit upsd.users ==== | ==== Edit upsd.users ==== | ||
Line 86: | Line 96: | ||
==== Edit /etc/default/nut ==== | ==== Edit /etc/default/nut ==== | ||
− | + | If necessary, modify the first few lines to: | |
# start upsd | # start upsd | ||
START_UPSD=yes | START_UPSD=yes | ||
Line 97: | Line 107: | ||
upsmon is the client which polls the server's upsd program to check status and shutdown the pc if needed. In this description server and client are both on the LS -which shuts itself down. | upsmon is the client which polls the server's upsd program to check status and shutdown the pc if needed. In this description server and client are both on the LS -which shuts itself down. | ||
− | ==== | + | ==== Load the nut drivers: ==== |
− | to load the | + | to load the ups driver (newhidups, genericups, or whatever drives your UPS), plus upsd and upsmon, |
+ | enter the command | ||
− | + | /etc/init.d/nut start | |
− | + | Check that this worked, by examining the output of | |
− | === | + | tail -1000 /var/log/syslog | grep ups |
− | + | ||
+ | You should see something like this: | ||
+ | Aug 11 15:31:38 LinkStation newhidups[1606]: Startup successful | ||
+ | Aug 11 15:31:38 LinkStation upsd[1607]: Connected to UPS [myups]: newhidups-auto | ||
+ | Aug 11 15:31:38 LinkStation upsd[1608]: Startup successful | ||
+ | Aug 11 15:31:38 LinkStation upsmon[1610]: Startup successful | ||
+ | Aug 11 15:31:38 LinkStation upsd[1608]: Connection from 127.0.0.1 | ||
+ | Aug 11 15:31:38 LinkStation upsd[1608]: Client monuser@127.0.0.1 logged into UPS [myups] | ||
+ | |||
+ | === Verify UPS connectivity === | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== Disabling the Beeper or changing UPS variables ==== | ==== Disabling the Beeper or changing UPS variables ==== | ||
− | Wish to disable that beeper that wakes you up at night ? | + | Wish to disable that beeper that wakes you up at night ? If you have a fully-hid-featured UPS, |
+ | the command | ||
upsrw myups@localhost | upsrw myups@localhost | ||
+ | |||
+ | will show you what settings you can change (perhaps none if you have a cheap "genericups"!). | ||
+ | |||
The ups.beeper.status variable is likely Enabled. | The ups.beeper.status variable is likely Enabled. | ||
Line 137: | Line 151: | ||
==== Power outage detection ==== | ==== Power outage detection ==== | ||
− | If this all works, try removing power from your UPS to verify | + | If this all works, try removing power from your UPS to verify if the Linkstation will detect it. |
You should see this in your syslogs, again using | You should see this in your syslogs, again using | ||
tail -1000 /var/log/syslog |grep ups | tail -1000 /var/log/syslog |grep ups | ||
Line 149: | Line 163: | ||
We need to set up a slave user, allow access from the LAN for it and then set up the clients. | We need to set up a slave user, allow access from the LAN for it and then set up the clients. | ||
− | |||
A slave user should shutdown before a master user. | A slave user should shutdown before a master user. | ||
+ | ==== Modifying the upsd server ==== | ||
Some changes on the LS (assumed upsd server): | Some changes on the LS (assumed upsd server): | ||
Modify upsd.users to add the slave user: | Modify upsd.users to add the slave user: | ||
Line 158: | Line 172: | ||
allowfrom = mynet | allowfrom = mynet | ||
upsmon slave | upsmon slave | ||
+ | |||
+ | "blah2" is another password to change to your own choice | ||
Edit the upsd.conf to define the "mynet" group of IP addresses to have a bit as per: | Edit the upsd.conf to define the "mynet" group of IP addresses to have a bit as per: | ||
Line 163: | Line 179: | ||
ACL mynet 192.168.1.0/24 | ACL mynet 192.168.1.0/24 | ||
ACL all 0.0.0.0/0 | ACL all 0.0.0.0/0 | ||
− | |||
ACCEPT localhost mynet | ACCEPT localhost mynet | ||
REJECT all | REJECT all | ||
− | Now for the client machines, which can be linux boxes with NUT installed or a WinXX box with WinNUT ( http://www.csociety.org/~delpha/winnut/ ) | + | Naturally, set 192.168.1.0 to your subnet if different. |
+ | |||
+ | ==== Setting up NUT and WinNUT clients ==== | ||
+ | Now for the client machines, which can be linux boxes with NUT installed or a WinXX box with WinNUT (http://www.csociety.org/~delpha/winnut/ ) located on the "mynet" IP range. | ||
Upsmon is only needed so you only need to edit upsmon.conf (through the WinNUT Config tool): | Upsmon is only needed so you only need to edit upsmon.conf (through the WinNUT Config tool): | ||
MONITOR myups@linkstationip 1 monslave blah2 slave | MONITOR myups@linkstationip 1 monslave blah2 slave | ||
− | For a linux box (well debian at least) you'll need to only start the upsmon daemon via /etc/default/nut : | + | For a linux box (well, debian at least) you'll need to only start the upsmon daemon via /etc/default/nut : |
# start upsd | # start upsd | ||
START_UPSD=no | START_UPSD=no | ||
# start upsmon | # start upsmon | ||
START_UPSMON=yes | START_UPSMON=yes | ||
+ | |||
+ | === Monitoring the UPS === | ||
+ | The upsd daemon can also be polled remotely using direct data requests through the various upsc and upsrw commands. I've used cacti (http://forums.cacti.net/ -please note this is quite heavyweight for an LS) which can log and graph pretty much anything, through a command request using upsc on the cacti server polling every 5mins: | ||
+ | |||
+ | upsc myups@linkstationip battery.charge | ||
+ | |||
+ | This returns the numeric value only. It can be wrapped into a script so that the NUT server can be changed. Search the cacti forums for scripts (e.g. http://forums.cacti.net/about9729.html) and then modify to what commands your ups might do, which you can find by using: | ||
+ | |||
+ | upsc myups@linkstationip | ||
+ | |||
+ | ==== Nut-cgi ==== | ||
+ | The nut-cgi package can also provide a web-gui to show the current status which can be installed (needs perl and apache I think) by: | ||
+ | |||
+ | apt-get install nut-cgi | ||
+ | |||
+ | The procedure is the same as the nut setup - look in /usr/share/doc/nut-cgi/ for instructions and copy the files in the examples folder to /etc/nut then configure them as instructed. Many UPSes don't give all the values of voltage and ups load etc, so its worth checking them using the upsc command. | ||
== References == | == References == | ||
Line 185: | Line 219: | ||
Network UPS Tools (nut) | Network UPS Tools (nut) | ||
http://www.networkupstools.org | http://www.networkupstools.org | ||
+ | |||
+ | http://opensource.mgeups.com/howto.htm |
Latest revision as of 00:43, 26 December 2007
![]() |
Contents
Connecting a UPS to your Linkstation (USB models)
Installing Network UPS Tools (nut)
NUT is a powerful tool for safely shutting down computers in a power cut. It can make a LS (or other embedded computer) attached to a usb UPS to be as effective as a full server UPS and shut down everything on your LAN if needed.
Prerequisites
Install the 2.6 kernel to get the new USB HID modules http://nas-central.org/index.php?title=Category:Kernel (the LS-Pro (arm9) FreeLink is already using a 2.6 kernel)
Setup your system to accept packages from the unstable branch (follow instructions for everything except the last step to "apt-get -t install xyz" ) http://www.nas-central.org/index.php?title=Get_access_to_packages_from_the_Debian_unstable_branch#Unstable_Packages
Fix your localhost entry if applicable. This is a current bug with freelink 1.11 HG (and the LSPro/Live arm9 version):
Modify /etc/hosts This line:
127.0.0.1 Linkstation
to
127.0.0.1 Linkstation localhost
if there was "127.0.0.1 localhost", this is good already, no need to change it.
Installing
apt-get -t unstable install nut nut-usb
which will also add the appropriate lib-usb. and install nut & nut-usb 2.0.4-2 or better
Config files setup
Now that you've installed nut, you must set it up. Follow instructions under /usr/share/doc/nut/README.Debian or use this quick and dry way:
cd /etc/nut/ cp /usr/share/doc/nut/examples/ups.conf . cp /usr/share/doc/nut/examples/upsd.conf . cp /usr/share/doc/nut/examples/upsmon.conf . cp /usr/share/doc/nut/examples/upsd.users . chown nut:nut * chmod 600 *
ups.conf sets up the nut server and which driver to talk from the linkstation to the UPS by usb.
upsd.conf defines the IP address access groups e.g. localhost only or your LAN network.
upsd.users defines the user level (e.g. monuser,monmaster,admin) their passwords, IP address access and allowed actions to read or write to the UPS.
upsmon.conf gives the client program (upsmon) the login user, pass and shutdown behaviour for the particular machine.
Edit ups.conf
Use the nut documentation to identify the appropriate nut driver for your UPS. If, for example, it is the newhidups driver, add this anywhere inside the file:
[myups] driver = newhidups port = auto pollinterval = 10 desc = "My APC 1000 UPS"
If you have a cheaper UPS with a serial interface connected to the LinkStation using a serial-to-usb cable, you may need to use the genericups driver,and specify the upstype (see man genericups for how to configure ups.conf in this case), and also explicitly specify the port (probably /dev/ttyUSB0 in this case; check the output of dmesg for clues):
You will also need to make sure that the user "nut" can write to the port used to communicate with the UPS (e.g., add user "nut" to the group identified as allowed to access it by ls -l /dev/xxx , where /dev/xxx is the port, or temporarily add a line "user=root" at the top of ups.conf, so nut runs as root, until you have identifed the port)
Edit upsd.users
Add this anywhere inside the file:
[monuser] password = blah allowfrom = localhost actions = SET upsmon master
blah is the password you wish to use. Make sure you use the same one in upsmon.conf
Edit upsmon.conf
Add this line:
MONITOR myups@localhost 1 monuser blah master
blah is the password, which you should change to your own. Make sure you use the same one in upsd.users
Edit /etc/default/nut
If necessary, modify the first few lines to:
# start upsd START_UPSD=yes
# start upsmon START_UPSMON=yes
Again: upsd is the server daemon which runs on the computer directly connected to the UPS.
upsmon is the client which polls the server's upsd program to check status and shutdown the pc if needed. In this description server and client are both on the LS -which shuts itself down.
Load the nut drivers:
to load the ups driver (newhidups, genericups, or whatever drives your UPS), plus upsd and upsmon, enter the command
/etc/init.d/nut start
Check that this worked, by examining the output of
tail -1000 /var/log/syslog | grep ups
You should see something like this:
Aug 11 15:31:38 LinkStation newhidups[1606]: Startup successful Aug 11 15:31:38 LinkStation upsd[1607]: Connected to UPS [myups]: newhidups-auto Aug 11 15:31:38 LinkStation upsd[1608]: Startup successful Aug 11 15:31:38 LinkStation upsmon[1610]: Startup successful Aug 11 15:31:38 LinkStation upsd[1608]: Connection from 127.0.0.1 Aug 11 15:31:38 LinkStation upsd[1608]: Client monuser@127.0.0.1 logged into UPS [myups]
Verify UPS connectivity
Disabling the Beeper or changing UPS variables
Wish to disable that beeper that wakes you up at night ? If you have a fully-hid-featured UPS, the command
upsrw myups@localhost
will show you what settings you can change (perhaps none if you have a cheap "genericups"!).
The ups.beeper.status variable is likely Enabled.
upsrw -s ups.beeper.status myups@localhost Username (root): monuser Password: blah Enter new value for ups.beeper.status: 1
upsrw myups@localhost
Verify that ups.beeper.status now shows up as disabled Follow same method for changing other variables.
Power outage detection
If this all works, try removing power from your UPS to verify if the Linkstation will detect it. You should see this in your syslogs, again using
tail -1000 /var/log/syslog |grep ups
Aug 10 15:59:28 LinkStation upsmon[1613]: UPS myups@localhost on battery
Aug 10 16:04:39 LinkStation upsmon[1613]: UPS myups@localhost on line power
Powering other computers from the UPS
So far it should work before proceeding further -the LS will shut down when the power supply is off and the battery is low. The real power of NUT is that it can turn off lots of PCs including WinXX which are anywhere on your LAN even if they are only connected to "dumb" UPSes.
We need to set up a slave user, allow access from the LAN for it and then set up the clients. A slave user should shutdown before a master user.
Modifying the upsd server
Some changes on the LS (assumed upsd server): Modify upsd.users to add the slave user:
[monslave] password = blah2 allowfrom = mynet upsmon slave
"blah2" is another password to change to your own choice
Edit the upsd.conf to define the "mynet" group of IP addresses to have a bit as per:
ACL localhost 127.0.0.1/32 ACL mynet 192.168.1.0/24 ACL all 0.0.0.0/0 ACCEPT localhost mynet REJECT all
Naturally, set 192.168.1.0 to your subnet if different.
Setting up NUT and WinNUT clients
Now for the client machines, which can be linux boxes with NUT installed or a WinXX box with WinNUT (http://www.csociety.org/~delpha/winnut/ ) located on the "mynet" IP range.
Upsmon is only needed so you only need to edit upsmon.conf (through the WinNUT Config tool):
MONITOR myups@linkstationip 1 monslave blah2 slave
For a linux box (well, debian at least) you'll need to only start the upsmon daemon via /etc/default/nut :
# start upsd START_UPSD=no # start upsmon START_UPSMON=yes
Monitoring the UPS
The upsd daemon can also be polled remotely using direct data requests through the various upsc and upsrw commands. I've used cacti (http://forums.cacti.net/ -please note this is quite heavyweight for an LS) which can log and graph pretty much anything, through a command request using upsc on the cacti server polling every 5mins:
upsc myups@linkstationip battery.charge
This returns the numeric value only. It can be wrapped into a script so that the NUT server can be changed. Search the cacti forums for scripts (e.g. http://forums.cacti.net/about9729.html) and then modify to what commands your ups might do, which you can find by using:
upsc myups@linkstationip
Nut-cgi
The nut-cgi package can also provide a web-gui to show the current status which can be installed (needs perl and apache I think) by:
apt-get install nut-cgi
The procedure is the same as the nut setup - look in /usr/share/doc/nut-cgi/ for instructions and copy the files in the examples folder to /etc/nut then configure them as instructed. Many UPSes don't give all the values of voltage and ups load etc, so its worth checking them using the upsc command.
References
Peter Selinger: Linux and the APC Back-UPS ES http://www.mathstat.dal.ca/~selinger/ups/backups.html
Network UPS Tools (nut) http://www.networkupstools.org