• Re: [gentoo-user] Suggestions for Gentoo-compatable UPS; stores around

    From Walter Dnes@21:1/5 to Dale on Sun Aug 18 18:00:02 2024
    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 [email protected] 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

    --
    There are 2 types of people
    1) Those who can extrapolate from incomplete data

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Walter Dnes@21:1/5 to Dale on Mon Aug 19 02:30:02 2024
    On Sun, Aug 18, 2024 at 04:06:41PM -0500, Dale wrote

    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?

    At the top of the script is the line "counter=60". Change that to "counter=300". The script does a "sleep 1" (1 second delay) each pass
    through the "while" loop. Note that it also checks...

    if echo "$output" | grep -q "OB"

    ...on each pass through the loop. ***IF AC POWER IS RESTORED BEFORE THE COUNTDOWN FINISHES*** the battery is no longer in use and the "if"
    returns false. It then executes the "else" portion of the loop on that
    pass and exits the script without taking any action. I don't want to
    hibernate or shutdown for a short 5-second power blip.

    --
    There are 2 types of people
    1) Those who can extrapolate from incomplete data

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)