A simple how-to install Apcupsd on Centos 7. ApcUpsD is a Daemon for APC UPS’s. A UPS is a big battery to keep the servers running when power fails and eventually shutdown clean when batteries are about to run out of juice. The install process is pretty straightforward.
The install package for Centos is not in default repo’s, we need to add the epel repository:
yum install epel-release yum update -y yum install apcupsd
Once installed best to set it up as start service, this is easily forgotten so let’s do that first :
chkconfig apcupsd on
Now configure the settings first in
/etc/apcupsd/apcupsd.conf these are my settings for a master server (server that is physically connected to usb/serial) :
## apcupsd.conf v1.1 ## #svennd UPSNAME UpsRackOne UPSCABLE usb UPSTYPE usb DEVICE LOCKFILE /var/lock SCRIPTDIR /etc/apcupsd PWRFAILDIR /etc/apcupsd NOLOGINDIR /etc # delay in s after power over battery (buffer for hikups) ONBATTERYDELAY 6 # less then x % battery level = shutdown BATTERYLEVEL 1 # less then x min power = shutdown MINUTES 5 # 0 : disable +0 : shutdowntimer on battery (testing) TIMEOUT 0 # tell the user x s before shutdown - linked to NOLOGON ANNOY 30 # initial delay after power failure ANNOYDELAY 60 # NOLOGON [ disable | timeout | percent | minutes | always ] NOLOGON disable # after shutdown does apcups need to keep up ? KILLDELAY 0 # netconfig NETSERVER on NISIP 0.0.0.0 NISPORT 3551 EVENTSFILE /var/log/apcupsd.events EVENTSFILEMAX 10 UPSCLASS standalone UPSMODE disable STATTIME 0 STATFILE /var/log/apcupsd.status LOGSTATS off DATATIME 0
note: these settings shutdown the server down pretty fast, I prefer to control the shutdown than to keep them up as long as possible.
After this, you can start the service, but preferably you should run through the testing first.
service apcupsd start
Now setting up a slave server is also possible, this server will use the network to listen to a master server (data connected to ups) for possible power failures. Note that you require to open the 3551 port on the master in order to be able to communicate.
## apcupsd.conf v1.1 ## # svennd UPSNAME ALFA UPSCABLE ether UPSTYPE net DEVICE 184.108.40.206:3551 LOCKFILE /var/lock # default is 10 - testing POLLTIME 5 # stuff SCRIPTDIR /etc/apcupsd PWRFAILDIR /etc/apcupsd NOLOGINDIR /etc # settings ONBATTERYDELAY 6 BATTERYLEVEL 5 MINUTES 6 TIMEOUT 0 ANNOY 300 ANNOYDELAY 60 NOLOGON disable KILLDELAY 0 # no netservice on this machine # netservice needed for service :/ NETSERVER on NISIP 0.0.0.0 EVENTSFILE /var/log/apcupsd.events EVENTSFILEMAX 10 UPSCLASS standalone UPSMODE disable STATTIME 0 STATFILE /var/log/apcupsd.status LOGSTATS off DATATIME 0
note: change & test all value’s but be sure to change DEVICE to your master server.
Pitfalls & Remarks
1. communication failure
For some reason my UPS’s stop communicating now and again, so don’t start shutting down the moment they lose communication. This is even a bigger issue on busy networks. Be sure to also put the switch on the UPS.
2. reading status
For Centos 6 you could use
service apcupsd status for systemD systems (Centos 7) this does not work any longer, and you can use :
3. custom actions
You can adapt the actions the daemon will take on certain events. For example on commfailure you can edit :
4. Windows crybaby
Apcupsd is a cross platform tool, you can install it on Windows servers. The network guys however called the apcupsd network activity “suspicious”, and wrongly marked the machine as infected.
Apcupsd has a really nice online manual if you get stuck somewhere that is a good point to start.