[alt.sources.d] UPS monitor daemon part 1 of 1

woods@eci386.uucp (Greg A. Woods) (04/11/91)

[BTW, just as a reminder for people who post sources to alt.sources:
Please set the "Followup-To:" header to alt.sources.d.]

In article <1991Apr03.095011.9609@pilikia.pegasus.com> root@pilikia.pegasus.com (Art Neilson) writes:
> 	The UPS monitor daemon or "upsd"  watches the serial port
> 	connected to an UPS and will perform an unattended shutdown
> 	of the system if the UPS is on battery longer than a specified
> 	number of minutes.

Neat-oh.  How about a feature that can calculate the total time down
and the average charging time, and thus be able to figure out how long
the battery will last?  I've seen this in a couple of commercial pgms.

>[....]
> echo shar: Extracting \"'README'\" \(3910 characters\)
> sed "s/^X//" >'README' <<'END_OF_FILE'
> X	Tue Apr 02 23:24:20 HST 1991	art@pilikia.pegasus.com		Pg. 1
>[....]
> X	usage: upsd [-d tty][-c cmd][-l log][-t min]
> X		-d tty		pathname of UPS device
> X		-c cmd		pathname of shutdown command
> X		-l log		pathname of UPS log file
> X		-t min		delay time in minutes
.[....]
> X	The -c cmd option specifies the full pathname of the command
> X	to be executed to shut down the system.  This command must
> X	be enclosed in quotes if it consists of 2 or more words.

A more elegant solution for System V is to just sent a SIGPWR to init,
i.e. kill(1, SIGPWR); and have your inittab configured correctly to
"do the right thing" with powerfail (and/or powerwait) entries.  Why
waste all that code which was put there for just this feature?

/etc/shutdown scripts are for human users, and can vary widely -- some
even ask for confirmation!  Not something the average daemon can answer!

Init is also smart about what it does with powerfail and powerwait
depending upon the current run-level, thus even if you are in
single-user mode, it can, for example, be configured to run 'sync'
and/or uadmin to halt the kernel.
-- 
							Greg A. Woods
woods@{eci386,gate,robohack,ontmoh,tmsoft}.UUCP		ECI and UniForum Canada
+1-416-443-1734 [h]  +1-416-595-5425 [w]  VE3TCP	Toronto, Ontario CANADA
Political speech and writing are largely the defense of the indefensible-ORWELL

syd@DSI.COM (Syd Weinstein) (04/12/91)

woods@eci386.uucp (Greg A. Woods) writes:
>Neat-oh.  How about a feature that can calculate the total time down
>and the average charging time, and thus be able to figure out how long
>the battery will last?  I've seen this in a couple of commercial pgms.
First off get a Best Products UPS, its in the UPS software itself
on the UPS (theirs has a Micro on board that speaks RS-232 and can
send change of status reports including time remaining on the battery,
load factors, voltage, etc.

The problem with doing the calc without reading amp draw and vin
is that the curve is not linear.  You need to figure the delta
in the vin of the battery (varies with size, charge and age of the
battery) to get a reliable calc.  Its easy if you can just scan
the vin, with a look for a signal change only interface (thats
not really rs-232 folks) its near impossible to get a good calculation.
-- 
=====================================================================
Sydney S. Weinstein, CDP, CCP                   Elm Coordinator
Datacomp Systems, Inc.                          Voice: (215) 947-9900
syd@DSI.COM or dsinc!syd                        FAX:   (215) 938-0235

del@fnx.UUCP (Dag Erik Lindberg) (04/24/91)

In article <1991Apr11.155416.28426@eci386.uucp> woods@eci386.UUCP (Greg A. Woods) writes:
>In article <1991Apr03.095011.9609@pilikia.pegasus.com> root@pilikia.pegasus.com (Art Neilson) writes:
>> 	The UPS monitor daemon or "upsd"  watches the serial port
>> 	connected to an UPS and will perform an unattended shutdown
>> 	of the system if the UPS is on battery longer than a specified
>> 	number of minutes.

This software does not seem to deal with the following case:
- Assume a UPS that lasts approximately 20 minutes on battery.
- I set the daemon to shut the system down at 15 minutes.
- Now, assume a power outage of 19 minutes duration.
- At 15 minutes the system starts to shut down.
- At 18 minutes the system is sitting at the "Press any key to reboot"
- At 19 minutes the power returns.
- We now have steady state with:
  a) Line power restored.
  b) Batteries are charging
  c) The system is waiting indefinitely for human intervention.

