Differences between revisions 8 and 9
Revision 8 as of 2021-08-24 17:27:59
Size: 27508
Editor: ThiagoPezzo
Comment: fix language code, main title in pt_BR, add category, add fixme warnings
Revision 9 as of 2021-08-24 18:21:55
Size: 27507
Editor: ThiagoPezzo
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
<!> ''Está página está muito desatualizada.'' <!> ''Esta página está muito desatualizada.''

Traduções: English - Português (Brasil)


<!> Esta página está muito desatualizada.

Apcupsd pode ser utilizado para controlar e gerenciar a maior parte dos modelos de no-break APC, incluíndo os modelos de sinais mais simples como os Back-UPS e BackUPS-Office.

Durante uma falha de energia ou outros eventos, apcupsd pode executar um script de ação para por exemplo enviar mensagem para todos usuários a respeito da falha de energia, ou enviar um email de alerta ou relatórios, ou executar um desligamento programado dos computadores afetados pelo sistema.

Instalação

Para instalar a documentação do apcupsd, execute:

$ sudo apt-get install apcupsd apcupsd-doc

Configurando (Dispositivo UPS sozinho)

Primeiro plugue o cabo no servidor.

Para verificar se o no-break foi reconhecido execute o comando::

  $ lsusb
  Bus 001 Device 002: ID 051d:0002 American Power Conversion Back-UPS Pro 500/1000/1500

Daemon

O daemon é o serviço que controla e monitora o status do no-break e permite ao computador permanecer ativo por um determinado período de tempo na bateria do no-break, e então executa um desligamento controlado em caso de falha extendida de energia.

Antes de iniciar o daemon, você precisa configurar o mínimo necessário nosr aquivos /etc/apcupsd/apcupsd.conf and /etc/default/apcupsd.

Em /etc/apcupsd/apcupsd.conf, você deve especificar o tipo de no-break :

UPSCABLE : o tipo de cabo conectado ao seu computador.
UPSTYPE : o tipo de no-break que você tem (USB, RS232,…)
DEVICE : o tipo de dispositivo

e em /etc/default/apcupsd, você indica que a configuração no arquivo de configurações já foram feitas, trocando o valor da variável ISCONFIGURED para yes.

ISCONFIGURED=yes

Bem. Agora você pode inicializar o daemon com o comando:

# service apcupsd start

O arquivo de log /var/log/apcupsd.events dirá se o daemon iniciou corretamente.

Configurando (Vários No-Breaks)

Os seguintes passos de configurações podem serem usadas para monitorar mais de um no-break a partir de um único computador. Para que seja possível controlar vários no-breaks, alguns passos a mais que não são necessários para configurar um único no-break são necessários.

For multiple UPS monitoring to work, each UPS must be uniquely identifiable and uniquely named on the monitoring computer, separate apcupsd.conf files must be used for each UPS device, and a modified apcupsd init.d script must be used to control multiple apcupsd daemon processes.

The UPS devices used as examples below are two APC SmartUPS SUA1500 devices connected to one computer via USB. One UPS is named "UPS Network" and controls power to networking equipment, and the other UPS is named "UPS Server" and controls power to the computer monitoring both UPSes. Each UPS performs different actions for different events.

Connect each UPS and determine they are visible USB devices

$ lsusb

Bus 004 Device 002: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 008 Device 003: ID 051d:0002 American Power Conversion Uninterruptible Power Supply

Determine the serial numbers for each UPS

The manufacturer and serial number attributes will be used by udev to uniquely identify each UPS on the system.

$ udevadm info --attribute-walk --name=/dev/usb/hiddev0 | egrep 'manufacturer|product|serial'

ATTRS{manufacturer}=="American Power Conversion"
ATTRS{product}=="Smart-UPS 1500 FW:601.3.D USB FW:1.3"
ATTRS{serial}=="AS0000000001"

$ udevadm info --attribute-walk --name=/dev/usb/hiddev1 | egrep 'manufacturer|product|serial'

ATTRS{manufacturer}=="American Power Conversion"
ATTRS{product}=="Smart-UPS 1500 FW:601.3.D USB FW:1.5"
ATTRS{serial}=="AS0000000002"

Create a new udev rules file for the UPS devices. Using the manufacturer and serial number attributes, add a rule for each UPS to create a uniquely named symlink for each UPS. These rules will be automatically run whenever the matching UPS device's USB cable is connected.

$ sudo nano /etc/udev/rules.d/ups.rules

# Network UPS
KERNEL=="hiddev*", ATTRS{manufacturer}=="American Power Conversion", ATTRS{serial}=="AS0000000001", OWNER="root", SYMLINK+="usb/ups-network"

# Server UPS
KERNEL=="hiddev*", ATTRS{manufacturer}=="American Power Conversion", ATTRS{serial}=="AS0000000002", OWNER="root", SYMLINK+="usb/ups-server"

Run the udev rules

$ udevadm trigger --verbose --sysname-match=hiddev*

$ ls -l /dev/usb

crw------- 1 root root 180, 96 Aug 30 10:41 hiddev0
crw------- 1 root root 180, 97 Aug 30 10:41 hiddev1
lrwxrwxrwx 1 root root       7 Aug 30 10:41 ups-network -> hiddev0
lrwxrwxrwx 1 root root       7 Aug 30 10:41 ups-server -> hiddev1

Set up the apcupsd configuration files

The original apcupsd.conf file needs to be removed and replaced with separate config files for each UPS. The conf files need to be named with a pattern matching apcupsd*.conf or the modified init.d script will not find them.

Each configuration files needs to specify a unique UPSNAME, preferably without spaces, as this is the name used by the modified apcupsd init.d script to control individual apcupsd daemons.

Ensure the configuration directives used during power failures are set up appropriately when there are multiple UPSes. Normally, you probably only want the UPS attached to the computer controlling apcupsd to actually be able to shutdown the computer.

Directives which are important for multiple UPS setups are:

Read the apcupsd manual for more information.

$ sudo nano /etc/apcupsd/apcupsd-network.conf

## apcupsd.conf v1.1 ##
# apcupsd-network.conf
# General Configuration Directives
UPSNAME Network
UPSTYPE usb
UPSCABLE usb
DEVICE /dev/usb/ups-network
POLLTIME 60
#LOCKFILE /var/lock

# Configuration Directives Used by the Network Information Server
NETSERVER on
NISIP 127.0.0.1
NISPORT 3551
EVENTSFILE /var/log/apcupsd-network.events
#EVENTSFILEMAX 10

# Configuration Directives used during Power Failures
BATTERYLEVEL -1
MINUTES -1
TIMEOUT 0
ANNOY 0
ANNOYDELAY 0
NOLOGON disable
#NOLOGONDIR /etc
KILLDELAY 0
SCRIPTDIR /etc/apcupsd/scripts-network
PWRFAILDIR /etc/apcupsd/scripts-network

# Configuration Directives used to Control System Logging
STATTIME 0
#STATFILE /var/log/apcupsd-network.status
DATATIME 0
FACILITY DAEMON

# Configuration Directives for Sharing a UPS
UPSCLASS standalone
UPSMODE disable

$ sudo nano /etc/apcupsd/apcupsd-server.conf

## apcupsd.conf v1.1 ##
# apcupsd-server.conf
# General Configuration Directives
UPSNAME Server
UPSTYPE usb
UPSCABLE usb
DEVICE /dev/usb/ups-server
POLLTIME 60
#LOCKFILE /var/lock

# Configuration Directives Used by the Network Information Server
NETSERVER on
NISIP 127.0.0.1
NISPORT 3552
EVENTSFILE /var/log/apcupsd-server.events
#EVENTSFILEMAX 10

# Configuration Directives used during Power Failures
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
#NOLOGONDIR /etc
KILLDELAY 0
SCRIPTDIR /etc/apcupsd/scripts-server
PWRFAILDIR /etc/apcupsd

