Difference between revisions of "Uninterruptable Power Supply:APC"

From SME Server
m (Configure Multimon etc Scripts: Minor changes to remove Scriptalias warning in httpd error_log)
m (Installation of Latest Version: Added note about use of Nut by standard SME)
Line 5: Line 5:
  
 
These installation instructions make some additional modifications for SME
 
These installation instructions make some additional modifications for SME
 
+
{{Note box|SME uses Nut as standard for UPS monitoring and control and works with a more than just APC UPS models. See [[Uninterruptable_Power_Supply]] for details }}
 
===Download and install===
 
===Download and install===
 
Get the rpms from sourceforge
 
Get the rpms from sourceforge

Revision as of 12:23, 4 June 2010

Installation of Latest Version

Apcupsd can be used for power management and controlling most of APC's UPS models on Unix and Windows machines. Apcupsd works with most of APC's Smart-UPS models as well as most simple signalling models such a Back-UPS, and BackUPS-Office. During a power failure, apcupsd will inform the users about the power failure and that a shutdown may occur. If power is not restored, a system shutdown will follow when the battery is exhausted, a timeout (seconds) expires, or runtime expires based on internal APC calculations determined by power consumption rates. Apcupsd is licensed under the GPL version 2.

The latest version of apcupsd is 3.14.8-1 (January 2010) and is available from sourceforge in two rpms - one for the UPS daemon and one for the web based monitoring scripts. Neither of these install exactly in line with the SME way, and neither does the older version available on DAG.

These installation instructions make some additional modifications for SME

Important.png Note:
SME uses Nut as standard for UPS monitoring and control and works with a more than just APC UPS models. See Uninterruptable_Power_Supply for details


Download and install

Get the rpms from sourceforge

wget https://sourceforge.net/projects/apcupsd/files/rpms%20-%20Stable/3.14.8/apcupsd-3.14.8-1.el4.i386.rpm/download
wget https://sourceforge.net/projects/apcupsd/files/rpms%20-%20Stable/3.14.8/apcupsd-multimon-3.14.8-1.el4.i386.rpm/download

Install with yum

yum localinstall apcupsd-3.14.8-1.el4.i386.rpm apcupsd-multimon-3.14.8-1.el4.i386.rpm

Configure apcupsd

Link the startup file and enable the service

ln -s /etc/init.d/e-smith-service /etc/rc.d/rc7.d/S38apcupsd
config set apcupsd service status enabled

Copy the original conf file

cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.orig

Edit /etc/apcupsd/apcupsd.conf file and make relevant changes for your UPS and requirements. The file is reasonably well documented and as a minimum you will probably want to set

UPSNAME 
UPSCABLE
UPSTYPE
DEVICE
BATTERYLEVEL
MINUTES
TIMEOUT

Now make sure Nut isn't running and start the service

config setprop nut status disabled
/etc/init.d/nut stop
/etc/rc.d/rc7.d/S38apcupsd start

Configure Multimon etc Scripts

The apcupsd-multimon rpm contains four cgi scripts that can be run via the webserver to monitor the UPS(s). The rpm does not install them correctly for SME however so the following modifications are needed.

