[comp.unix.questions] UPS directed system shutdown info needed

john@wa3wbu.UUCP (John Gayman) (01/19/89)

    Does anyone have experience with interfacing a small UPS system (600-
1000VA) to a 386-based Unix box to allow for orderly system shutdown
when the batteries run down ?

    I see most small UPS vendors are offering a signal port option on most
of their units. I also see vendors offering software drivers for the
popular Mess-DOS LAN systems.

    My question is, how are these interfaces being handled by small Unix
boxes ?  I'm using a 386 machine running Microport V/386. What would
it take to have the system shutdown (logically) from a signal on an UPS ?
I assume most UPS's interfaces simply bring a signal low (or high) and
its up to the system to act upon it ?  Or does the UPS carry on a 
dialog with the CPU ? (ie: Pssst, I have 3 minutes left, watta ya wanna
do, shutdown or go for broke ? Well punk, do ya feel lucky ?)

    [Sorry I got carried away]

    Seriously, I'd really like to hear from anyone doing this. Thanks.


						John


-- 
John Gayman, WA3WBU              |           UUCP: uunet!wa3wbu!john
1869 Valley Rd.                  |           ARPA: john@wa3wbu.uu.net 
Marysville, PA 17053             |           Packet: WA3WBU @ AK3P 

ag@elgar.UUCP (Keith Gabryelski) (01/20/89)

In article <210@wa3wbu.UUCP> john@wa3wbu.UUCP (John Gayman) writes:
>Does anyone have experience with interfacing a small UPS system (600-
>1000VA) to a 386-based Unix box to allow for orderly system shutdown
>when the batteries run down ?

I do, that is ... I wrote such an interface to SCO Xenix, SunOS, SysV,
and BSD machines for Elgar Corporation.

>I see most small UPS vendors are offering a signal port option on
>most of their units. I also see vendors offering software drivers for
>the popular Mess-DOS LAN systems.

MS-DOS, OS2, Novell, 3Com, Unix, Xenix ... It is a big market.

>My question is, how are these interfaces being handled by small Unix
>boxes?

Our interface is through a cable to a serial port.  This seemed the
most logical, since they are readily available [read no development
time needed to design a card for each bus out there] and can be added
for relative cheapness.

>I'm using a 386 machine running Microport V/386.  What would it take
>to have the system shutdown (logically) from a signal on an UPS?  I
>assume most UPS's interfaces simply bring a signal low (or high) and
>its up to the system to act upon it ?  Or does the UPS carry on a
>dialog with the CPU ? (ie: Pssst, I have 3 minutes left, watta ya
>wanna do, shutdown or go for broke ? Well punk, do ya feel lucky ?)

(two senarios)

First for the Z-1000, Zenith Data System's new multi-386 system,
running a hacked up SCO XENIX.

    This uses an internal (on-line) IPS (Intelligent Power System).
    The IPS signals init to run a shutdown program which sends a
    message to the users; something like "System on Battery Power,
    Save and Logout".  Then, the process sleeps for a couple of
    minutes and calls uadmin() with a new flag that flushes cache and
    inverts power in the IPS (saving battery time for subsequent power
    failures).

    When commercial power is restored, the system boots and users are
    allowed to login.

[This scenario does not require a serial port, because the IPS was
specifically designed for Z-1000 and is actually internal to the
system.]

The second scenario is for any system that does not use an internal
IPS.

    A daemon monitors a serial port for a message from the IPS tell it
    that the system is on battery power.  Actually, the daemon blocks
    on an open() to the serial port.  When the system goes on battery
    power, the IPS asserts a HIGH on the DCD pin which allows the
    open() to return.  This tells the daemon the the system is on
    battery power.

    The daemon sends out warning messages (every minute or so) to the
    users until a countdown time has elasped.  If commercial power is
    restored before the countdown, the daemons sends out a power
    restored message to the users and resets itself.

    At the end of the countdown time (if commercial power hasn't been
    restored) the daemon executes a shutdown script which logs out the
    users, unmounts the files systems, syncs the unmountable file
    systems and inverts power in the IPS.  This shuts power off to the
    system (to save battery time) until commercial power is restored.

    When commercial power is restored, the system boots and users are
    allowed to login.

