From: Dale <rdalek1967@gmail.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Suggestions for Gentoo-compatable UPS; stores around Toronto??
Date: Sun, 18 Aug 2024 16:06:41 -0500 [thread overview]
Message-ID: <0a59e8d9-2cf8-78a2-860e-cc398546652b@gmail.com> (raw)
In-Reply-To: <MTAwMDAzMi53ZG5lc2RheQ.1723996320@quikprotect>
Walter Dnes wrote:
> On Sun, Aug 18, 2024 at 07:00:52AM -0500, Dale wrote
>> Walter Dnes wrote:
>>> My current manual hibernation script is...
>>>
>>> #!/bin/bash
>>> sync
>>> sudo /usr/sbin/hibernate
>> The one thing I wish I could figure out how to set up, once power
>> is lost, wait 2 minutes, maybe 5 minutes, then power off even if
>> the battery still has lots of power left.
> I asked Mr. Google. APCUPSD has an ONBATTERDELAY command that does
> something only if the battery is in use (i.e. AC power is off) for at
> least a certain specified length of time..
>
>> P. S. Your little script looks like something I'd come up with. Simple
>> but works. ;-) LOL
> The solution for NUT appears to be to launch a countdown script rather
> than do an immediate kill. The examples I saw were exceedingly complex,
> designed to handle all sorts of outlier cases. Here's the barebones
> simplest I think you can get away with. It launches as soon as
> ONBATTERY is detected. It has a main loop that runs up to 60 seconds
> (i.e. "sleep 1" x 60). If it falls through the bottom of the loop
> (counter = 0), it executes a "hibernate" (or "shutdown" if you prefer).
> If if detects battery not in use (i.e. AC power back on) before
> 60 seconds, it'll exit entirely. ***WARNING*** I HAVE NOT TESTED THIS
> CODE. I don't have a machine with a UPS running NUT
>
> ###################################################
>
> in /etc/nut/upsmon.conf on client change to this
>
> NOTIFYCMD "/etc/nut/countdown"
> NOTIFYFLAG ONBATT EXEC
>
> /etc/nut/countdown looks like so (counter = 60 ==> 60 seconds)
>
> ###################################################
>
> #!/bin/bash
> counter=60
>
> while [ ${counter} -gt 0 ]
> do
> output=$(upsc qnapups@192.168.222.252 ups.status)
> if echo "$output" | grep -q "OB"
> then
> sleep 1
> counter--
> else
> exit
> fi
> done
> /usr/sbin/hibernate
>
> ###################################################
>
> NOTES:
> * status output may change between versions
> * adjust IP address as appropriate for your system
> * make sure to mark the script executable
> * you may have to set up and invoke sudo for "hibernate"
> or "shutdown" if the NUT daemon is not root
>
I think I get what your script does. When Nut sees onbatt then it
executes your script because of the NOTIFYCMD option. The script then
waits 60 seconds then executes what is under 'done'. Could one change
the 60 seconds to say 300 seconds? If I'm not here, it will have to
shut itself down. If I'm here tho, I'd like to be able to stop it from
shutting down and shutdown manually. I assume I could just kill the
script to stop it if I'm here.
I've looked into this too in the past and it does seem more complicated
than it should be. It should be as simple as a option that onbatt,
shutdown in 5 minutes unless power is returned or user stops it. There
used to be a app called powstatd I think. I used it on Mandrake
waaaaaaay back. It would do that with a simple setting. I don't know
why Nut has so much trouble with this. Found its web page.
https://manpages.ubuntu.com/manpages/xenial/man8/powstatd.8.html
If only. ;-)
Dale
:-) :-)
next prev parent reply other threads:[~2024-08-18 21:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-18 3:48 [gentoo-user] Suggestions for Gentoo-compatable UPS; stores around Toronto?? Walter Dnes
2024-08-18 12:00 ` Dale
2024-08-18 15:52 ` Walter Dnes
2024-08-18 19:11 ` Daniel Frey
2024-08-18 21:06 ` Dale [this message]
2024-08-19 0:27 ` Walter Dnes
2024-08-19 1:10 ` Dale
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0a59e8d9-2cf8-78a2-860e-cc398546652b@gmail.com \
--to=rdalek1967@gmail.com \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox