Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

APC Power Management

Discussion in 'Linux Other' started by Jarret B, Aug 21, 2018.

  1. Jarret B

    Jarret B Member

    Joined:
    May 22, 2017
    Messages:
    89
    Likes Received:
    38
    Computers have become very important for use in home and business settings. No matter where you may be using your system your work is very important to be sure you do not lose it.
    As information is entered into a computer it is not retained until it is saved. If your system should experience a quick disruption in power, or a complete loss, it is imperative that all data should be saved before the system is shutdown. A shutdown will hopefully always be performed properly and not a complete power loss which can lose or corrupt data.

    Power Issues

    Some things that can cause a power issue are the following:

    • Blackout
    • Brownout
    • Power spike
    A blackout is when there is a complete loss of power.
    A brownout occurs when the power dips below the normal voltage but does not go down all the way to zero volts. When a brownout occurs, the lights dim for a second and then come back on full again. The lowered voltage may cause some computers to restart or turn off. Any files opened may be corrupted or completely lost.
    A power spike is when the voltage rises above normal and then falls back to the normal state. Spikes can cause loss of data or even hardware. Spikes may be caused by lightning strikes. Extra voltage is sent through the power lines into a building and through the electrical wiring. If there is a blackout a spike may occur when the power is restored.
    Power Management Devices can prevent these issues and save data and hardware.

    Power Management Devices

    The Power Management Device we will be concentrating on is an Uninterruptible Power Supply (UPS). A UPS device contains a battery which is charged from a wall outlet. The UPS has specific power outlets which provide battery power to a computer to prevent a blackout/brownout. There is usually a built-in surge protector to prevent hardware damage from power spikes.
    While the UPS is charging the battery from the wall outlet it is also discharging the battery to power the connected devices. If the power should drop (brownout/blackout) then the computer will not be aware of the power loss. If the UPS is a “smart” UPS it will alert the system that a power outage has occurred. The communications between the PC and the UPS is usually through a USB cable, but can be a serial cable.
    Power Management Software on the computer will monitor the communications connection for alerts that the power has failed or been restored. The software is configured to shutdown the computer when a power outage occurs and before the battery runs out of power. If the power should resume then the system shutdown should not occur.

    NOTE: It is usually best for a UPS to include a connection cable to alert the system to shutdown properly. Some UPS devices are not “smart” and will therefore not alert the system to shutdown. When the battery charge is depleted the system will simply lose power and go off. A “hard shutdown” can cause data loss and cause hardware damage.

    A “hard shutdown” is basically when a PC is powered off by a means other than using the Operating System (OS) to power off the PC. A “hard shutdown” occurs when your push the power button and turn off the system and it also happens when the power is lost and the computer instantly goes off.

    One brand of UPS is the American Power Conversion (APC) which has a specific power management daemon.

    APC UPS Daemon (APCUPSD)

    If you have already installed the ‘apcupsd’ service from an apt-get command then you need to remove it. One of the monitoring tools, called ‘gapcmon’, must be compiled with the service for the two to be able to work together.
    To start you will need to to download the source code. Go to the website ‘apcupsd.com’. Toward the bottom left of the page is a link to the ‘Source’ code. When you click on the link you will be redirected to Sourceforge to complete the download. The download should be at least version 3.14.14. Once the file is downloaded you need to extract the file using an archive program. Once extracted it should create a folder named similar to ‘apcupsd-3.14.14’ (the version number may be different). Open a Terminal into this newly created folder. Before continuing with compiling the source code you need to install the following if it isn’t already:

    • gcc
    • build-essential
    • pkg-config
    • libgtk2.0-dev
    • libgconf2-dev
    Perform the following command:

    sudo ./configure --prefix=/usr --sbindir=/sbin --enable-usb --enable-gapcmon

    The command is assuming the APC UPS device will be connected to the PC by a USB cable. If you are using a different connection type, then type ‘./configure --help’ to see a listing of the various options you can specify.

    NOTE: Be sure to use the option ‘--enable-gapcmon’ so the monitoring too will be compiled as well.

    Once the command is completed then execute the command:

    sudo make

    After the command has completed you can perform the last command:

    sudo make install

    The programs should now be compiled. If any errors should occur go back and make sure all dependencies are installed.
    Use your favorite text editor to edit the file ‘/etc/default/apcupsd’ with elevated privileges. Find the line which is ‘ISCONFIGURED=no’ and change it to ‘ISCONFIGURED=yes’. Save and exit the file. Now you should connect the UPS to the system via the cable (most likely USB).
    With elevated privileges you need to edit another file: ‘/etc/apcupsd/apcupsd.conf’. Within the file you need to find the line ‘UPSNAME’ and add a name containing no more than 8 characters. For my system I used the name ‘CS350’ for my APC-SmartUPS CS350. The ‘UPSCABLE’ should be set to USB if you do have a USB connection. For DEVICE leave it blank if you are using a USB cable, otherwise look through the comments above the line to see other settings. Set UPSTYPE to USB if you have a USB cable.
    Other settings can be changed as you see fit. The ONBATTERYDELAY is defaulted to 6 seconds. The value specifies how many seconds after the PC is warned that the power is off before it starts to do something about the situation. The BATTERYLEVEL has a default value of 5. The setting is the percentage of the battery remaining before the system will be shutdown. The default value for MINUTES is 3. The value denotes how many minutes of battery time can remain before a shutdown is started. The TIMEOUT value is set to disabled or a value of 0. The value is how many minutes the system is on battery before a shutdown is started. Most of the settings should be fine for a standard system. Save the file and close the text editor after you make your changes. Any time changes are made to the configuration they will not take effect until the APCUPSD Service has been restarted with the command:

    sudo systemctl restart apcupsd.service

    To verify everything is working and configured you can open a Terminal and type the command ‘gapcmon’. The Graphics Monitor for APCUPSD should start and look similar to Figure 1.

    Figure 01.jpg
    FIGURE 1

    The line in purple is what you are setting up to monitor. Under Graph Refresh click on the number and change it to a 1 to cause the graph to update every 8 seconds rather than 240 seconds. You should check the box for ‘Use Tray Icon’ then also click on the box for ‘Enabled’. Once the ‘Enable’ box is checked a graph will appear as shown in Figure 2.

    Figure 02.jpg
    FIGURE 2

    You can see that the system is showing monitored data for the on-line UPS called CS350 on the system called ‘jarret-Aspire-One’.
    The second tab is for ‘Detailed Information’ and the information given is shown in Figure 3.

    Figure 03.jpg
    FIGURE 3

    The next tab, shown in Figure 4, gives details on ‘Power Events’. The data here comes from the file ‘/var/log/apcupsd.events’. The size of the file is set to a maximum size of 10 kb. The maximum events file size can be set in the ‘apcupsd.conf’ file on the line ‘EVENTSFILEMAX’. Remember if you change it to restart the service.

    Figure 04.jpg
    FIGURE 4

    The last tab shows the ‘Full UPS Status’ which can also be found from the command line program ‘apcaccess’.

    Figure 05.jpg
    FIGURE 5


    (Log in to hide this advertisement)


    NOTE: The ‘apcaccess’ is created during the compile along with ‘gapcmon’ and ‘apctest’.

    Testing the APC UPS Daemon

    The file ‘apctest’ was created to allow for some simple testing. To run the test program you must first stop the Daemon with the command:

    sudo systemctl stop apcupsd.service

    Once the service is stopped you can enter the command ‘sudo apctest’ as shown in Figure 6.

    Figure 06.jpg
    FIGURE 6

    If you enter a ‘1’ to ‘Test Kill UPS Power’ the UPS should switch to ‘On Battery’. If you restart the ‘apcupsd.service’ after exiting the test program you should see the Daemon switch the UPS back to ‘On Line’. By switching the UPS On-Line you can tell that the UPS and PC are communicating perfectly.
    For a full test you can unplug the UPS and make sure the system is powered down properly by the ‘apcupsd.service’. Any settings you determine need to be changed you can change in the configuration file and restart the service for the changes to take effect.
     

Share This Page