Gli ups APC e linux


L'ups è indespensabile ma se non comunica con il sistema serve a ben poco perchè, presto o tardi la batteria si esaurisce ed il sistema si spegne di botto mettendo a rischio filesystem e database.
Vediamo come si comportano gli ups Apc e come configurare il software di controllo su linux

Per chi (spero pochi) non abbia mai avuto a che fare con un ups, l'ups o "gruppo di continuità" è un'accessorio indispensabile per OGNI pc e server tanto che io personalmente non lo considero un'accessorio.
Cosa fa? L'ups non è altro che un dispositivo contenente una (o più) batterie che intervengono in caso di mancanza di corrente dalla rete elettrica (ad es. quando scatta il contatore) ma non solo. Un buon ups corregge anche gli sbalzi di tensione, sia i picchi positivi (eccesso di corrente dalla rete) che quelli negativi (difetto di corrente), protegge, per quanto possibile da scariche elettrostatiche come il fulmine. I modelli pensati per la casa hanno addirittura un filtro per la linea telefonica (primo elemento a trasmettere scariche elettrostatiche).
Esistono vari tipi di ups (tra questi anche quelli che fanno schifo e che non servono a nulla) ma non ne discuto perchè ci vorrebbe un libro e non sono nemmeno in grado di farlo.

Gli ups Apc possono essere collegati al pc mediante porta seriale o usb. Alcuni modelli hanno il doppio connettore. In questo post mi concentro sulla connessione usb perchè i modelli prodotti dopo il 2000 sono quasi tutti usb.



Ecco as es. lo smart-ups 750VA, ups da rack a 19" molto diffuso:


 
 
Collegando l'ups al pc via usb, questo è il messaggio che appare in syslog (kernel 2.6.x) :
Oct 23 21:16:49 agata kernel: [233137.424717] usb 1-1: new low speed USB device using uhci_hcd and address 4
Oct 23 21:16:49 agata kernel: [233137.568686] usb 1-1: configuration #1 chosen from 1 choice
Oct 23 21:16:51 agata kernel: [233139.631054] hiddev96hidraw0: USB HID v1.10 Device [American Power Conversion Smart-UPS 750 RM FW:615.3.I USB FW:1.5] on usb-0000:00:1d.0-1
Oct 23 21:16:51 agata kernel: [233139.631054] usb 1-1: New USB device found, idVendor=051d, idProduct=0002
Oct 23 21:16:51 agata kernel: [233139.631054] usb 1-1: New USB device strings: Mfr=3, Product=1, SerialNumber=2
Oct 23 21:16:51 agata kernel: [233139.631054] usb 1-1: Product: Smart-UPS 750 RM FW:615.3.I USB FW:1.5
Oct 23 21:16:51 agata kernel: [233139.631054] usb 1-1: Manufacturer: American Power Conversion
Oct 23 21:16:51 agata kernel: [233139.631054] usb 1-1: SerialNumber: AS0452211182


Il software che, in linux, si occupa della gestione degli ups apc è l'ottimo apcupsd del quale è assolutamente consigliata la lettura del manuale (formato pdf) per comprenderne i meccanismi: su debian etc, lenny 32/64 bitsi installa cosi:

apt-get install apcupsd

termina con:

Setting up apcupsd (3.12.4-2) ...
Please check your configuration  ISCONFIGURED in /etc/default/apcupsd

Apcupsd si può configurare in modalità standalone oppure master/slave. Standalone è quando per ciascun pc si ha un ups, mentre slave/master è quando si ha un ups condiviso con più di un pc.
Questo è un buon file di configurazione per la modalità standalone:

## apcupsd.conf v1.1 ##        #do not mess with this
################################################################
## apcupsd.conf
#
# This configuration file works on:
# ---------------------------------------------
# IBM X206 and APC SmartUPS 750VA usb
# os:            debian etch 32/64bit
# kernel:        2.6.26-1-amd64 (official)
# apcupsd daemon:    apcupsd 3.12.4 (19 August 2006)
# ---------------------------------------------
#
################################################################

# CONFIG
#
#   Use this to give your UPS a name in log files and such. This
#   is particulary useful if you have multiple UPSes. This does not
#   set the EEPROM. It should be 8 characters or less.
UPSNAME luppolo

#   Defines the type of cable connecting the UPS to your computer.
UPSCABLE usb
#UPSTYPE usb
UPSTYPE usb

DEVICE             #do not mess with this
LOCKFILE /var/lock    #do not mess with this

