Difference between revisions of "Uninterruptable Power Supply"

From SME Server
Jump to navigationJump to search
(→‎Configuration Options: Change newhidusb to usbhid-ups)
(Added modifying shutdown time delay & modified additional info)
Line 113: Line 113:
  
 
- Templating example: http://forums.contribs.org/index.php?topic=40668.0
 
- Templating example: http://forums.contribs.org/index.php?topic=40668.0
 +
 +
==Modifying shutdown time delay==
 +
 +
The following changes to NUT configuration will shut down the server a specified time after receiving the "on battery" signal (the example given is for 2 minutes).
 +
 +
To create a timed shutdown before the BATTLOW signal is received, it is necessary to configure upssched and have a script handle the UPS events (upsmon cannot do this).
 +
config setprop nut status enabled
 +
config setprop nut Model megatec_usb
 +
config setprop nut Type auto
 +
 +
Create and edit a custom template
 +
mkdir -p /etc/e-smith/templates-custom/etc/ups/upsmon.conf
 +
pico -w /etc/e-smith/templates-custom/etc/ups/upsmon.conf/NOTIFYCMD
 +
 +
Add the following:
 +
NOTIFYCMD /usr/sbin/upssched
 +
 +
Save & exit
 +
Ctrl o
 +
Ctrl x
 +
 +
Create and edit a custom template
 +
mkdir -p /etc/e-smith/templates-custom/etc/ups/upssched.conf
 +
pico -w /etc/e-smith/templates-custom/etc/ups/upssched.conf/01CONFIG
 +
 +
Add the following:
 +
CMDSCRIPT /sbin/e-smith/nutUPS.cmd
 +
PIPEFN /tmp/upspipe
 +
LOCKFN /tmp/upslock
 +
AT COMMBAD * EXECUTE commbad
 +
AT COMMOK * EXECUTE commok
 +
AT NOCOMM * EXECUTE nocomm
 +
AT ONBATT * EXECUTE powerout
 +
AT ONBATT * START-TIMER shutdownnow 120   
 +
AT LOWBATT * EXECUTE shutdowncritical
 +
AT ONLINE * CANCEL-TIMER shutdownnow
 +
AT ONLINE * EXECUTE powerup
 +
 +
In the above set the line
 +
AT ONBATT * START-TIMER shutdownnow 120
 +
to how many seconds after ONBATT signal you want to shut down
 +
 +
Save & exit
 +
Ctrl o
 +
Ctrl x
 +
 +
Create the script
 +
pico -w /sbin/e-smith/nutUPS.cmd
 +
 +
Add the following:
 +
 +
#! /bin/sh
 +
        case $1 in
 +
                commbad)
 +
                        /bin/echo "UPS communications failure on `date`." | /bin/mail -s"UPS communications LOST" admin
 +
                        /usr/bin/wall "UPS communications failure."
 +
                        ;;
 +
                commok)
 +
                        /bin/echo "UPS communications restored on `date`." | /bin/mail -s"UPS communications restored" admin
 +
                        /usr/bin/wall "UPS communications restored."
 +
                        ;;
 +
                nocomm)
 +
                        /bin/echo "UPS communications cannot be established on `date`." | /bin/mail -s"UPS uncontactable" admin
 +
                        /usr/bin/wall "UPS communications cannot be established."
 +
                        ;;
 +
                powerout)
 +
                        /bin/echo "Power failure on `date`." | /bin/mail -s"UPS on battery" admin
 +
                        /usr/bin/wall "UPS on battery. Shutdown in 60 seconds...."
 +
                        ;;
 +
                shutdownnow)
 +
                        /bin/echo "UPS has been on battery for 60 seconds. Starting orderly shutdown on `date`." | /bin/mail -s"UPS on battery for 60 seconds" admin
 +
                        /usr/bin/wall "UPS has been on battery for 60 seconds. Shutting down NOW!!!!"
 +
                        /usr/bin/sudo /sbin/e-smith/signal-event halt
 +
                        ;;
 +
                shutdowncritical)
 +
                        /bin/echo "UPS battery level CRITICAL. Starting EMERGENCY shutdown on `date`." | /bin/mail -s"UPS battery CRITICAL" admin
 +
                        /usr/bin/wall "UPS battery level CRITICAL. Shutting down NOW!!!!"
 +
                        /usr/bin/sudo /sbin/e-smith/signal-event halt
 +
                        ;;
 +
                powerup)
 +
                        /bin/echo "Power restored on `date`." | /bin/mail -s"UPS on line" admin
 +
                        /usr/bin/wall "UPS on line. Shutdown aborted."
 +
                        ;;
 +
                *)
 +
                        /bin/echo "Unrecognized command: $1"
 +
                        ;;
 +
        esac
 +
 +
 +