# Configuration Directives used to Control System Logging
STATTIME 0
#STATFILE /var/log/apcupsd-server.status
DATATIME 0
FACILITY DAEMON

# Configuration Directives for Sharing a UPS
UPSCLASS standalone
UPSMODE disable

Create directory(ies) for event handling scripts

Each directory should be for different versions of the scripts. The scripts can be used by one or more UPSes which you want trigger the same actions. However, if one computer is monitoring multiple UPSes, such as one UPS for a server, and another for networking equipment, you probably want to associate different scripts for different actions for each UPS, which requires different script directories and SCRIPTDIR variables set appropriately in each config file. For instance, you probably want to shutdown the server ONLY when the server's UPS triggers an appropriate event.

$ sudo mkdir /etc/apcupsd/scripts-network
$ sudo mkdir /etc/apcupsd/scripts-server

Copy the apccontrol file to each script directory

$ sudo cp /etc/apcupsd/apccontrol /etc/apcupsd/scripts-network
$ sudo cp /etc/apcupsd/apccontrol /etc/apcupsd/scripts-server

Modify apccontrol scripts to perform actions for monitoring events

For example, on the doshutdown event, you might want to send an email, broadcast a wall message, and then run the shutdown command. See the "onbattery" event in the apccontrol script below for an example.

Since these apccontrol scripts were copied to a non-standard location, they should not be modified when the distribution package manager updates apcupsd, so individual event scripts are not required.

Read the apcupsd manual for more information.

$ sudo nano /etc/apcupsd/scripts-server/apccontrol

#
# apcupsd apccontrol script for multiple UPSes.
#
# This script will be called by apcupsd when an event is detected and raised.
# In order for apccupd to find this file, the SCRIPTDIR must be set to the
# directory containing this script for each apcupsd UPS configuration file. This
# script must also be named apccontrol and marked as executable.
#
# If different UPSes should perform different actions on events, this script
# should be copied and placed in a different SCRIPTDIR for each UPS, and then
# modified for the specific UPS. Obviously, the SCRIPTDIR needs to be updated
# also in each UPS's configuration file.
#
# Note: All events are still logged to the syslog regardless of the actions
# taken by this script.

SHUTDOWN=/sbin/shutdown
APCUPSD=/sbin/apcupsd
WALL=wall
HOSTNAME=$(hostname -f)

MSGTO="admin@example.com"
SMSTO="admincell@example.com"
MSGFROM="root@${HOSTNAME} <root@${HOSTNAME}>"
MSGSUBJ="${HOSTNAME} apcupsd alert: $1 event"


case "$1" in

killpower)

        eventDesc="Apccontrol issuing 'apcupsd --killpower' to power off UPS ${2}."
        echo "$eventDesc" | $WALL
        sleep 10
        $APCUPSD --killpower
        ;;


annoyme)
        # When a shutdown is scheduled, and the time specified on the ANNOYME
        # directive in the apcupsd.conf file expires, this event is generated.
        # Default action: wall a message

        eventDesc="Warning! Power problems with UPS ${2}. Please logoff."
        echo "$eventDesc" | $WALL
        ;;


changeme)
        # When apcupsd detects that the mains are on, but the battery is not
        # functioning correctly, this event is generated. It is repeated every x
        # hours.
        # Default action: wall a message

        eventDesc="Warning! Batteries have failed on UPS ${2}. Change them NOW!"
        echo "$eventDesc" | $WALL
        ;;


commfailure)
        # This event is generated each time the communications line with the
        # computer is severed. This event is not detected on dumb signaling UPSes.
        # Default action: wall a message

        eventDesc="Communications lost with UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


commok)
        # After a commfailure event is issued, when the communications to the
        # computer is re-established, this event will be generated.
        # Default action: wall a message

        eventDesc="Communications restored with UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