# The ONBATTERYDELAY is the time in seconds from when a power failure
#   is detected until apccontrol will react and notify the power failure.
#   In this case we want to be notified only when the failure lasts more than 6 seconds
ONBATTERYDELAY 6

# If during a power failure, the remaining battery percentage
# (as reported by the UPS) is below or equal to BATTERYLEVEL,
# apcupsd will initiate a system shutdown.
BATTERYLEVEL 5 #%

# If during a power failure, the remaining runtime in minutes
# (calculated by the UPS) is below or equal to MINUTES,
# apcupsd, will initiate a system shutdown.
MINUTES 8

# If during a power failure, the UPS has run on batteries for TIMEOUT
# seconds or longer, apcupsd will initiate a system shutdown.
# A value of 0 disables this timer.
TIMEOUT 0        #do not mess with this

# Initial delay after power failure before warning users to get
# off the system.
ANNOYDELAY 90         #hopefully we will have at least 90 seconds of charge :-)

#  Time in seconds between annoying users to signoff prior to
#  system shutdown. 0 disables.
#  This is how frequently the message will be prompted to the user
ANNOY 30       

# The condition which determines when users are prevented from
# logging in during a power failure.
# NOLOGON <string> [ disable | timeout | percent | minutes | always ]
NOLOGON disable        #do not mess with this if you are not in a big network with many users

# If KILLDELAY is non-zero, apcupsd will continue running after a
# shutdown has been requested, and after the specified time in
# seconds attempt to kill the power. This is for use on systems
# where apcupsd cannot regain control after a shutdown.
# KILLDELAY <seconds>  0 disables
KILLDELAY 0        #do not mess with this

#########################
# NIS (Network Information Server) parameters
# http://www.linux-nis.org/nis/
#
# do not mess with these parameters if you are not configuring apcupsd to work with a master a some slaved daemons running on other machines
#NETSERVER off
#NISIP 127.0.0.1
#NISPORT 3551
#EVENTSFILE /var/log/apcupsd.events
#EVENTSFILEMAX 10
#########################

#########################
# Network parameters
#
# The configuration statements below are used if you want to share one
# UPS to power multiple machines and have them communicate by the network.
#
# do not mess with this if you are running one ups per machine
#########################
UPSCLASS standalone
UPSMODE disable

#########################
# Logging informations
#########################

# Time interval in seconds between writing the STATUS file; 0 disables
STATTIME 300

# Location of STATUS file (written to only if STATTIME is non-zero)
STATFILE /var/log/apcupsd.status

# LOGSTATS [ on | off ] on enables, off disables
# Note! This generates a lot of output, so if        
#       you turn this on, be sure that the
#       file defined in syslog.conf for LOG_NOTICE is a named pipe.
#  You probably do not want this on.
LOGSTATS off

# Time interval in seconds between writing the DATA records to
#   the log file. 0 disables.
DATATIME 0

# FACILITY defines the logging facility (class) for logging to syslog.
#          If not specified, it defaults to "daemon". This is useful
#          if you want to separate the data logged by apcupsd from other
#          programs.
FACILITY DAEMON

Una volta sistemato il file di configurazione si può modificare il file /etc/default/apcupsd in modo che il servizio si possa avviare:

vim /etc/default/apcupsd

ISCONFIGURED=yes

Mediante l'applicazione apcaccess posso ottenere importanti informazioni sull'ups.
Il servizio apcupsd deve essere stato avviato almeno 15 secondi prima di lanciare apcaccess altrimenti potremmo ottenere questo errore:

agata:/etc/apcupsd# 2v_ups_control
FATAL ERROR in apcaccess.c at line 252
tcp_open: cannot connect to server localhost on port 3551.
apcaccess status

APC      : 001,040,0983
DATE     : Sun Oct 26 23:50:32 CET 2008
HOSTNAME : agata
RELEASE  : 3.12.4
VERSION  : 3.12.4 (19 August 2006) debian
UPSNAME  : luppolo
CABLE    : USB Cable
MODEL    : Smart-UPS 750 RM
UPSMODE  : Stand Alone
STARTTIME: Sun Oct 26 23:44:50 CET 2008
STATUS   : ONLINE
LINEV    : 227.5 Volts
LOADPCT  :  27.3 Percent Load Capacity BCHARGE  : 100.0 Percent TIMELEFT :  42.0 Minutes MBATTCHG : 5 Percent
MINTIMEL : 8 Minutes
MAXTIME  : 0 Seconds
OUTPUTV  : 227.5 Volts
DWAKE    : -01 Seconds
DSHUTD   : 090 Seconds
LOTRANS  : 208.0 Volts
HITRANS  : 253.0 Volts
RETPCT   : 000.0 Percent
ITEMP    : 34.6 C Internal
ALARMDEL : Always
BATTV    : 27.3 Volts
LINEFREQ : 50.0 Hz
LASTXFER : No transfers since turnon
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x07000008 Status Flag
SERIALNO : AS0453211882
BATTDATE : 2004-12-30
NOMBATTV :  24.0
FIRMWARE : 15.3.I USB FW:1.5
APCMODEL : Smart-UPS 750 RM
END APC  : Sun Oct 26 23:50:40 CET 2008

Questi sono i 3 parametri fondamentali:

LOADPCT  :  27.3 Percent Load Capacity <--- indica quanto stanno assorbendo le periferiche collegate all'ups. All'incrementarsi di questo valore diminuisce proporzionalmente la durata del periodo di alimentazione in assenza di corrente dalla rete elettrica.

BCHARGE  : 100.0 Percent  <--- indica quanto è carica la batteria. Se l'ultima volta che è andata via la corrente è stato più di 6 ore fa, allora il valore dovrebbe indicare 100%. Viceversa c'è qualche problema alle batterie e probabilmente si è acceso il led rosso sul frontale (quello con il simbolo della batteria che contiene una "X")

TIMELEFT :  42.0 Minutes  <--- è una stima del periodo di alimentazione in assenza di corrente dalla rete elettrica.

Sono pronto per avviare il servizio:

Oct 23 21:22:04 agata apcupsd[5497]: NIS server startup succeeded
Oct 23 21:22:04 agata apcupsd[5497]: apcupsd 3.12.4 (19 August 2006) debian startup succeeded


I parametri che apcaccess mi mostra sono incoraggianti ma che succede se tolgo la corrente? Il test è d'obbligo ma prima mi premuro di fare il backup, quanto meno dei database e di ciò che più importante. Arresto i servizi (se è un server va verificato che non ci siano utenti collegati) e .... (rullo di tamburi) stacco la spina di alimentazione dell'ups. (NB. sembra una pirlata ma fate attenzione a non staccare il cavo che alimenta il pc!)
Questo è quanto vedo in syslog:

Broadcast Message from root@agata                                             
        (somewhere) at 21:24 ...                                           
Warning power loss detected on UPS luppolo                                    
                                              
Oct 23 21:24:00 agata apcupsd[5497]: Power failure.
                                                                              
Broadcast Message from root@agata                                             
        (somewhere) at 21:24 ...
Power failure on UPS luppolo. Running on batteries.                           
                                                                              
Oct 23 21:24:06 agata apcupsd[5497]: Running on UPS batteries.
Oct 23 21:24:06 agata postfix/pickup[5424]: A0EF4FA0024: uid=0 from=<root>
Oct 23 21:24:06 agata postfix/cleanup[5514]: A0EF4FA0024: message-id=<20081023192406.A0EF4FA0024@agata.2v.ntw>
Oct 23 21:24:06 agata postfix/qmgr[2765]: A0EF4FA0024: from=<root@agata.2v.ntw>, size=1450, nrcpt=1 (queue active)
Oct 23 21:24:06 agata postfix/cleanup[5514]: A611EFA0025: message-id=<20081023192406.A0EF4FA0024@agata.2v.ntw>
Oct 23 21:24:06 agata postfix/qmgr[2765]: A611EFA0025: from=<root@agata.2v.ntw>, size=1577, nrcpt=1 (queue active)
Oct 23 21:24:06 agata postfix/local[5518]: A0EF4FA0024: to=<root@agata.2v.ntw>, orig_to=<root>, relay=local, delay=0.04, delays=0.03/0.01/0/0, dsn=2.0.0, status=sent (forwarded as A611EFA0025)
Oct 23 21:24:06 agata postfix/qmgr[2765]: A0EF4FA0024: removed
Oct 23 21:24:06 agata postfix/smtp[5519]: A611EFA0025: to=<notyourbusiness@squadrainformatica.com>, orig_to=<root>, relay=brunilde.2v.ntw[192.168.0.2]:25, delay=0.31, delays=0/0.01/0.11/0.19, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 3A2051CE322)
Oct 23 21:24:06 agata postfix/qmgr[2765]: A611EFA0025: removed
                                                                              
Broadcast Message from root@agata                                             
        (somewhere) at 21:24 ...                                              
                                                                              