Create a custom template
 +
mkdir -p /etc/e-smith/templates-custom/etc/sudoers/30nut
 +
 +
Add the following
 +
nut  ALL=NOPASSWD: ALL
 +
 +
To complete the process
 +
signal-event post-upgrade
 +
signal-event reboot
 +
  
 
==Aditional Information==
 
==Aditional Information==
Line 130: Line 229:
 
  man upsd
 
  man upsd
 
  man nutupsdrv
 
  man nutupsdrv
 +
 +
The NUT website is here
 +
 +
http://www.networkupstools.org/
 +
 +
From that website you can glean which configuration setting does what function
 +
 +
Then modify the NUT config file, by creating a custom template, expanding template and restarting service
 +
 
----
 
----
 
<noinclude>[[Category:Howto]]</noinclude>
 
<noinclude>[[Category:Howto]]</noinclude>

Revision as of 14:15, 31 July 2009


Introduction

The primary goal of the Network UPS Tools (NUT) project is to provide reliable monitoring of UPS hardware and ensure safe shutdowns of the systems which are connected.

The default configuration of NUT, will keep your connected systems operational until a critical battery state is reached (ie battery is nearing exhaustion) and then power down your server/equipment in a controlled fashion. See http://www.networkupstools.org/

Default Configuration (USB)

Most USB connected UPS's will work with the default settings. If using a USB connection just enable nut as follows:

config setprop nut status enabled
signal-event post-upgrade
signal-event reboot

If your USB UPS does not work properly OR you have a serial device then follow the Configuration Options below.

Configuration Options

Not all UPS's are supported by USB or the usbhid-ups driver. However NUT supports many UPS's and can be configured under SME Server easily.