This is unacceptable to me.  It would seem the only acceptable solution
would require MCU control including the ability to actually shut off
line power to the system after a pre-determined delay to allow orderly
shutdown, regardless of whether line power has been restored or not.
Then, if line power *has* been restored, power up the system again.

>
>Neat-oh.  How about a feature that can calculate the total time down
>and the average charging time, and thus be able to figure out how long
>the battery will last?  I've seen this in a couple of commercial pgms.

As someone pointed out, to really know how the battery is doing is
difficult without analog monitoring of the VIN of the charging system.
I don't think that would be much of a problem though, as you could 
easily build in big enough fudge factors to have the whole thing work,
and the idea is an excellent one.

>> X	The -c cmd option specifies the full pathname of the command
>> X	to be executed to shut down the system.  This command must
>> X	be enclosed in quotes if it consists of 2 or more words.
>
>A more elegant solution for System V is to just sent a SIGPWR to init,
>i.e. kill(1, SIGPWR); and have your inittab configured correctly to
>"do the right thing" with powerfail (and/or powerwait) entries.  Why
>waste all that code which was put there for just this feature?

WRONG!!!  This may be good enough for a single user workstation, but
any multi-user system *MUST* warn users of impending doom to allow 
them to save their work, shut down whatever they are doing, and exit
in a way that will allow them to resume work as quickly as possible
when power is restored.  Don't assume that everyone will be aware
power went out on the system, they could be in a different building,
or even another city.

>
>/etc/shutdown scripts are for human users, and can vary widely -- some
>even ask for confirmation!  Not something the average daemon can answer!

So don't use the supplied shutdown script.  Modify it, or write another.

-- 
del AKA Erik Lindberg                             uunet!pilchuck!fnx!del
                          Who is John Galt?

woods@eci386.uucp (Greg A. Woods) (04/26/91)

In article <958@fnx.UUCP> del@fnx.UUCP (Dag Erik Lindberg) writes:
> In article <1991Apr11.155416.28426@eci386.uucp> woods@eci386.UUCP (that's me!) wrote:
> >A more elegant solution for System V is to just sent a SIGPWR to init,
> >i.e. kill(1, SIGPWR); and have your inittab configured correctly to
> >"do the right thing" with powerfail (and/or powerwait) entries.  Why
> >waste all that code which was put there for just this feature?
> 
> WRONG!!!  This may be good enough for a single user workstation, but
> any multi-user system *MUST* warn users of impending doom to allow 
> them to save their work, shut down whatever they are doing, and exit
> in a way that will allow them to resume work as quickly as possible
> when power is restored.  Don't assume that everyone will be aware
> power went out on the system, they could be in a different building,
> or even another city.

Uh, I said "do the right thing"....  On my 3b2, which is certainly not
a workstation(!), when init receives a SIGPWR, such as when the
"power" switch is flicked to off, the system is gracefully shut down,
giving the users a one-minute warning to log off....  I never assume
anything!  :-)

> >/etc/shutdown scripts are for human users, and can vary widely -- some
> >even ask for confirmation!  Not something the average daemon can answer!
> 
> So don't use the supplied shutdown script.  Modify it, or write another.

No, I'd change the deamon to do a 'kill(1, SIGPWR)', then make sure my
inittab and related scripts did the right thing (i.e. the same way my
3b2 works).

On the other hand, with my 3b2, a directly connecting the UPS to the
powerfail line on the "power" switch into the motherboard eliminates
the need for the daemon in the first place!
-- 
							Greg A. Woods
woods@{eci386,gate,robohack,ontmoh,tmsoft}.UUCP		ECI and UniForum Canada
+1-416-443-1734 [h]  +1-416-595-5425 [w]  VE3TCP	Toronto, Ontario CANADA
Political speech and writing are largely the defense of the indefensible-ORWELL