Pax, Keith
-- 
ag@elgar.CTS.COM         Keith Gabryelski          ...!{ucsd, crash}!elgar!ag

clewis@ecicrl.UUCP (01/21/89)

In article <210@wa3wbu.UUCP> john@wa3wbu.UUCP (John Gayman) writes:
>
>    My question is, how are these interfaces being handled by small Unix
>boxes ?  I'm using a 386 machine running Microport V/386. What would
>it take to have the system shutdown (logically) from a signal on an UPS ?
>I assume most UPS's interfaces simply bring a signal low (or high) and
>its up to the system to act upon it ?  Or does the UPS carry on a 
>dialog with the CPU ? (ie: Pssst, I have 3 minutes left, watta ya wanna
>do, shutdown or go for broke ? Well punk, do ya feel lucky ?)

The ones I've seen have only two lines:
	- one to the computer saying "AC Gone!"
	- one to the UPS saying "shutdown completely".

Twould be also nice to have a "n minute warning"...


Altos machines have some sort of hardware/software package to use some
UPS's.  So does Novell for messydos.

What you can do if you have a serial port to burn, is to connect the
"AC Gone!" wire to receive data or CD or something, and have a bit of
software waiting for a transition on that line.  When it sees it,
it does:
	echo bye bye | /etc/wall
	sleep 20
	/etc/telinit 0
(or some such).

You'll have to ensure that the voltages are okay (< +-12) and
that the transition can be reliably detected.  Might even be able
to do it without losing the port...
-- 
Chris Lewis, Markham, Ontario, Canada
{uunet!attcan,utgpu,yunexus,utzoo}!lsuc!ecicrl!clewis
Ferret Mailing list: ...!lsuc!gate!eci386!ferret-request
(or lsuc!gate!eci386!clewis or lsuc!clewis)

levy@ttrdc.UUCP (Daniel R. Levy) (01/21/89)

In article <32@elgar.UUCP>, ag@elgar.UUCP (Keith Gabryelski) writes:
< The second scenario is for any system that does not use an internal
< IPS.
< 
<     A daemon monitors a serial port for a message from the IPS tell it
<     that the system is on battery power.  Actually, the daemon blocks
<     on an open() to the serial port.  When the system goes on battery
<     power, the IPS asserts a HIGH on the DCD pin which allows the
<     open() to return.  This tells the daemon the the system is on
<     battery power.

I could see a possible problem with this if the port jams;  the UPS could
go on battery power and the system would fail to notice, nor would it notice
the fact that the port had jammed.  Mightn't it be better to have some kind
of continuous "self test" going on?
-- 
Daniel R. Levy             UNIX(R) mail:  att!ttbcad!levy
AT&T Bell Laboratories
5555 West Touhy Avenue     Any opinions expressed in the message above are
Skokie, Illinois  60077    mine, and not necessarily AT&T's.

sl@van-bc.UUCP (pri=-10 Stuart Lynne) (01/22/89)

In article <3149@ttrdc.UUCP> levy@ttrdc.UUCP (Daniel R. Levy) writes:
>In article <32@elgar.UUCP>, ag@elgar.UUCP (Keith Gabryelski) writes:
>< The second scenario is for any system that does not use an internal
><     A daemon monitors a serial port for a message from the IPS tell it
><     that the system is on battery power.  Actually, the daemon blocks

>I could see a possible problem with this if the port jams;  the UPS could
>go on battery power and the system would fail to notice, nor would it notice
>the fact that the port had jammed.  Mightn't it be better to have some kind
>of continuous "self test" going on?

A simple way to do this would be to have a little watchdog box, simply
emitting a stream of characters at a known rate. If it is powered from the
same supply as the UPS unit it will stop sending when the power goes out. 

All you need is a simple watchdog deamon under Unix to do a shutdown if it
doesn't see a character on the appropriate port for a specified period of
time.

I'm sure that a reasonably good hardware type could design something
appropriate in a few minutes using a 555 timer, garden variety UART, and
appropriate glue parts.

This would have the advantage of working easily with virtually any UPS
without having to have something overly intelligent in it.

The watchdog is very simple to write, set an alarm, read a char, loop. If
the alarm ever goes off call shutdown. To keep things robust make the
character rate about 1/5 of alarm time.  For example if you have a twenty
minute UPS (i.e. you can run twenty minutes from your UPS) and need ten to
shut things down safely; set the watchdog alarm for five minutes, and watchdog
hardware for one char per minute.