doshutdown|doreboot)
        # When the UPS is running on batteries and one of the limits expires (time,
        # run, load), this event is generated to cause the machine to shutdown.
        # Note: The doreboot event is depreciated and should not be used.
        # Default action: Shuts down the system using shutdown -h or similar

        eventDesc="Warning! UPS $2 initiated shutdown sequence on ${HOSTNAME}."
        echo "$eventDesc" | $WALL
        $SHUTDOWN -h now "apcupsd UPS $2 initiated shutdown"
        ;;


emergency)
        # Called for an emergency system shutdown. (What triggers such a shutdown is
        # unclear...) After completing this event, apcupsd will immediately initiate
        # a doshutdown event.
        # Default action: wall a message

        eventDesc="Warning! Possible battery failure on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


failing)
        # This event is generated when the UPS is running on batteries and the
        # battery power is exhausted. The event following this one will be a
        # shutdown.
        # Default action: wall a message

        eventDesc="Battery power exhaused on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


loadlimit)
        # This event is generated when the battery charge is below the low limit
        # specified in the apcupsd.conf file. After completing this event, apcupsd
        # will immediately initiate a doshutdown event.
        # Default action: wall a message

        eventDesc="Remaining battery charge below limit on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


powerout)
        # This event is generated immediately when apcupsd detects that the UPS has
        # switched to batteries. It may be due to a short powerfailure, an automatic
        # selftest of the UPS, or a longer powerfailure.
        # Default action: nothing

        ;;


onbattery)
        # This event is generated 5 or 6 seconds after an initial powerfailure is
        # detected. It means that apcupsd definitely considers the UPS to be on
        # batteries. The onset of this event can be delayed by the ONBATTERYDELAY
        # apcupsd.conf configuration directive.
        # Default action: wall a message

        eventDesc="Power failure on UPS ${2}. Running on batteries."
        echo "$eventDesc" | $WALL

        status=$(service apcupsd report $2)
        echo "$eventDesc\n\n$status" | mail -r "$MSGFROM" -s "$MSGSUBJ" "$MSGTO"

        status=$(service apcupsd sms $2)
        echo "$status" | mail -r "$MSGFROM" -s "$MSGSUBJ" "$SMSTO"


        #messaging.sprintpcs.com
        ;;


offbattery)
        # This event is generated when the mains return only if the onbattery event
        # has been generated.
        # Default action: wall a message

        eventDesc="Power has returned on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


mainsback)
        # This event is generated when the mains power returns after a powerout
        # condition. The shutdown event may or may not have been generated depending
        # on the parameters you have defined and the length of the power outage.
        # Default action: nothing

        ;;


remotedown)
        # This event is generated on a slave machine when it detects either that the
        # master has shutdown, or that a onbattery situation exists and the
        # communications line has been severed.
        # Default action: wall a message

        eventDesc="Remote shutdown by apcupsd."
        echo "$eventDesc" | $WALL
        ;;


runlimit)
        # This event is generated when the MINUTES value defined in the apcupsd.conf
        # file expires while in a power fail condition. The MINUTES is the remaining
        # runtime as internally calculated by the UPS and monitored by apcupsd.
        # After completing this event, apcupsd will immediately initiate a
        # doshutdown event.
        # Default action: wall a message

        eventDesc="Remaining battery runtime below limit on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


timeout)
        # This event is generated when the TIMEOUT value defined in the apcupsd.conf
        # file expires while in a power fail condition. It indicates that the total
        # time in a power failure has been exceeded and the machine should be
        # shutdown. After completing this event, apcupsd will immediately initiate a
        # doshutdown event.
        # Default action: wall a message

        eventDesc="Battery time limit exceeded on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


startselftest)
        # This event is generated when apcupsd detects a self test by the UPS.
        # Normally due to the 6 second onbattery delay default time, self test
        # events are not detected.
        # Default action: nothing

        eventDesc="Performing self-test on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


