Showing posts with label apc. Show all posts
Showing posts with label apc. Show all posts

Wednesday, 13 June 2007

Network UPS Tools

A while ago I ranted about the installation of APC's Powerchute Network Shutdown for Linux. While I got it working, the 60Mb+ of memory footprint used by the Java VM always seemed ridiculous to me, specially for a daemon that doesn't do much more than wait for a shutdown command.

Today I needed those 67Mb of RAM because the kernel on an old-timer began oomkill'ing my processes. A quick search yielded NUT, that works just fine with the Network Management card of Smart-UPS 3000, using the SNMP module.

Here's what I did on the Debian machine.

1. Install packages nut and nut-snmp
# aptitude install nut nut-snmp
2. Create /etc/nut/ups.conf:
[apc1]
driver = snmp-ups
mibs=apcc
community=public
port = apc1.mydomain
desc = "APC1 UPS Network Management Card"
Notice that "port" is the hostname or IP of your APC network card.

3. Start the UPS driver to see if it is working:
# upsdrvctl start

Network UPS Tools - UPS driver controller 2.0.4
Network UPS Tools - Multi-MIBS SNMP UPS driver 0.41 (2.0.4)
Warning: This is an experimental driver.
Some features may not function correctly.

detected Smart-UPS 3000 RM on host apc1.mydomain
4. Create an empty upsd.users file for now:
 echo "" > /etc/nut/upsd.users
5. Create upsd.conf:
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32

ACCEPT localhost
REJECT all
6. Start the server:
# upsd
Network UPS Tools upsd 1.5.12
Connected to UPS [apc1]: snmp-ups-apc1.mydomain
Synchronizing...done
7. Run the upsc utility to test the daemon:
# upsc apc1@localhost ups.status
TRIM # OBS: Should have been "OL" but it seems Energy Australia wasn't cooperating.

# upsc apc1@localhost
battery.charge: 100.0
battery.charge.low: 120
battery.charge.restart: 30
battery.runtime: 840.0
driver.name: snmp-ups
driver.parameter.mibs: apcc
driver.parameter.port: apc1.q-free.com.au
driver.version: 2.0.4
driver.version.internal: 0.41
input.frequency: 050.0
input.sensitivity: 4
input.transfer.high: 253
input.transfer.low: 208
input.voltage: 250.0
output.current: 000.0
output.voltage: 221.0
output.voltage.target.battery: 230
ups.delay.shutdown: 180
ups.delay.start: 0
ups.firmware: 666.6.I
ups.load: 042.0
ups.mfr: APC
ups.mfr.date: 09/26/06
ups.model: Smart-UPS 3000 RM
ups.serial: JS0640013695
ups.status: TRIM
ups.temperature: 025.0
ups.test.result: 1
8. At this point it seems that all is working fine. Edit the upsd.users file:
[monuser]
password = mypass
allowfrom = localhost
upsmon master
9. Edit your upsmon.conf file and remember to set a MONITOR line:
(...)
MONITOR apc1@localhost 1 monuser mypass master
(...)
Check the examples for the other configuration directives.

10. Restart using the init script to make sure:
# /etc/init.d/ups-monitor restart
Restarting Network UPS Tools: upsdrvctl upsdrvctl upsd upsmon.
Check that the processes are running:
# ps auwx | grep ups
nut 22030 0.0 3.6 4540 2260 ? Ss 16:19 0:00 /lib/nut/snmp-ups -a apc1
nut 22032 0.0 1.1 1732 728 ? Ss 16:19 0:00 /sbin/upsd
root 22034 0.0 1.1 1724 680 ? Ss 16:19 0:00 /sbin/upsmon
nut 22035 0.0 1.2 1724 736 ? S 16:19 0:00 /sbin/upsmon
Have a look at the log files; they should look similar to:
# tail /var/log/syslog
Jun 13 15:52:08 localhost snmp-ups[22030]: Startup successful
Jun 13 15:52:08 localhost upsd[22031]: Connected to UPS [apc1]: snmp-ups-apc1.mydomain
Jun 13 15:52:08 localhost upsd[22032]: Startup successful
Jun 13 15:52:08 localhost upsmon[22034]: Startup successful
Jun 13 15:52:08 localhost upsd[22032]: Connection from 127.0.0.1
Jun 13 15:52:08 localhost upsd[22032]: Client monuser@127.0.0.1 logged into UPS [apc1]
If that didn't work, have a look at your /etc/default/nut file - make sure the "START_" variables are set to yes.

I managed to get it running using NUT's install instructions. These are the basic things to get it running; I recommend reading the rest of the documentation to finish your set-up.

Monday, 7 May 2007

APC UPS shutdown client

UPDATE 24/06/07: installing APC java UPS client on Linux? Have a look at NUT first.

Vendor support for Linux gets better everyday but sometimes they miss the point. I'm happier they do a somewhat sloppy job than not do it at all but there is room for improvement.

Case in point: APC's Powerchute Network Shutdown for Linux 2.2.1. For a daemon whose only job is listening for a "power will be out soon" notice and shutting down the machine, this implementation based on Java is a resource hog.

Many admins will try to install the application via remote console and puzzle at the enigmatic error message:
$ sudo ./pcns221lnx.bin
Password:
Preparing wizard...
Searching for JVM...
Starting the wizard...
Exception in main class "JExpressLoader"

See errors.log for other possible causes.out of disk space?
The log file doesn't help in figuring out that you need X to install the application. On Debian, install the xbase-clients packages and its dependencies; do the same for package sun-java5-jre (it's in the non-free group) if you still haven't done so.

The installer also assumes a RedHat SysV structure (with /etc/rc.d/...). Create this directory if it doesn't exist or you will not have the init script after the install is finished. After a successful installation move the created scripts and links to the correct location on your system.

On a few of my installations, the powerchute.sh script (in /usr/local/bin/PowerChute) was broken; it seemed that some variables weren't substituted by the installer. The correct one looks like this:
INSTALL_PATH="/usr/local/bin/PowerChute"

cd $INSTALL_PATH
#fixes developer.java.sun.com bug id #4059472 -java.net.SocketException: too many files open
ulimit -n 256
nohup /usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/bin/java -Xrs -cp \
./lib/m11.jar:./lib/collections.jar:./lib/jsdk.jar:./comp/AAOL.jar:\
./comp/CommandFileRunner.jar:./comp/EventLogger.jar:./comp/http.jar:\
./comp/Notifier.jar:./comp/Omaha.jar:./comp/PowerSourceAggregator.jar:\
./comp/PSAggregator.jar:./comp/RunTimeVerifier.jar:./comp/Shutdowner.jar:\
./comp/StdPowerSource.jar:./comp/ps/StdPowerSource.jar:\
./comp/shutdownerlets/OSshutdownerlet.jar: com.apcc.m11.arch.application.Application \
1>/dev/null 2>/dev/null &
PROCESSID=$!
echo $PROCESSID > pcns.pid
Last but not least, if you are installing over SSH, make sure your X11 connections are forwarded. The option X11Forward option must be set to "yes" in the server's /etc/ssh/sshd_config. Also, use "-X" when calling ssh, to enable forwarding on the client side (or muck around with your options in ~/.ssh/).