UPS e Linux
Da Wizard linux team wiki.
Mi è capitato di giocare con un APC Smart-UPS 1000 ed anche qui quando si dice che in certi casi, e più il tempo passa e più ce ne sono, Linux è più facile di Winzozz si dice una sacrosanta verità.
- installare il pacchetto apcupsd (standard in linux)
- attacchiamo l'USB e lanciamo il comando apcaccess status
- otteniamo una serie di indicazioni che riporto interamente sotto evidenziando in grassetto la parte interessante.
APC : 001,038,0928
DATE : Sun Feb 26 15:48:24 CET 2006
HOSTNAME : pcmorpheus
RELEASE : 3.10.18
VERSION : 3.10.18 (21 July 2005) mandrake
UPSNAME : pcmorpheus
CABLE : USB Cable
MODEL : Smart-UPS 1000
UPSMODE : Stand Alone
STARTTIME: Sun Feb 26 15:39:48 CET 2006
STATUS : ONLINE
LINEV : 236.1 Volts
LOADPCT : 25.3 Percent Load Capacity
BCHARGE : 100.0 Percent
TIMELEFT : 56.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
OUTPUTV : 236.1 Volts
DWAKE : -01 Seconds
DSHUTD : 090 Seconds
LOTRANS : 208.0 Volts
HITRANS : 253.0 Volts
ITEMP : 35.5 C Internal
ALARMDEL : Always
BATTV : 27.3 Volts
LINEFREQ : 50.0 Hz
NUMXFERS : 0
TONBATT : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x02000008 Status Flag
SERIALNO : AS0544125052
BATTDATE : 2005-10-31
NOMBATTV : 24.0
FIRMWARE : 52.12.I USB FW:4.2
APCMODEL : Smart-UPS 1000
END APC : Sun Feb 26 15:48:25 CET 2006
Se visualizzate quanto sopra è bene ... io non ho avuto problemi fino a qui se voi li avete contattatemi.
- Scrivete dalla konsole da root "tail -f /var/log/messages
- Staccatte la corrente dall'UPS e vedrete apparire tra le altre informazioni
apcupsd[7507]: Power failure
apcupsd[7507]: Running on UPS batteries.
e poi quest'altra apcupsd[10111]: Cannot exec /etc/apcupsd/apccontrol onbattery: No such file or directory
- Riattaccate la spina all'ups e vedrete apcupsd[7507]: Mains returned. No longer on UPS batteries.
- Ora c'è la configurazione dell'apccontrol (il file che appunto non trovava). Questo file è uno script bash che esegue comandi prendendo in considerazione i messaggi che apcups monitorizza.
- Il gioco è fatto. Di seguito metto il mio apccontrol come esempio.
#!/bin/sh
#
# Safe apccontrol for testing.
#
# This apccontrol can be used for testing without fear
# that it will bring your system down
# examples/safe.apccontrol. Generated from safe.apccontrol.in by configure.
#
prefix=/usr
exec_prefix=/usr
APCUPSD=/sbin/apcupsd
SHUTDOWN=/sbin/shutdown
SCRIPTDIR=/etc/apcupsd
#
case "$1" in
killpower)
wall <<EOF
apccontrol: ${APCUPSD} --killpower would have been.
EOF
;;
commfailure)
wall <<EOF
apccontrol: Warning serial port communications with UPS lost.
EOF
;;
commok)
wall <<EOF
apccontrol: Serial communciations with UPS restored.
EOF
;;
powerout)
wall <<EOF
apccontrol: Warning power loss detected.
EOF
;;
onbattery)
/sbin/shutdown -h +10 "Power Failure; System Shutting Down in 10 minutes"
wall <<EOF
apccontrol: Power failure. Running on UPS batteries.
EOF
;;
offbattery)
/sbin/shutdown -c
wall <<EOF
apccontrol: Off battery. Mains returned.
EOF
;;
failing)
/sbin/shutdown -h now
wall <<EOF
apccontrol: UPS battery power exhaused. Doing shutdown.
EOF
;;
timeout)
/sbin/shutdown -h now
wall <<EOF
apccontrol: UPS battery runtime limit exceeded. Doing shutdown.
EOF
;;
loadlimit)
/sbin/shutdown -h now
wall <<EOF
apccontrol: UPS battery discharge limit reached. Doing shutdown.
EOF
;;
runlimit)
/sbin/shutdown -h now
wall <<EOF
apccontrol: UPS battery runtime percent reached. Doing shutdown.
EOF
;;
doreboot)
wall <EOF
apccontrol: ${SHUTDOWN} for reboot would have been called.
EOF
;;
doshutdown)
wall <<EOF
apccontrol: ${SHUTDOWN} for halt would have been called.
EOF
;;
mainsback)
/sbin/shutdown -c
wall <<EOF
apccontrol: Power has returned...
EOF
;;
annoyme)
wall <<EOF
apccontrol: Power problems please logoff.
EOF
;;
emergency)
wall <<EOF
apccontrol: ${SHUTDOWN} for emergency halt would have been called.
EOF
;;
changeme)
wall <<EOF
apccontrol: Emergency! UPS batteries have failed.
Change them NOW !
EOF
;;
remotedown)
wall <<EOF
apccontrol: ${SHUTDOWN} for remote halt would have been called.
EOF
;;
restartme)
wall <<EOF
apccontrol: restarting apcupsd would have been called.
EOF
;;
startselftest)
wall <<EOF
apccontrol: start self test would have been called.
EOF
;;
endselftest)
wall <<EOF
apccontrol: end self test would have been called.
EOF
;;
mastertimeout)
wall <<EOF
apccontrol: Warning connection from master lost.
EOF
;;
masterconnect)
wall <<EOF
apccontrol: Connection from master established.
EOF
;;
*) echo "Usage: ${0##*/} command"
echo " warning: this script is intended to be launched by"
echo " apcupsd and should never be launched by users."
exit 1
;;
esac