Power has returned on UPS luppolo...                                          

                                                                              
Oct 23 21:24:27 agata apcupsd[5497]: Mains returned. No longer on UPS batteries.
Oct 23 21:24:27 agata apcupsd[5497]: Power is back. UPS running on mains.
Oct 23 21:24:28 agata postfix/pickup[5424]: 7C1C2FA0024: uid=0 from=<root>
Oct 23 21:24:28 agata postfix/cleanup[5514]: 7C1C2FA0024: message-id=<20081023192428.7C1C2FA0024@agata.2v.ntw>
Oct 23 21:24:28 agata postfix/qmgr[2765]: 7C1C2FA0024: from=<root@agata.2v.ntw>, size=1480, nrcpt=1 (queue active)
Oct 23 21:24:28 agata postfix/cleanup[5514]: 7ED33FA0025: message-id=<20081023192428.7C1C2FA0024@agata.2v.ntw>
Oct 23 21:24:28 agata postfix/local[5518]: 7C1C2FA0024: to=<root@agata.2v.ntw>, orig_to=<root>, relay=local, delay=0.02, delays=0.01/0/0/0, dsn=2.0.0, status=sent (forwarded as 7ED33FA0025)
Oct 23 21:24:28 agata postfix/qmgr[2765]: 7C1C2FA0024: removed
Oct 23 21:24:28 agata postfix/qmgr[2765]: 7ED33FA0025: from=<root@agata.2v.ntw>, size=1607, nrcpt=1 (queue active)
Oct 23 21:24:28 agata postfix/smtp[5519]: 7ED33FA0025: to=<notyourbusiness@squadrainformatica.com>, orig_to=<root>, relay=brunilde.2v.ntw[192.168.0.2]:25, delay=0.1, delays=0/0/0.02/0.08, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as CD5ED1CE322)
Oct 23 21:24:28 agata postfix/qmgr[2765]: 7ED33FA0025: removed

Poichè il server che sto monitorando è in grado di inviare email (è un smtp server) apccontrol, il programma che provvede alla gestione degli eventi generati dall'ups, invia una email a root avvisandolo del problema.

Questa è la mail che ricevo

Subject: agata Power Failure !!!
 
agata Power Failure !!!
 
APC      : 001,041,1018
DATE     : Thu Oct 23 21:24:02 CEST 2008
HOSTNAME : agata
RELEASE  : 3.12.4
VERSION  : 3.12.4 (19 August 2006) debian
UPSNAME  : luppolo
CABLE    : USB Cable
MODEL    : Smart-UPS 750 RM
UPSMODE  : Stand Alone
STARTTIME: Thu Oct 23 21:21:51 CEST 2008
STATUS   : ONBATT
LINEV    : 000.0 Volts
LOADPCT  :  30.5 Percent Load Capacity
BCHARGE  : 090.0 Percent
TIMELEFT :  36.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 8 Minutes
MAXTIME  : 0 Seconds
OUTPUTV  : 229.3 Volts
DWAKE    : -01 Seconds
DSHUTD   : 090 Seconds
LOTRANS  : 208.0 Volts
HITRANS  : 253.0 Volts
RETPCT   : 000.0 Percent
ITEMP    : 36.9 C Internal
ALARMDEL : Always
BATTV    : 23.8 Volts
LINEFREQ : 50.0 Hz
LASTXFER : Low line voltage
NUMXFERS : 1
XONBATT  : Thu Oct 23 21:24:00 CEST 2008
TONBATT  : 6 seconds
CUMONBATT: 6 seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x07060010 Status Flag
SERIALNO : AS0453211882
BATTDATE : 2004-12-30
NOMBATTV :  24.0
FIRMWARE : 15.3.I USB FW:1.5
APCMODEL : Smart-UPS 750 RM
END APC  : Thu Oct 23 21:24:06 CEST 2008


 

dotmap: 

Commenti

answer this topic

If you want to buy a house, you will have to receive the mortgage loans. Moreover, my mother always uses a commercial loan, which supposes to be the most firm.

Invia nuovo commento

Il contenuto di questo campo è privato e non verrà mostrato pubblicamente.
  • Indirizzi web o e-mail vengono trasformati in link automaticamente
  • Elementi HTML permessi: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Linee e paragrafi vanno a capo automaticamente.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.

Ulteriori informazioni sulle opzioni di formattazione

CAPTCHA
Questa domanda serve per verificare che tu sia un visitatore umano (non un computer) e per prevenire lo spam
Image CAPTCHA
Scrivi ció che vedi nella immagine.