mkdir -p /opt/apcupsd
chown root:www /opt/apcupsd
mv /var/www/cgi-bin/multimon.cgi /opt/apcupsd
mv /var/www/cgi-bin/upsstats.cgi /opt/apcupsd
mv /var/www/cgi-bin/upsfstats.cgi /opt/apcupsd
mv /var/www/cgi-bin/upsimage.cgi /opt/apcupsd
chown root:www /opt/apcupsd/*
chmod 750 /opt/apcupsd/*
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
cd /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf

Now edit and create a new file 92apcupsdmon with the following content

{
    $OUT = "";
    my $allow = 'all';
    my $pass = '0';
    my $satisfy = 'all';
    my $name = $apcupsd{'Name'} || 'apcupsd UPS Monitor';

    for ('exit-if-none')
    {
      if ($apcupsd{'PublicAccess'})
      {
          if ($apcupsd{'PublicAccess'} eq 'none')
          {
           next;
          }
          elsif ($apcupsd{'PublicAccess'} eq 'local')
          {
            $allow   = $localAccess;
            $pass    = 0;
            $satisfy = 'all';
          }
          elsif ($apcupsd{'PublicAccess'} eq 'local-pw')
          {
            $allow   = $localAccess;
            $pass    = 1;
            $satisfy = 'all';
          }
          elsif ($apcupsd{'PublicAccess'} eq 'global')
          {
            $allow   = 'all';
            $pass    = 0;
            $satisfy = 'all';
          }
          elsif ($apcupsd{'PublicAccess'} eq 'global-pw')
          {
            $allow   = 'all';
            $pass    = 1;
            $satisfy = 'all';
          }
          elsif ($apcupsd{'PublicAccess'} eq 'global-pw-remote')
          {
            $allow   = $localAccess;
            $pass    = 1;
            $satisfy = 'any';
          }
      } 

      $OUT .= "#------------------------------------------------------------\n";
      $OUT .= "# apcupsd - $name\n";
      $OUT .= "#------------------------------------------------------------\n";

      {
        if ((exists $apcupsd{'URL'}) && ($apcupsd{'URL'} ne ))
        { $OUT .= "Alias  /$apcupsd{'URL'}  /opt/apcupsd\n";
          $OUT .= "ScriptAlias  /$apcupsd{'URL'}  /opt/apcupsd\n"; }
      }

      $OUT .= "Alias  /apcupsd  /opt/apcupsd\n";

      $OUT .= "\n";
      $OUT .= "<Directory /opt/apcupsd>\n";
      $OUT .= "    DirectoryIndex upsstats.cgi\n";
      $OUT .= "    Options +ExecCGI\n";
      $OUT .= "    order deny,allow\n";
      $OUT .= "    deny from all\n";
      $OUT .= "    allow from $allow\n";
      if ($pass)
      {
          $OUT .= "    AuthName $name\n";
          $OUT .= "    AuthType Basic\n";
          $OUT .= "    AuthExternal pwauth\n";
          $OUT .= "    require valid-user\n";
          $OUT .= "    Satisfy $satisfy\n";
      }
      $OUT .= "</Directory>\n";
    }
}

Configure and expand the template

config setprop apcupsd PublicAccess local
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
Important.png Note:
The above sets access to the scripts to local ip addresses only. See the Web_Application_RPM#New_DB_settings for further info and settings


Restart the web server

sv t httpd-e-smith

Usage of Multimon etc Scripts

Now go to http://yourdomain.tld/apcupsd to see the statistics for the UPS at localhost, or https://yourdomain.tld/apcupsd/multimon.cgi for an overview of the UPS(s).

By editing /etc/apcupsd/hosts.conf and adding additional network UPS details, multimon.cgi can be used to monitor more than one UPS. By default only the localhost is monitored.

References

See the apcupsd main site.

See the apcupsd manual for further configuration and testing options.

See Uninterruptable_Power_Supply for standard SME use of Nut for UPS monitoring

See original forum post


Original Instructions (DAG)

The following instructions are based on the original forum post http://forums.contribs.org/index.php?topic=45923.0 and the use of an rpm from the DAG repository.

Setup the DAG repository

The following command will configure the Dag repository on SME Server. Dag After adding it to the database we have to update the changes to the configuration file:

signal-event yum-modify

Installation

Install apcupsd

yum install --enablerepo=dag --enablerepo=base apcupsd

Copy original conf file

cp apcupsd.conf apcupsd.conf.orig

Copy CGI files

cp /var/www/apcupsd/* /home/e-smith/files/ibays/Primary/cgi-bin/

Link the startup script

ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99apcupsd

Set the Service in SME

config set apcupsd service status enabled

Configuration

Edit /etc/apcupsd/apcupsd.conf. The conf file has good detail on setup options.

Suggest setting the TIMEOUT to 600 seconds; You shouldn't let UPS batteries run down to 5% (default) as this massively shortens their life. Set TIMEOUT to 10 for testing.

Reboot or

/etc/init.d/apcupsd start 

to start the service.

Usage

http://yourdomain.tld/cgi-bin/multimon.cgi gives a nice look at the UPS status, including a log of past events