Serial Connection

  1. Find the configuration details for your model of UPS. Refer to: http://www.networkupstools.org/compat/stable.html and make note of the driver name and upstype number (if any) in the third column.
    Warning.png Warning:
    Always use the serial cable supplied with the UPS. Standard serial cables won't work with a serial UPS and have been known to cause damage to the UPS. Pay particular attention to any references to cable in in the UPS Model column.

  2. From the consol issue the following commands: config setprop nut Model <model> config setprop nut Device <device> config setprop nut Type <type> config setprop nut status enabled Where:
    <model> and <type> are the driver name and type number found above.
    <device> is the serial port that the UPS is connected to eg. /dev/ttyS0. It also possible to use a more readable symlink. See HowTo on udev - symlinks for details. Note: The case of Model, Device and Type.
  3. Check: config show nut
  4. Apply changes and restart server: signal-event post-upgrade signal-event reboot Alternatively, without NUT running or requiring a server reboot: expand-template /etc/sysconfig/ups expand-template /etc/ups/* /etc/rc7.d/S38nut start
  5. Confirm server is communicating with UPS: upsc UPS@localhost Whenever a UPS event occurs Emails are sent to the admin account.

Configuring as a slave

Set configuration values:

config setprop nut SlaveUPS UPS@192.168.33.11
config setprop nut Master no

Where 192.168.33.11 is your UPS master, that is the computer that is in direct communication with the UPS. The hostname of that computer may also work.

Apply changes and restart server:

signal-event post-upgrade
signal-event reboot 

Confirm server is communicating with master:

upsc UPS@192.168.33.11

Conecting multiple UPS's

To be added http://bugs.contribs.org/show_bug.cgi?id=629

Modifying UPS Parameters

In some cases you may wish to modify parameters on the actual UPS such as the Low Charge/LOWBATTERY setting. This requires the use of the upsrw command and temporary modifications to the upsd.users configuration file. In general, the UPS data should be left protected and changes thought out. If you wish to make the administrative privileges more permanent, then you can make custom templates as identified in the section "Additional Information".

In the examples below, it is assumed your UPS name is ups and that the UPS is local. you can verify the UPS name via:

upsc -l

To determine the modifiable parameters for your UPS execute the command:

upsrw ups

next we need to create a temporary user with privileges to modify these parameters. First make a safe copy of /etc/ups/upsd.users

cp /etc/ups/upsd.users /etc/ups/upsd.users.backup

Modify /etc/ups/upsd.users and add the user "admin" or anything else you prefer. The entry should look like the other entries and be something like:

      [admin]
              password = admin
              allowfrom = localhost
              actions = set

Now reload the config files:

upsd -c reload

You can now modify the parameters you wish using a command similar to:

upsrw -s battery.charge.low=20 -u admin -p admin ups

Where the value after -s should be one of the parameters identified by the upsrw ups command and where "-u admin -p admin" is the username and password set above and ups is the name of your ups. You can of course verify your changes using upsrw ups or upsc ups.

After you are done, clean up:

mv /etc/ups/upsd.users.backup /etc/ups/upsd.users
upsd -c reload

And don't forget to verify that your changes meet your intended behaviour!

More information on upsrw can be found at:

- Manual page: man upsrw

- Upsrw examples: http://opensource.mgeups.com/howto.htm

- Templating example: http://forums.contribs.org/index.php?topic=40668.0

Modifying shutdown time delay

The following changes to NUT configuration will shut down the server a specified time after receiving the "on battery" signal (the example given is for 2 minutes).

To create a timed shutdown before the BATTLOW signal is received, it is necessary to configure upssched and have a script handle the UPS events (upsmon cannot do this).

config setprop nut status enabled
config setprop nut Model megatec_usb
config setprop nut Type auto

Create and edit a custom template

mkdir -p /etc/e-smith/templates-custom/etc/ups/upsmon.conf
pico -w /etc/e-smith/templates-custom/etc/ups/upsmon.conf/NOTIFYCMD

Add the following:

NOTIFYCMD /usr/sbin/upssched

Save & exit

Ctrl o
Ctrl x

Create and edit a custom template

mkdir -p /etc/e-smith/templates-custom/etc/ups/upssched.conf
pico -w /etc/e-smith/templates-custom/etc/ups/upssched.conf/01CONFIG

Add the following:

CMDSCRIPT /sbin/e-smith/nutUPS.cmd
PIPEFN /tmp/upspipe
LOCKFN /tmp/upslock
AT COMMBAD * EXECUTE commbad
AT COMMOK * EXECUTE commok
AT NOCOMM * EXECUTE nocomm
AT ONBATT * EXECUTE powerout
AT ONBATT * START-TIMER shutdownnow 120     
AT LOWBATT * EXECUTE shutdowncritical
AT ONLINE * CANCEL-TIMER shutdownnow
AT ONLINE * EXECUTE powerup

In the above set the line AT ONBATT * START-TIMER shutdownnow 120 to how many seconds after ONBATT signal you want to shut down

Save & exit

Ctrl o
Ctrl x

Create the script

pico -w /sbin/e-smith/nutUPS.cmd

Add the following:

#! /bin/sh
       case $1 in
               commbad)
                       /bin/echo "UPS communications failure on `date`." | /bin/mail -s"UPS communications LOST" admin
                       /usr/bin/wall "UPS communications failure."
                       ;;
               commok)
                       /bin/echo "UPS communications restored on `date`." | /bin/mail -s"UPS communications restored" admin
                       /usr/bin/wall "UPS communications restored."
                       ;;
               nocomm)
                       /bin/echo "UPS communications cannot be established on `date`." | /bin/mail -s"UPS uncontactable" admin
                       /usr/bin/wall "UPS communications cannot be established."
                       ;;
               powerout)
                       /bin/echo "Power failure on `date`." | /bin/mail -s"UPS on battery" admin
                       /usr/bin/wall "UPS on battery. Shutdown in 60 seconds...."
                       ;;
               shutdownnow)
                       /bin/echo "UPS has been on battery for 60 seconds. Starting orderly shutdown on `date`." | /bin/mail -s"UPS on battery for 60 seconds" admin
                       /usr/bin/wall "UPS has been on battery for 60 seconds. Shutting down NOW!!!!"
                       /usr/bin/sudo /sbin/e-smith/signal-event halt
                       ;;
               shutdowncritical)
                       /bin/echo "UPS battery level CRITICAL. Starting EMERGENCY shutdown on `date`." | /bin/mail -s"UPS battery CRITICAL" admin
                       /usr/bin/wall "UPS battery level CRITICAL. Shutting down NOW!!!!"
                       /usr/bin/sudo /sbin/e-smith/signal-event halt
                       ;;
               powerup)
                       /bin/echo "Power restored on `date`." | /bin/mail -s"UPS on line" admin
                       /usr/bin/wall "UPS on line. Shutdown aborted."
                       ;;
               *)
                       /bin/echo "Unrecognized command: $1"
                       ;;
       esac


Create a custom template

mkdir -p /etc/e-smith/templates-custom/etc/sudoers/30nut

Add the following

nut   ALL=NOPASSWD: ALL

To complete the process

signal-event post-upgrade
signal-event reboot


Aditional Information

There are template fragments in /etc/e-smith/templates/etc/ups that control the config files located in /etc/ups. The default settings should be OK for most situations.

An example of doing this can be found in the forum: http://forums.contribs.org/index.php?topic=40668.0

For information on configuration parameters:

man ups.conf
man upsd.conf
man upsd.users
man upsmon.conf
man upssched.conf

For general information:

man upsd
man nutupsdrv

The NUT website is here

http://www.networkupstools.org/

From that website you can glean which configuration setting does what function

Then modify the NUT config file, by creating a custom template, expanding template and restarting service