-- 
Stuart.Lynne@wimsey.bc.ca {ubc-cs,uunet}!van-bc!sl     Vancouver,BC,604-937-7532

jbayer@ispi.UUCP (Jonathan Bayer) (01/30/89)

In article <210@wa3wbu.UUCP> john@wa3wbu.UUCP (John Gayman) writes:
>
>    Does anyone have experience with interfacing a small UPS system (600-
>1000VA) to a 386-based Unix box to allow for orderly system shutdown
>when the batteries run down ?
>

The UPSs I have worked with usually have an open/close switch.  In other
words, the switch is usually open, but closes when the power goes away. 
It could also be the other way around.

What you want to do is to create a background daemon which will poll a
serial port.  The serial port will be hooked up to the ups, switching
open the td and rd lines.  In the case of the normally open switch, if
the deamon is able to send a character out the port, and get it back, it
will know that power has failed. In the case of the normally closed
switch, when it fails to receive the character back it will know that
power has failed.

The daemon should poll at least once every two minutes (depending on the
capacity of the UPS).  When it detects a power failure it should notify
all users that a system shutdown due to power failure is imminent, and
start keeping time.  If the power does not come back within a specified
period of time, the daemon will do an orderly system shutdown.


JB


-- 
Jonathan Bayer			      Beware: The light at the end of the
Intelligent Software Products, Inc.	      tunnel may be an oncoming dragon
19 Virginia Ave.				...uunet!ispi!jbayer
Rockville Centre, NY 11570  (516) 766-2867    jbayer@ispi

blum@drutx.ATT.COM (Mark Blumhardt) (02/02/89)

In article <431@ispi.UUCP>, jbayer@ispi.UUCP (Jonathan Bayer) writes:
> In article <210@wa3wbu.UUCP> john@wa3wbu.UUCP (John Gayman) writes:
> >
> >    Does anyone have experience with interfacing a small UPS system (600-
> >1000VA) to a 386-based Unix box to allow for orderly system shutdown
> >when the batteries run down ?
> >
> What you want to do is to create a background daemon which will poll a
> serial port.  The serial port will be hooked up to the ups...

Another way, which may use less resources is to...hook the serial port to
the UPS, and connect (I cant remember exactly) ground and DTR.  Exec a
process that tries to open the port.  It will block (or return), depending
on the state of the contact closure.  After the return you can do a
graceful shutdown.

Mark

ag@elgar.UUCP (Keith Gabryelski) (02/04/89)

In article <10170@drutx.ATT.COM> blum@drutx.ATT.COM (Mark Blumhardt) writes:
>In article <431@ispi.UUCP>, jbayer@ispi.UUCP (Jonathan Bayer) writes:
>> In article <210@wa3wbu.UUCP> john@wa3wbu.UUCP (John Gayman) writes:
>> >
>> >    Does anyone have experience with interfacing a small UPS system (600-
>> >1000VA) to a 386-based Unix box to allow for orderly system shutdown
>> >when the batteries run down ?
>> >
>> What you want to do is to create a background daemon which will poll a
>> serial port.  The serial port will be hooked up to the ups...
>
>Another way, which may use less resources is to...hook the serial port to
>the UPS, and connect (I cant remember exactly) ground and DTR.  Exec a
>process that tries to open the port.  It will block (or return), depending
>on the state of the contact closure.  After the return you can do a
>graceful shutdown.

Yes, as I had pointed out earlier, this is infact how Elgar's UniSafe
product works.  I think Jonathan was talking about a fault tolerant
way of handling the communications on a possibly faulty serial device
(one which may hang).

Actually, the first demo I gave of UniSafe was basicly:

    cat /dev/null >/dev/ttya	# When this returns, we are on battery power

    wall << THEEND
    We're on battery power.  Going down in 1 minute.
    THEEND

    sleep 60			# One minute

    /etc/shutdown 0		# See Ya!

This is ofcourse simplistic; you'd never want to wait just one minute
and you'd definitely want to test for short term power failures, but
it does the job.

Pax, Keith
-- 
ag@elgar.CTS.COM         Keith Gabryelski          ...!{ucsd, crash}!elgar!ag