endselftest)
        # This event is generated when the end of a self test is detected.
        # Default action: nothing

        eventDesc="Completed self-test on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


battdetach)
        # This event is generated when apcupsd detects that the UPS battery has been
        # disconnected.
        # Default action: nothing

        eventDesc="Battery detached on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


battattach)
        # This event is generated when apcupsd detects that the UPS battery has been
        # reconnected after a battdetach event.
        # Default action: noting

        eventDesc="Battery attached on UPS ${2}."
        echo "$eventDesc" | $WALL
        ;;


*)
        echo "This script is called by apcupsd when UPS events occur."
        ;;

esac

Replace the init.d apcupsd script with one with multiple UPS support

$ sudo mv /etc/init.d/apcupsd /etc/init.d/apcupsd.old
$ sudo nano /etc/init.d/apcupsd

### BEGIN INIT INFO
# Provides: apcupsd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Controls the apcupsd daemon for multiple UPS devices
# Description: apcupsd provides UPS power management for APC products.
### END INIT INFO


# Installation customizable fields.
#USELOCK=false
SUMMARYFIELDS='UPSNAME|MODEL|SERIALNO|STATUS|LINEV|LOADPCT|BCHARGE|TIMELEFT|OUTPUTV|ITEMP|ALARMDEL|BATTV|LINEFREQ|LASTXFER|NUMXFERS|TONBATT|CUMONBATT|BATTDATE|HUMIDITY|AMBTEMP'
SMSFIELDS='UPSNAME|STATUS|BCHARGE|TIMELEFT|LASTXFER|TONBATT'


NAME=apcupsd
DESC="This script controls the apcupsd daemon for multiple UPS devices."
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/sbin/apcupsd
APCTEST=/sbin/apctest
CONFIG=/etc/default/apcupsd
CONFDIR=/etc/apcupsd
RUNDIR=/var/run

. $CONFIG
. /lib/lsb/init-functions

test -x $DAEMON || exit 5
test -x $APCTEST || exit 5
test -x $APCACCESS || exit 5
test -e $CONFIG || exit 5
test -d $CONFDIR || exit 5


if [ "$ISCONFIGURED" != "yes" ]; then
        log_failure_msg "Check your configuration ISCONFIGURED in $CONFIG"
        exit 6  # program is not configured
fi

ls $CONFDIR/apcupsd*.conf > /dev/null 2>&1
statusCode=$?
if [ $statusCode -gt 0 ]; then
        log_failure_msg "No apcupsd configuration files found in $CONFDIR"
        exit 6
fi


