Uninterruptable Power Supply:APC

From SME Server
Revision as of 11:52, 2 June 2010 by Timn (talk | contribs) (Updated for newer version and for SME)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Installation of Latest Version

The latest version of apcupsd is 3.14.8-1 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

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
BATTEYLEVEL
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

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 .= "ScriptAlias  /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

Now go to http://yourdomain.tld/apcupsd to see the stats 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 momitor 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.

Original Instructions

The following instructions are based on the original forum post http://forums.contribs.org/index.php?topic=45923.0

Setup the DAG repository

The following command will configure the Dag repository on SME Server. EDIT NOT COMPLETE!


To create an entry in the database for the epel repository we open put the following commands in a terminal window or in a shell window:

/sbin/e-smith/db yum_repositories set epel repository \

Name 'SME Server - epel' \
BaseURL 'http://<http://download.fedoraproject.org/pub/epel/7/$basearch' \
EnableGroups yes \
GPGCheck yes \
Visible no \
status disabled

To enable the changes:

    signal-event yum-modify

Just to be sure, give yum a fresh start:

    yum clean all

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