Skip to content

Instantly share code, notes, and snippets.

@laubstein
Last active December 26, 2023 18:10
Show Gist options
  • Save laubstein/23e7bdd237ba9807acf810d0b94431fd to your computer and use it in GitHub Desktop.
Save laubstein/23e7bdd237ba9807acf810d0b94431fd to your computer and use it in GitHub Desktop.
Raspberry - Configurar APCUPSD

Raspberry - Configurar APCUPSD

Modelo de no-break testado: APC Back-UPS BX 1500BI-BR
Raspberry Pi: RPi 3 Model B+
SO: DietPi v8.25.1

Instalação dos Softwares Necessários

apt-get -y install apcupsd apcupsd-cgi lighttpd

Configuração do Serviço

  1. Comentar linha DEVICE
cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.original
sed -i 's/^DEVICE/#DEVICE/' /etc/apcupsd/apcupsd.conf
  1. Definir configuração como concluída
sed -i 's/=no/=yes/' /etc/default/apcupsd
  1. Reiniciar serviço
service apcupsd restart
  1. Verificar status do serviço
# apcaccess status

APC      : 001,036,0867
DATE     : 2023-12-26 17:47:09 +0000  
HOSTNAME : DietPi
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : DietPi
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2023-12-26 17:47:07 +0000  
MODEL    : Back-UPS BX 1500BI-BR 
STATUS   : ONLINE 
LINEV    : 129.0 Volts
LOADPCT  : 0.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 83.4 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 93.0 Volts
HITRANS  : 150.0 Volts
ALARMDEL : No alarm
BATTV    : 28.4 Volts
LASTXFER : Unacceptable line voltage changes
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NG
STATFLAG : 0x05000008
SERIALNO : 5B2316WJ0681
BATTDATE : 2023-05-09
NOMINV   : 115 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 900 Watts
FIRMWARE : V586 -USB FW:A8
END APC  : 2023-12-26 17:47:34 +0000

Configuração do Lighttpd

Após a configuração abaixo, o status do no-break poderá ser visualizado em http://dietpi.localdomain/apcupsd/upsstats.cgi

cat << EOF > /etc/lighttpd/conf-enabled/20-ups.conf
server.modules += ( "mod_cgi" )
\$HTTP["url"] =~ "^/apcupsd/" {
  alias.url += ( "/apcupsd/" => "/usr/lib/cgi-bin/apcupsd/" )
  server.dir-listing = "enabled"
  cgi.assign = (
    "" => "",
  )
}
EOF
systemctl restart lighttpd

image

Configuração de scripts de eventos

Quando ocorre um evento, os scripts localizados em /etc/apcupsd são executados.

  • onbattery - executado quando operando com bateria
  • offbattery - executado quando a energia é reestabelecida
  • changeme - executado quando a bateria precisa ser substituída
  • commfailure - a comunicação com o no-break falhou
  • commok - a comunicação com o no-break foi reestabelecida
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment