Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-15 Thread Dmitri Stepanov

>Четверг, 14 июля 2016, 23:58 +03:00 от Roger Price < ro...@rogerprice.org >:
>
>On Thu, 14 Jul 2016, Dmitri Stepanov wrote:
>
>> Some of those hosts haven't NUT including upsmon (and other software 
>> which is not included by suppliers of the hosts) for a number of 
>> reasons. I don't need to inform not-NUT hosts about any UPS events, 
>> etc... but only shutdown all the hosts after upssched timer expired. So 
>> I think shutdown them via ssh would be enough and creating some 
>> replacement for upsmon is too much.
>
>Perhaps it is possible to have a micro upsmon in the form of a cron job in 
>every slave which, every minute, runs something like
>
>  rprice@maria:~> X=$( echo "GET VAR my-ups battery.charge" | netcat -w1 
>upsd-server 3493 )
>  rprice@maria:~> if [[ "$X" =~ \"([0-9]*)\" ]] ; then Y=${BASH_REMATCH[1]}; 
>else Y=999 ; fi
>  rprice@maria:~> if [[ "$Y" -gt 35 ]] ; then echo "Carry on $Y" ; else echo 
>"Shutdown $Y" ; fi
>  Carry on 100
>
>Different slaves could have different low battery values. I'm sure that a 
>netcat expert would be able to find a way of executing netcat only once.

Cool. I've never think via this way. I'm sure I'll use it. Thank you for the 
hint.
But a problem could be with netcat software (if it installed or not on the 
not-NUT slaves, moreover there are a number of Windows hosts). Unfortunately I 
have no ability to break in configuration and installed software of the not-NUT 
hosts too deeply (licenses of the suppliers of the hosts, etc...).

Thanks to Kris Jordan, I guess the problem is the uid of the upssched 
(CMDSCRIPT and my shutdown script and ssh) process. I hope I 'd check it as 
soon as I get connection to the system.

>
>Roger
>
>___
>Nut-upsuser mailing list
> Nut-upsuser@lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-14 Thread Kris Jordan

Dmitri Stepanov wrote on 7/14/2016 5:18 AM:
All the hosts are installed together in one rack and have fed from one 
UPS (only I am remote from the system :) and I haven't ability to 
connect to it. Some of hosts haven't NUT for a number of reasons. I 
don't need to inform not-NUT hosts about any UPS events, heartbeat, 
etc... but only shutdown all the hosts after upssched timer expired. 
Because script shutdown-all-hosts.sh works fine (there is no ssh 
problem) if it's been run by hand but don't work from CMDSCRIPT - I 
thought that I miss something "at the NUT side".


I do something similar, I don't want inbound connections (DMZ --> LAN), 
so I use SSH.


SSH environment difference (e.g. SSH agent forwarding)? That could 
explain why it works manually, but not when unattended (upssched).


I specifically set SSH_AUTH_SOCK="" in my shutdown script so it won't 
affect my testing when running the script by hand. I use ssh -i 
 for each host to shut down.


___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser


Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-14 Thread Roger Price

On Thu, 14 Jul 2016, Dmitri Stepanov wrote:

Some of those hosts haven't NUT including upsmon (and other software 
which is not included by suppliers of the hosts) for a number of 
reasons. I don't need to inform not-NUT hosts about any UPS events, 
etc... but only shutdown all the hosts after upssched timer expired. So 
I think shutdown them via ssh would be enough and creating some 
replacement for upsmon is too much.


Perhaps it is possible to have a micro upsmon in the form of a cron job in 
every slave which, every minute, runs something like


 rprice@maria:~> X=$( echo "GET VAR my-ups battery.charge" | netcat -w1 
upsd-server 3493 )
 rprice@maria:~> if [[ "$X" =~ \"([0-9]*)\" ]] ; then Y=${BASH_REMATCH[1]}; 
else Y=999 ; fi
 rprice@maria:~> if [[ "$Y" -gt 35 ]] ; then echo "Carry on $Y" ; else echo 
"Shutdown $Y" ; fi
 Carry on 100

Different slaves could have different low battery values. I'm sure that a 
netcat expert would be able to find a way of executing netcat only once.


Roger

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser


Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-14 Thread Dmitri Stepanov
Thank you for answer Stuart

>Среда, 13 июля 2016, 17:54 +03:00 от Stuart Gathman :
>
>On 07/13/2016 10:02 AM, Stuart Gathman wrote:
>> On 07/13/2016 04:17 AM, Dmitri Stepanov wrote:
>>>I need to shutdown a number of hosts which has not NUT from one which 
>>> has it.
>> Let's make sure you are not missing an obvious point.  By "has not NUT",
>> you might mean not running upsd.  The best practice is to run upsmon on
>> the other hosts.  This does not require running NUT proper (server).  Is
>> there some reason why you can't run upsmon on the other hosts? 
>> Typically, upsd and drivers are packaged as something like "nut-server",
>> whereas upsmon is packaged as "nut-client".
>If you truly can't run upsmon, then you can speak the upsd protocol
>directly over tcp.  For an example non-nut implementation, look at the
>"check_ups" plugin for nagios.  It queries a NUT server for basic
>information, including whether it is on battery.
>

Some of those hosts haven't NUT including upsmon (and other software which is 
not included by suppliers of the hosts) for a number of reasons. I don't need 
to inform not-NUT hosts about any UPS events, etc... but only shutdown all the 
hosts after upssched timer expired. So I think shutdown them via ssh would be 
enough and creating some replacement for upsmon is too much.

>___
>Nut-upsuser mailing list
>Nut-upsuser@lists.alioth.debian.org
>http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-14 Thread Dmitri Stepanov
Thank you Roger

 Среда, 13 июля 2016, 15:22 +03:00 от Roger Price :
>
>On Wed, 13 Jul 2016, Dmitri Stepanov wrote:
>
    shutdown-all-hosts.sh contains:
 # Linux hosts
 HOSTLIST="sim iogate br"
 for host in $HOSTLIST
 do
 ...
  ssh $host halt -p
 ...
 done
>
    shutdown-all-hosts.sh works fine if it runned manually.
    But it does not work even if I insert sleep 30 sec before upsmon -c fsd
>>>
>>> When you say "it does not work", what are the symptoms? Does 
>>> shutdown-all-hosts.sh get called?
>
>> System has installed far away (in China) and there is bad Internet 
>> connection, so I might have ability to connect and check log files in a 
>> few day or weeks. Now I know exactly only that NUTed hosts shutdown via 
>> NUT as expected and no one host listed in shutdown-all-hosts.sh script 
>> don't.
>
>> Roger, I would appreciate if you give me a hint how to "reproduce the 
>> NUT protocol ... ". Do you mean getting feedback to CMDSCRIPT about the 
>> "no NUTed" slaves indeed shutting down and/or some timing in NUT config 
>> files...?
>
>Without knowing the details of your system architecture, it looks as if 
>your system is very different from the typical case for which NUT is 
>intended.  I'm assuming that your with-NUT machine is far away from the 
>"slaves" with an unreliable connection.  In this case the "slaves" will 
>have to be autonomous and decide for themselves if and when they shut 
>down.  I notice that you set up the SSH connection only when you want to 
>remotely order a slave shutdown.  Perhaps in your case it would be better 
>to have the ssh link open all the time with a periodic "heartbeat" between 
>the no-NUT slaves and the master-with-NUT. In other words, sim, iogate and 
>br behave as masters, not slaves.

All the hosts are installed together in one rack and have fed from one UPS 
(only I am remote from the system  :) and I haven't ability to connect to it. 
Some of hosts haven't NUT for a number of reasons. I don't need to inform 
not-NUT hosts about any UPS events, heartbeat, etc... but only shutdown all the 
hosts after upssched timer expired. Because script shutdown-all-hosts.sh works 
fine (there is no ssh problem) if it's been run by hand but don't work from 
CMDSCRIPT - I thought that I miss something "at the NUT side".

>
>
>> It is not good to shutdown from CMDSCRIPT the master itself. Is it correct?
>
>If the no-NUT machines were autonomous, then NUT is in charge of just the 
>with-NUT machine, and there is no problem with shutting down from the 
>CMDSCRIPT.
>
>Could you build a local version of your setup for testing?
>

Yes I've thought about it. I'd build the model of the system locally.

>
>Roger
>___
>Nut-upsuser mailing list
>Nut-upsuser@lists.alioth.debian.org
>http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-13 Thread Stuart Gathman
On 07/13/2016 10:02 AM, Stuart Gathman wrote:
> On 07/13/2016 04:17 AM, Dmitri Stepanov wrote:
>>I need to shutdown a number of hosts which has not NUT from one which has 
>> it.
> Let's make sure you are not missing an obvious point.  By "has not NUT",
> you might mean not running upsd.  The best practice is to run upsmon on
> the other hosts.  This does not require running NUT proper (server).  Is
> there some reason why you can't run upsmon on the other hosts? 
> Typically, upsd and drivers are packaged as something like "nut-server",
> whereas upsmon is packaged as "nut-client".
If you truly can't run upsmon, then you can speak the upsd protocol
directly over tcp.  For an example non-nut implementation, look at the
"check_ups" plugin for nagios.  It queries a NUT server for basic
information, including whether it is on battery.

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser


Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-13 Thread Stuart Gathman
On 07/13/2016 04:17 AM, Dmitri Stepanov wrote:
>I need to shutdown a number of hosts which has not NUT from one which has 
> it.
Let's make sure you are not missing an obvious point.  By "has not NUT",
you might mean not running upsd.  The best practice is to run upsmon on
the other hosts.  This does not require running NUT proper (server).  Is
there some reason why you can't run upsmon on the other hosts? 
Typically, upsd and drivers are packaged as something like "nut-server",
whereas upsmon is packaged as "nut-client".

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser


Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-13 Thread Roger Price

On Wed, 13 Jul 2016, Dmitri Stepanov wrote:


   shutdown-all-hosts.sh contains:
# Linux hosts
HOSTLIST="sim iogate br"
for host in $HOSTLIST
do
...
 ssh $host halt -p
...
done



   shutdown-all-hosts.sh works fine if it runned manually.
   But it does not work even if I insert sleep 30 sec before upsmon -c fsd


When you say "it does not work", what are the symptoms? Does 
shutdown-all-hosts.sh get called?


System has installed far away (in China) and there is bad Internet 
connection, so I might have ability to connect and check log files in a 
few day or weeks. Now I know exactly only that NUTed hosts shutdown via 
NUT as expected and no one host listed in shutdown-all-hosts.sh script 
don't.


Roger, I would appreciate if you give me a hint how to "reproduce the 
NUT protocol ... ". Do you mean getting feedback to CMDSCRIPT about the 
"no NUTed" slaves indeed shutting down and/or some timing in NUT config 
files...?


Without knowing the details of your system architecture, it looks as if 
your system is very different from the typical case for which NUT is 
intended.  I'm assuming that your with-NUT machine is far away from the 
"slaves" with an unreliable connection.  In this case the "slaves" will 
have to be autonomous and decide for themselves if and when they shut 
down.  I notice that you set up the SSH connection only when you want to 
remotely order a slave shutdown.  Perhaps in your case it would be better 
to have the ssh link open all the time with a periodic "heartbeat" between 
the no-NUT slaves and the master-with-NUT. In other words, sim, iogate and 
br behave as masters, not slaves.



It is not good to shutdown from CMDSCRIPT the master itself. Is it correct?


If the no-NUT machines were autonomous, then NUT is in charge of just the 
with-NUT machine, and there is no problem with shutting down from the 
CMDSCRIPT.


Could you build a local version of your setup for testing?

Roger___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-13 Thread Dmitri Stepanov
Thank you for answer Roger

>Среда, 13 июля 2016, 11:49 +03:00 от Roger Price :
>
>On Wed, 13 Jul 2016, Dmitri Stepanov wrote:
>
>> Hi
>>
>>    I need to shutdown a number of hosts which has not NUT from one which has 
>> it.
>>
>>    I tried to do it from upssched script (after upssched's timer) like this:
>>
>> case $1 in
>>     earlyshutdown)
>>     logger -t upssched-cmd "Early shutdown is started"
>>     /bin/sh /usr/local/sbin/shutdown-all-hosts.sh
>>     /usr/local/sbin/upsmon -c fsd
>>     ;;
>> esac
>>
>>    shutdown-all-hosts.sh contains:
>> # Linux hosts
>> HOSTLIST="sim iogate br"
>> for host in $HOSTLIST
>> do
>> ...
>>  ssh $host halt -p
>> ...
>> done
>> # Windows hosts
>> ssh shut@com "shutdown -s -t 0"
>>
>>    shutdown-all-hosts.sh works fine if it runned manually.
>>    But it does not work even if I insert sleep 30 sec before upsmon -c fsd
>
>When you say "it does not work", what are the symptoms? Does 
>shutdown-all-hosts.sh get called?

System has installed far away (in China) and there is bad Internet connection, 
so I might have ability to connect and check log files in a few day or weeks. 
Now I know exactly only that NUTed hosts shutdown via NUT as expected and no 
one host listed in shutdown-all-hosts.sh script don't.

>
>>    Also I read somewhere that it is not a good idea to shutdown other hosts 
>> from the CMDSCRIPT.
>
>The User Manual chapter 7.2:
>
><< It’s not a good idea to call your system’s shutdown routine directly 
>from the CMDSCRIPT, since there’s no synchronization with the slave 
>systems hooked to the same UPS. FSD is the master’s way of saying "we’re 
>shutting down now like it or not, so you’d better get ready". >> 
>http://networkupstools.org/docs/user-manual.chunked/ar01s07.html

It is not good to shutdown from CMDSCRIPT the master itself. Is it correct?

>
>If you want to shutdown your slave systems siom, iogate and br from the 
>CMDSCRIPT, you will need to of "slaves first", 
>then the master.  Your current protocol does not check that the slaves are 
>indeed shutting down.

Roger, I would appreciate if you give me a hint how to "reproduce the NUT 
protocol ... ". Do you mean getting feedback to CMDSCRIPT about the "no NUTed" 
slaves indeed shutting down and/or some timing in NUT config files...?

>
>Roger
>___
>Nut-upsuser mailing list
>Nut-upsuser@lists.alioth.debian.org
>http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Re: [Nut-upsuser] Best practice to shutdown hosts which has not NUT via upssched

2016-07-13 Thread Roger Price

On Wed, 13 Jul 2016, Dmitri Stepanov wrote:


Hi

   I need to shutdown a number of hosts which has not NUT from one which has it.

   I tried to do it from upssched script (after upssched's timer) like this:

case $1 in
    earlyshutdown)
    logger -t upssched-cmd "Early shutdown is started"
    /bin/sh /usr/local/sbin/shutdown-all-hosts.sh
    /usr/local/sbin/upsmon -c fsd
    ;;
esac

   shutdown-all-hosts.sh contains:
# Linux hosts
HOSTLIST="sim iogate br"
for host in $HOSTLIST
do
...
 ssh $host halt -p
...
done
# Windows hosts
ssh shut@com "shutdown -s -t 0"

   shutdown-all-hosts.sh works fine if it runned manually.
   But it does not work even if I insert sleep 30 sec before upsmon -c fsd


When you say "it does not work", what are the symptoms? Does 
shutdown-all-hosts.sh get called?



   Also I read somewhere that it is not a good idea to shutdown other hosts 
from the CMDSCRIPT.


The User Manual chapter 7.2:

<< It’s not a good idea to call your system’s shutdown routine directly 
from the CMDSCRIPT, since there’s no synchronization with the slave 
systems hooked to the same UPS. FSD is the master’s way of saying "we’re 
shutting down now like it or not, so you’d better get ready". >> 
http://networkupstools.org/docs/user-manual.chunked/ar01s07.html


If you want to shutdown your slave systems siom, iogate and br from the 
CMDSCRIPT, you will need to reproduce the NUT protocol of "slaves first", 
then the master.  Your current protocol does not check that the slaves are 
indeed shutting down.


Roger___
Nut-upsuser mailing list
Nut-upsuser@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser