Friday, October 19, 2012

Installing APCUPSD in Debian 6 Squeeze

English: Logo of American Power Conversion
English: Logo of American Power Conversion (Photo credit: Wikipedia)

Sooner or later we all start thinking about a parachute for the server.

Personally I so as many other people prefer to use for this goal equipment from APC ompany because they produce hardware of high enough quality and an admin friendly daemon named apcupsd for managing UPS.

If our tastes here coinside then power up the server via UPS and connect with USB-Dara cable.

Now we can take a glance into /var/log/dmesg - here we must see something like that:
cat /var/log/dmesg | grep -i 'American Power Conversion'
[    1.570614] usb 6-2: Manufacturer: American Power Conversion
[    2.174944] generic-usb 0003:051D:0002.0001: hiddev0,hidraw0: USB HID v1.10 Device \
 [American Power Conversion Back-UPS ES 525 FW:851.t3.I USB FW:t3] on usb-0000:00:1d.1-2/input0
If the device appeared then we may start installing.
#Install apcupsd and something else needed for configurating
apt-get install apcupsd apcupsd-doc gawk sed vim gzip
#Get configuration file ready for work via usb-data-cable
cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.origin
gunzip /usr/share/doc/apcupsd/examples/usb_hid_usages.gz
cp /usr/share/doc/apcupsd/examples/usb.conf /etc/apcupsd/apcupsd.conf
sed -i -e 's/^ISCONFIGURED.*$/ISCONFIGURED=yes/g' /etc/default/apcupsd
Let's make basic configuration.

For this specify NISPORT 3551 (it is a default port apcaccess connects to) and turn off NETACCESS function because it is not supported any more.
sed -i -e 's/^NISPORT.*$/NISPORT 3551/g' /etc/apcupsd/apcupsd.conf
sed -i -e 's/^NETACCESS.*$/#NETACCESS/g' /etc/apcupsd/apcupsd.conf
Convince the system that we trust ourselves.
cp /etc/hosts.allow /etc/hosts.allow.orig
echo "apcupsd:" >> /etc/hosts.allow
Give our uninterrupted power supply unit correct name, restart apcupsd and make sure that the name was set correctly.
UPSNAME=`cat /var/log/dmesg | awk -F'American Power Conversion ' '{ printf $2 }' | awk '{ print $1"_"$2"_"$3 }'`
sed -i -e "s/^UPSNAME.*$/UPSNAME $UPSNAME/g" /etc/apcupsd/apcupsd.conf
/etc/init.d/apcupsd restart
Stopping UPS power management: apcupsd.
Starting UPS power management: apcupsd.
apcaccess status | grep UPSNAME
UPSNAME  : Back-UPS_ES_525
You can check the state ouninterrupted power supply unit with command:
apcaccess status
After that you can start tweaking by editing /etc/apcupsd/apcupsd.conf file the more so because it is furnished with abundant of comments.

Personnaly I am interested only in item MINUTES where I set value 30. This item claims the number of minutes before end of battery the server is to shutdown.

BTW the time left before battery's death can be checked using the following command:
apcaccess status | grep TIMELEFT
TIMELEFT :  40.8 Minutes
What I was guided by: if power supply was not restored in 10 minutes then it won't be so in nearest future. And extra half of an hour you can listen to the music from your laptop using the rest power of battery. Ж:-)) 

If your server is heavy with plenty of virtual machines then I strongly recommend you to calculate the time it needs to shutdown and give it a reserve of 10 minutes.
Enhanced by Zemanta

No comments:

Post a Comment