case "$1" in
start|stop|restart|force-reload|status|report|summary|sms|test)
        # Each one of these commands are run for all apcupsd configuration files
        # unless a UPSNAME is specified, which will run the command only for
        # that UPS.

        # Note: If a daemon is started, and its conf file is deleted or
        # otherwise can't be found by this script, then this script wont be able
        # to control that daemon.

        if [ "$1" = "start" ]; then
                rm -f $CONFDIR/powerfail
                rm -f /etc/nologin
        fi

        count=0  # Used for white space control in report/summary/sms commands.
        counter=0
        if [ "$1" = "report" ] || [ "$1" = "summary" ] || [ "$1" = "sms" ]; then
                # Count the number of conf files found.
                for conf in $CONFDIR/apcupsd*.conf ; do
                        count=`expr $count + 1`
                done
        fi

        foundUPS=false  # Used only when a UPSNAME is specified.
        errorOccured=false
        statusCode=0
        errorCode=0

        # Loop through the $CONFDIR and find any conf file matching the pattern below.
        for conf in $CONFDIR/apcupsd*.conf ; do
                inst=`basename $conf`
                UPSNAME=$(cat $CONFDIR/$inst | grep "^[^#]" | grep "UPSNAME" | awk '{printf $2}')

                # Check that UPSNAME exists in configuration file.
                if [ -z "$UPSNAME" ]; then
                        log_failure_msg "UPSNAME is not configured in $inst (skipping)"
                        errorOccured=true

                # Continue if either no UPS was specified or the specified UPS was found.
                elif [ -z "$2" ] || ( [ -n "$2" ] && [ "$UPSNAME" = "$2" ] ); then
                        foundUPS=true

                        case "$1" in

                                start)
                                        # Show the daemon's status if it's running.
                                        OUTPUT=$($0 status "$UPSNAME")
                                        returnCode=$?
                                        if [ $returnCode -gt 0 ]; then
                                                log_daemon_msg "Starting UPS monitor (for $UPSNAME UPS)" "apcupsd"
                                        else
                                                echo "$OUTPUT"
                                        fi

                                        start-stop-daemon --start --quiet --oknodo --pidfile $RUNDIR/$inst.pid --exec $DAEMON -- -f $conf -P $RUNDIR/$inst.pid
                                        statusCode=$?

                                        # If the daemon wasn't running, show start result.
                                        # (We still try starting if it wasn't running, just
                                        # in case, but we do it quietly.)
                                        if [ $returnCode -ne 0 ]; then
                                                log_end_msg $statusCode
                                        fi
                                        ;;


                                stop)
                                        # Show the daemon's status if it's not running.
                                        OUTPUT=$($0 status "$UPSNAME")
                                        returnCode=$?
                                        if [ $returnCode -gt 0 ]; then
                                                echo "$OUTPUT"
                                        else
                                                log_daemon_msg "Stopping UPS monitor (for $UPSNAME UPS)" "apcupsd"
                                        fi

                                        start-stop-daemon --stop --quiet --oknodo --pidfile $RUNDIR/$inst.pid
                                        statusCode=$?

                                        # If the daemon was running, show stop result.
                                        # (We still try stopping if it was running, just in
                                        # case, but we do it quietly.)
                                        if [ $returnCode = 0 ]; then
                                                log_end_msg $statusCode
                                        fi
                                        ;;


                                restart|force-reload)
                                        $0 stop "$UPSNAME"
                                        #echo -n "Waiting for just a moment..."
                                        sleep 1
                                        #echo "done."
                                        $0 start "$UPSNAME"
                                        ;;


                                status)
                                        status_of_proc -p $RUNDIR/$inst.pid $DAEMON "UPS monitor (for $UPSNAME UPS)" && statusCode=0 || statusCode=$?
                                        ;;


                                report|summary|sms)
                                        # Report shows full details; summary shows just
                                        # pertinent info; sms shows a very short one liner.
                                        # This code parses the conf file and find the NISPORT
                                        # and NISIP, then display the status of UPS using
                                        # "apcaccess status NISPORT:NISIP" so each UPS needs to
                                        # be configured to have NIS running on a different port.
                                        counter=`expr $counter + 1`
                                        nisport=$(cat $CONFDIR/$inst | grep "^[^#]" | grep "NISPORT" | awk '{printf $2}')
                                        nisip=$(cat $CONFDIR/$inst | grep "^[^#]" | grep "NISIP" | awk '{printf $2}')

                                        if [ "$1" = "summary" ]; then
                                                # Shows only pertinent info.
                                                $APCACCESS status $nisip:$nisport | grep -E $SUMMARYFIELDS

                                        elif [ "$1" = "sms" ]; then
                                                # Produces a short, condensed one line string.
                                                # Note: The output doesn't contain a trailing newline.
                                                $APCACCESS status $nisip:$nisport | grep -E $SMSFIELDS | sed 's/\(^[A-Z]*\)\( *\)\(:\)/\1\3/;s/ *$//;s/ Percent/%/i;s/Minutes/min/i;s/seconds/sec/i;s/UPSNAME:/UPS/;/^STATUS: /s/$/\;/;s/STATUS: //' | tr '\n' ' ' | sed 's/ *$//'

                                        else
                                                # Shows all details.
                                                echo "APCUPSD  : $nisip:$nisport"
                                                echo "CONFFILE : $inst"
                                                $APCACCESS status $nisip:$nisport
                                        fi

                                        if [ -z "$2" ] && [ $count -gt 1 ] && [ $counter -lt $count ]; then
                                                # Only show newline white space if there's more than one
                                                # UPS and it's not the last UPS being shown.
                                                echo
                                        fi
                                        ;;


                                test)
                                        # Runs apctest for a specific UPS. Automatically stops
                                        # apcupsd if it's running and restarts it when finished.

                                        if [ -z "$2" ]; then
                                                log_failure_msg "A specific UPSNAME is required but not provided."
                                                exit 2  # invalid or excess argument(s)
                                        else
                                                # Check if apcupsd is running for this UPS.
                                                $0 status "$UPSNAME" > /dev/null 2>&1
                                                returnCode=$?
                                                if [ $returnCode = 0 ]; then
                                                        $0 stop "$2"
                                                        echo -n "Waiting for just a moment..."
                                                        sleep 3
                                                        echo "done."
                                                fi

                                                $APCTEST -f $conf

                                                # Restart apcupsd if it was running.
                                                if [ $returnCode = 0 ]; then
                                                        $0 start "$2"
                                                fi
                                        fi
                                        ;;

                        esac

                        # Record that a non fatal error occurred somewhere.
                        if [ $statusCode -gt 0 ]; then
                                errorOccured=true
                                errorCode=$statusCode
                                # errorCode may get overridden but only with another error
                                # code, so at the very least the last error code will be
                                # returned (see below).
                        fi

                fi

        done


        # Display an error if a UPS was specified but not found.
        if [ -n "$2" ] && [ "$foundUPS" = "false" ]; then
                log_failure_msg "UPSNAME '$2' not found in any apcupsd configuration file."
                exit 1  # generic or unspecified error

        # If an error code was returned somewhere, exit with it.
        elif [ $errorCode -gt 0 ]; then
                exit $errorCode

        # If any other error occurred, exit with a generic error code.
        elif [ "$errorOccured" = "true" ]; then
                exit 1
        fi

        exit 0  # Everything seems to have finished successfuly!
        ;;


reload|try-restart)
        log_failure_msg "Actions reload and try-restart are not implemented."
        exit 3  # unimplemented feature
        ;;


*)
        N=/etc/init.d/$NAME
        echo $DESC
        echo "Each $CONFDIR/apcupsd*.conf file found will run a separate apcupsd process."
        echo
        echo "Usage: $N {start|stop|restart|status} [UPSNAME]"
        echo "Usage: $N {report|summary|sms} [UPSNAME]"
        echo "Usage: $N test UPSNAME"
        echo
        echo "The start, stop, restart, and status commands control apcupsd processes."
        echo
        echo "The report, summary, and sms commands runs 'apcaccess status'. A report"
        echo "shows full apcaccess status details, summary shows just pertinent info,"
        echo "and sms shows a very short one liner."
        echo
        echo "The test command runs 'apctest' on a specific UPS."
        echo
        echo "The UPSNAME must be set for each UPS in each configuration file."

        exit 2  # invalid or excess argument(s)
        ;;
esac

Mark apcupsd as configured

Edit configuration /etc/default/apcupsd and set the ISCONFIGURED flag.

$ sudo nano /etc/default/apcupsd

ISCONFIGURED=yes

Try to start the daemon

$ sudo service apcupsd start

* Starting UPS monitor (for Network UPS) apcupsd    [ OK ]
* Starting UPS monitor (for Server UPS) apcupsd     [ OK ]

Check daemon status

$ service apcupsd status

* UPS monitor (for Network UPS) is running
* UPS monitor (for Server UPS) is running

Check UPS status

$ service apcupsd report

(Optional) Query a UPS for alarm and battery configuration

The UPSNAME matches the same UPSNAME configuration directive in each UPS device's config file.

$ sudo service apcupsd test UPSNAME

See also


FixMe: página muito desatualizada.


CategoryHardware