Difference between revisions of "Linux/Services/Ups"

From Iveze
Jump to: navigation, search
Line 18: Line 18:
  
 
Basically apcupsd will now shutdown this server when there is a power cut. If there are other servers that must be shutdown too, you can make use of the internal NIS server that communicates Ups events to other servers where apcupsd is installed too. More information about that is in the [http://www.apcupsd.org/manual/manual.html manual] of apcupsd.   
 
Basically apcupsd will now shutdown this server when there is a power cut. If there are other servers that must be shutdown too, you can make use of the internal NIS server that communicates Ups events to other servers where apcupsd is installed too. More information about that is in the [http://www.apcupsd.org/manual/manual.html manual] of apcupsd.   
 +
 +
We prefer to shutdown the other servers from this server via ssh. Therefore we must override default behaviour of the script '''apccontrol. '''Do not edit this script, because it will be overwritten with an update. The case options in the script can be overridden by adding an '''executable''' script with the same name to /etc/apcupsd. We add two override scripts. 
 +
 +
doshutdown 
 +
#!/bin/sh<br>
 +
 +
# redirect all output to file
 +
exec >>/var/log/apcupsd.events 2>&1<br>
 +
<br>
 +
echo "$(/bin/date) Shutdown start"<br>
 +
 +
# use ip's because the DNS server may go down at some time
 +
/usr/bin/ssh root@192.168.1.1 'shutdown -h +1' & # servername1<br>
 +
/usr/bin/ssh root@192.168.1.2 'shutdown -h +1' & # servername2<br>
 +
 +
echo "$(/bin/date) Shutdown stop"<br>
 +
 +
# prevent default action (this machine is not shutdown automatically)
 +
exit 99
 +
doreboot
 +
#!/bin/sh<br>
 +
 +
# redirect all output to file
 +
exec >>/var/log/apcupsd.events 2>&1<br>
 +
 +
# We do not know if reboots are desirable, so we do nothing but prevent them <br>
 +
echo "$(/bin/date) Reboot start"<br>
 +
echo "Reboot not done"<br>
 +
echo "$(/bin/date) Reboot stop"<br>
 +
 +
# prevent default action (this machine is not rebooted automatically)
 +
exit 99
 +
Ssh will only work in scripts without password.
  
 
=== Selinux ===
 
=== Selinux ===

Revision as of 16:07, 11 June 2015

Shutdown the servers before the Uninterruptible Power Supply is completely drained.

Use case

A Ups is great to avoid hard shutdowns of servers with short power cuts. But what if the power is interrupted for a longer time than the battery can provide the servers? For such cases there is software that shuts down the servers at a certain percentage of battery drainage.

Apcupsd

Apcupsd is software specifically for Apc Ups-es. The hardware link between the Ups and a server is (often) a Usb cable. Apc Ups-es come with an odd cable, with on one end a Usb connector and on the other end something that looks like a Utp connector. One server can be connected with the Ups. Other servers must be shutdown from that connected server.

Install

Apcupsd is in the non standard Epel repository.

yum install apcupsd

Connect the usb cable to the Ups and start the service and make it auto start at boot.

Run apcaccess to check if the Ups is found. It will display several parameters of the Ups.

Configure

The configuration files are in the directory
/etc/apcupsd
The most interesting variable in apcupsd.conf is
BATTERYLEVEL 50
Here it is set to initiate shutdown at 50% battery level. Be sure there is enough battery for the time the server needs to shutdown.

Basically apcupsd will now shutdown this server when there is a power cut. If there are other servers that must be shutdown too, you can make use of the internal NIS server that communicates Ups events to other servers where apcupsd is installed too. More information about that is in the manual of apcupsd.

We prefer to shutdown the other servers from this server via ssh. Therefore we must override default behaviour of the script apccontrol. Do not edit this script, because it will be overwritten with an update. The case options in the script can be overridden by adding an executable script with the same name to /etc/apcupsd. We add two override scripts.

doshutdown

#!/bin/sh
# redirect all output to file exec >>/var/log/apcupsd.events 2>&1

echo "$(/bin/date) Shutdown start"
# use ip's because the DNS server may go down at some time /usr/bin/ssh root@192.168.1.1 'shutdown -h +1' & # servername1
/usr/bin/ssh root@192.168.1.2 'shutdown -h +1' & # servername2
echo "$(/bin/date) Shutdown stop"
# prevent default action (this machine is not shutdown automatically) exit 99

doreboot

#!/bin/sh
# redirect all output to file exec >>/var/log/apcupsd.events 2>&1
# We do not know if reboots are desirable, so we do nothing but prevent them
echo "$(/bin/date) Reboot start"
echo "Reboot not done"
echo "$(/bin/date) Reboot stop"
# prevent default action (this machine is not rebooted automatically) exit 99

Ssh will only work in scripts without password.

Selinux

Alternatives

Nut is a generic software, suitable for more Ups brands than Apc.