Friday, 22 June 2007

Power button event on gnome

On my Debian etch, I configured gnome-power-manager to ask me what to do when the power button is pressed. However, when I did, I could see the GPM prompt followed by the system immediately shutting down.

This is caused by the script /etc/acpi/, which, I believe, was written to work with KDE. I have changed mine to look like this:

# /etc/acpi/
# Initiates a shutdown when the power putton has been
# pressed.

# If powersaved is running, let it process the acpi event
if pidof powersaved; then
exit 0

# Commented-out the following line
#if ps -Af | grep -q '[k]desktop' && test -f /usr/bin/dcop

if ps -Af | grep -q 'gnome-power-manager'
# Commented-out the following line and added "exit 0"
# dcop --all-sessions --all-users ksmserver ksmserver logout 0 2 0 && exit 0

exit 0
/sbin/shutdown -h now "Power button pressed"
Quick-and-dirty, but it works. Maybe I should be running powersaved but I couldn't bother.

Brightness control on notebooks

# cat /proc/acpi/video/VGA/LCD/brightness
levels: 100 37 12 25 37 50 62 75 87 100
current: 50

# echo "any of the above numbers" > /proc/acpi/video/VGA/LCD/brightness
/proc/acpi/video/VGA/LCD/brightness does not exist? Try:
# modprobe video
To load automatically:
# echo video >> /etc/modules
Works on my Dell Inspiron 1501 running Debian Etch (kernel 2.6.18-4-k7).

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:
driver = snmp-ups
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
ACL localhost

ACCEPT localhost
6. Start the server:
# upsd
Network UPS Tools upsd 1.5.12
Connected to UPS [apc1]: snmp-ups-apc1.mydomain
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 snmp-ups
driver.parameter.mibs: apcc
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 230
ups.delay.shutdown: 180
ups.delay.start: 0
ups.firmware: 666.6.I
ups.load: 042.0
ups.mfr: APC 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:
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
Jun 13 15:52:08 localhost upsd[22032]: Client monuser@ 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.