DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2010-02-15 12:11:45

caust1c
Member
Registered: 2010-01-03
Posts: 35

Given up on UPS control. Simple ping shutdown script?

I have officially given up on UPS control through the FW's NUT or trying to install it on my own.  As a result I have been trying to setup a little cronjob to shutdown my NAS automatically but it does not seem to be working.  I am REALLY new to this so please if anyone can point out what I am doing wrong.

Theory:  If my power goes out, my router is down but DNS-323 is on my UPS.  (My windows box is using the UPS control via USB instead now).  Since my network is down, I wanted a cronjob to run a 'power test' script every 5 minutes. 

I have successfully got my cronjobs to reload on boot up.  I have cleanboot working to 'cleanly' shutdown and reboot by command line.

My crontab:
*/5 * * * * /mnt/HD_a2/ffp/share/power.sh

My script: /mnt/HD_a2/ffp/share/power.sh

Code:

#!/bin/sh

PING=`/ffp/bin/ping -c 1 192.168.221.1 | /ffp/bin/grep % | awk '{print $7}'`

if [ "$PING" = "0%" ]
        then
                echo Power on!
        else
                /sbin/shutdown
fi

So I tried adding an echo of $PING and it did show "0%" when my router was there... I am assuming I have something wrong with my expression as my NAS shuts down every 5 minutes even when it is able to ping 192.168.221.1

What the heck am I missing here?  Thanks!!

EDIT: I admit, much of this script was cut from another one I found so admittedly I don't really know exactly what I'm doing but I it does seem like I'm setting my $PING right as I tested it with a simple echo for the 'else' statement 'echo power off!' and when i supplied an incorrect ip is did report as it should have...  Does it possibly have something to do with the network actually being down and trying to ping so I get a different result?

Last edited by caust1c (2010-02-15 12:17:18)

Offline

 

#2 2010-02-15 13:14:40

fordem
Member
Registered: 2007-01-26
Posts: 1938

Re: Given up on UPS control. Simple ping shutdown script?

Try searching the forum - I believe scripts have been written that use the windows box to shut the DNS-323 down - so when the power goes, the UPS triggers a shutdown on Windows & Windows triggers a shutdown on the DNS-323.

Offline

 

#3 2010-02-15 16:30:46

caust1c
Member
Registered: 2010-01-03
Posts: 35

Re: Given up on UPS control. Simple ping shutdown script?

I did look search into options like that but I don't have the ability to keep my network on the UPS.  Not sure how I could get the signal out prior to losing connectivity.

An option that actually relies on the network dieing looks like the best one in my mind.  Plus it is nicer that my windows box can depend on the UPS signals directly.

Offline

 

#4 2010-02-15 16:52:14

scarcow
Member
From: Hungary
Registered: 2008-10-10
Posts: 16

Re: Given up on UPS control. Simple ping shutdown script?

On my box there is no /sbin/shutdown, try /sbin/poweroff instead.

-sc

Offline

 

#5 2010-02-15 17:15:00

fordem
Member
Registered: 2007-01-26
Posts: 1938

Re: Given up on UPS control. Simple ping shutdown script?

caust1c wrote:

I did look search into options like that but I don't have the ability to keep my network on the UPS.  Not sure how I could get the signal out prior to losing connectivity.

An option that actually relies on the network dieing looks like the best one in my mind.  Plus it is nicer that my windows box can depend on the UPS signals directly.

In the scenario outlined the windows box does "depend" on the UPS signals directly - as for "keeping the network on the UPS" - it does require at least the network switch or router to be powered from the UPS, these typically are not high power consumption devices, and can usually be connected to whichever UPS is powering the remaining equipment.

In my case I have frequently have databases, that are physically located on a server, open on a desktop, and an orderly shutdown would depend on the network linking the two to be functional, so this works for me - but - whatever works best for you...

Offline

 

#6 2010-02-15 21:03:12

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: Given up on UPS control. Simple ping shutdown script?

The line
if [ "$PING" = "0%" ]
should be
if [ "$PING" == "0%" ]

But this will give you false positives, as icmp packages do get lost, sometimes.
A more stable approach:

Code:

#!/bin/sh

PING=`/ffp/bin/ping -c 3 192.168.221.1 | /ffp/bin/grep % | awk '{print $7}'`

if [ "$PING" == "100%" ]
        then
                /sbin/shutdown
        else
                echo Power on!
fi

Offline

 

#7 2010-02-15 21:53:51

caust1c
Member
Registered: 2010-01-03
Posts: 35

Re: Given up on UPS control. Simple ping shutdown script?

scarcow wrote:

On my box there is no /sbin/shutdown, try /sbin/poweroff instead.

-sc

I noticed that cleanboot copies 'shutdown' into /sbin/ so I was hoping that would invoke the safe unmounting to power off

Offline

 

#8 2010-02-15 22:03:43

caust1c
Member
Registered: 2010-01-03
Posts: 35

Re: Given up on UPS control. Simple ping shutdown script?

Mijzelf wrote:

The line
if [ "$PING" = "0%" ]
should be
if [ "$PING" == "0%" ]

But this will give you false positives, as icmp packages do get lost, sometimes.
A more stable approach:

Code:

#!/bin/sh

PING=`/ffp/bin/ping -c 3 192.168.221.1 | /ffp/bin/grep % | awk '{print $7}'`

if [ "$PING" == "100%" ]
        then
                /sbin/shutdown
        else
                echo Power on!
fi

Thanks the changes are clever and make sense!  I will give that a shot!  Can you explain what the difference between "=" and "==" is for an expression?  I did a quick google search and didn't notice.

fordem wrote:

In the scenario outlined the windows box does "depend" on the UPS signals directly - as for "keeping the network on the UPS" - it does require at least the network switch or router to be powered from the UPS, these typically are not high power consumption devices, and can usually be connected to whichever UPS is powering the remaining equipment.

In my case I have frequently have databases, that are physically located on a server, open on a desktop, and an orderly shutdown would depend on the network linking the two to be functional, so this works for me - but - whatever works best for you...

Yeah, I would ideally like to have both 'monitor' or at least let the other know when the UPS kicks in but damn I was having troubles getting NUT to work and I don't have time to be frustrated with that sort of thing right now! :-)

Offline

 

#9 2010-02-16 11:44:05

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: Given up on UPS control. Simple ping shutdown script?

caust1c wrote:

Can you explain what the difference between "=" and "==" is for an expression?  I did a quick google search and didn't notice.

Actually I can't. You wrote your box shut down each 5 minutes, so obviously the expression wasn't evaluated well. So I had a look at my scripts, and found that a comparison of two strings are done with a ==.

Offline

 

#10 2010-02-16 11:57:52

ojosch
Member
Registered: 2010-01-15
Posts: 18

Re: Given up on UPS control. Simple ping shutdown script?

If it were ME, I'd definitely get NUT to work on the DNS-323 and have the UPS plugged into that via USB cable. Then run the 323 as 'master' and run your Windows box as 'slave' and the DNS-323 can be in charge of shutting the Winbox down. Then you don't have to leave the Windows box running 24/7 (it consumes more juice than the 323). The DNS-323 only uses maybe like 14watts when idle and the drives are all spun-down. I can give you all of my NUT scripts and conf files if you want. What brand of UPS are you using? I'd run an APC if possible because I've had the least amount of trouble getting NUT to work on those. But supposedly NUT ships with 4 drivers for UPS which should cover most all UPSs. If the driver loads right, you should be able to see it in TOP as upsdrvctl. If it is not there then it did not load. If the dns-323 wiki how-to doesn't seem to help you understand NUT enough, I'd find some other generic NUT how-to somewhere else on the www. And like fordom says, I'd run your switch or router off the UPS as well so that you can have NUT shutdown the Windows box in slave mode over the wire. If the switch or router is not in the same room, and you need UPS power to it, you can either run an extension to it, or what I've done to my current 2 wireless routers and 2 switches that aren't near UPSs, is to take it apart and soldier in some jumpers from the ethernet terminals 4 and 5 (to bridge and be positive), and terminals 7 and 8 (to bridge and be negative) and the jumper get soldiered to the power terminals inside the router. BY THE WAY, THIS ONLY WORKS ON 10/100 and NOT GIGABIT SINCE GIGABIT uses all 8 wires in a cat5/6 cable, so if you use gigabit then you need to run separate power wires. Then I make or buy a power injector, which you plug the power adapter (transformer) into the other end of the ethernet cable which is near the UPS and it injects the (in my case) 12v juice from the low side of the transformer in pins 4-5 for positive and 7-8 for negative, which then feed down the ethernet cable and into my jumpers inside my wireless AP and bridge to the power terminals from inside of the unit. We always used this method when I worked for wireless ISPs where we would feed this 'power-over-ethernet' to the device to save on wiring and simplicity of installion for both client devices and AP equipment. I have all of my infrastructure backbone equipment in my house (main Linux router/webserver, 3 switches, 2 wireless access points, and the DNS-323) all set up on 2 different UPS throughout scattered locations in my house and use NUT as master on all the Linux boxes, and all switches and wireless APs run on UPS power so that when the power goes out the internet will not die and kill all of my ssh & vpn connections going out to my work from home. Luckily, my ISP is my city gov, and they have done a nice job of building their backbone infrastructure using UPSs and generators to run all of their equipment during power outages so that my internet stays up. If my power goes out, my whole network will last about 25 mins if I leave the Linux server running, but if I shut it down and run my simple router config'd to run as a simple backup when I shutdown the main router, and only run that with the wireless APs and switches, the system will run for about 2.5 hours and internet gateway still works fine. Sorry for the long spew, but I am just trying to illustrate that with some simple planning and execution of proven strategies that ISPs use, you can make your home network a little more robust and more accessible during all times, including power outages. My next plan is to scrap my big clucky 4U Linux server and install a DC battery-powered compact i686 that will do all the same things as my current web server does, but will run on a fraction of the current at any given time.

Anyway, I think you can get NUT working. It is not that complicated, just make sure your startup script deletes all the old UPS related stuff off the ramdrive if you are running the beta firmware, because when I ran pre-beta, I only had to add in upsmon from the NUT tools package and adjust the conf files a bit to get it to work, but after installing the beta 1.08 firmware, I had to make my new script delete all UPS related stuff that dlink was trying to load and run all UPS related stuff off of the fun_plug NUT package in order to be able to get the driver to even load.

Offline

 

#11 2010-02-16 22:06:26

caust1c
Member
Registered: 2010-01-03
Posts: 35

Re: Given up on UPS control. Simple ping shutdown script?

ojosch wrote:

If it were ME, I'd definitely get NUT to work on the DNS-323 and have the UPS plugged into that via USB cable. Then run the 323 as 'master' and run your Windows box as 'slave' and the DNS-323 can be in charge of shutting the Winbox down. Then you don't have to leave the Windows box running 24/7 (it consumes more juice than the 323). The DNS-323 only uses maybe like 14watts when idle and the drives are all spun-down. I can give you all of my NUT scripts and conf files if you want. What brand of UPS are you using? I'd run an APC if possible because I've had the least amount of trouble getting NUT to work on those. But supposedly NUT ships with 4 drivers for UPS which should cover most all UPSs. If the driver loads right, you should be able to see it in TOP as upsdrvctl. If it is not there then it did not load. If the dns-323 wiki how-to doesn't seem to help you understand NUT enough, I'd find some other generic NUT how-to somewhere else on the www. And like fordom says, I'd run your switch or router off the UPS as well so that you can have NUT shutdown the Windows box in slave mode over the wire. If the switch or router is not in the same room, and you need UPS power to it, you can either run an extension to it, or what I've done to my current 2 wireless routers and 2 switches that aren't near UPSs, is to take it apart and soldier in some jumpers from the ethernet terminals 4 and 5 (to bridge and be positive), and terminals 7 and 8 (to bridge and be negative) and the jumper get soldiered to the power terminals inside the router. BY THE WAY, THIS ONLY WORKS ON 10/100 and NOT GIGABIT SINCE GIGABIT uses all 8 wires in a cat5/6 cable, so if you use gigabit then you need to run separate power wires. Then I make or buy a power injector, which you plug the power adapter (transformer) into the other end of the ethernet cable which is near the UPS and it injects the (in my case) 12v juice from the low side of the transformer in pins 4-5 for positive and 7-8 for negative, which then feed down the ethernet cable and into my jumpers inside my wireless AP and bridge to the power terminals from inside of the unit. We always used this method when I worked for wireless ISPs where we would feed this 'power-over-ethernet' to the device to save on wiring and simplicity of installion for both client devices and AP equipment. I have all of my infrastructure backbone equipment in my house (main Linux router/webserver, 3 switches, 2 wireless access points, and the DNS-323) all set up on 2 different UPS throughout scattered locations in my house and use NUT as master on all the Linux boxes, and all switches and wireless APs run on UPS power so that when the power goes out the internet will not die and kill all of my ssh & vpn connections going out to my work from home. Luckily, my ISP is my city gov, and they have done a nice job of building their backbone infrastructure using UPSs and generators to run all of their equipment during power outages so that my internet stays up. If my power goes out, my whole network will last about 25 mins if I leave the Linux server running, but if I shut it down and run my simple router config'd to run as a simple backup when I shutdown the main router, and only run that with the wireless APs and switches, the system will run for about 2.5 hours and internet gateway still works fine. Sorry for the long spew, but I am just trying to illustrate that with some simple planning and execution of proven strategies that ISPs use, you can make your home network a little more robust and more accessible during all times, including power outages. My next plan is to scrap my big clucky 4U Linux server and install a DC battery-powered compact i686 that will do all the same things as my current web server does, but will run on a fraction of the current at any given time.

Anyway, I think you can get NUT working. It is not that complicated, just make sure your startup script deletes all the old UPS related stuff off the ramdrive if you are running the beta firmware, because when I ran pre-beta, I only had to add in upsmon from the NUT tools package and adjust the conf files a bit to get it to work, but after installing the beta 1.08 firmware, I had to make my new script delete all UPS related stuff that dlink was trying to load and run all UPS related stuff off of the fun_plug NUT package in order to be able to get the driver to even load.

I followed the wiki Howto on getting Nut to work.  I am using 1.07fw and it recognized my UPS as Cyber  Power AVR850 which is correct.   Whenever I tried to initiate the driver control after I manually installed NUT it failed.  I tried to remove the built-in NUT and could get the daemon to stop but I could not get the driverctrl to stop.  I am sure that had something to do with it not working for me.  I would definitely be up for getting NUT running if I can manage it, I just don't know enough about what I was doing.

On the positive power note, at least my desktop is sleeping much of the time or will hibernate in 3 minutes if the UPS says so.  My UPS will run my NAS for about 80 after the LCD and desktop have been shutdown automatically.  So really, this script I am using now is 'good enough'.  Not sure if I want the frustration of trying to get NUT working again...

I am sure my problem stopped with the driverctrl part as I couldn't unload the FW's one nor get the installed one to recognize my UPS.  Polling the USB did show my UPS as expected...

Offline

 

#12 2010-02-17 10:02:12

ojosch
Member
Registered: 2010-01-15
Posts: 18

Re: Given up on UPS control. Simple ping shutdown script?

Here's what I did when I was running the pre-beta FW 1.07 on mine. Since dlink ALREADY was loading the correct driver fine, and hence upsd, and upsdrvctl were loading just fine on their own from the dlink firmware (since I could also see my UPS in the web GUI 'Status' page), then I realized that these 2 daemons were working fine, and all I needed from NUT was upsmon (to actually provide the calling of 'shutdown' command when battery status changes to 'LOW BATT') which dlink does not provide. So I went to the nut startup .sh file that NUT uses to load it's version, and I did the following mod:  I commented out the lines in the start and stop sections which start and stop the upsd and upsdrvctl daemons, and left it so that it only would start up upsmon. When I did it like this, it worked great this way, but later on after I installed the new Beta 1.08 latest build, this method quit on me since something in the other conf files got messed in the later build and the driver couldn't load if I didn't stop the dlink daemons and update all the conf files and restart them. So currently while running beta FW, I made my startup script stop the upsd and upsdrvctl from dlink first (in case they even were to start - Although I never saw them running while using the beta FW), and then it copies all of my new conf files that make it start right and the upsmon bin file and over to the ramdrive (since I like to run everything from there), and then after it overwrites the dlink conf files, I start upsd, upsdrvctl, and upsmon. The problem you are having is that you need to either only start the upsmon daemon by itself and stop the startup script from trying to load all 3 daemons (since the 2 are probably already running fine), or you need to stop the existing dlink daemons first (if they are even running) and copy to overwrite the conf files that the dlink starts from. Type the command TOP after a fresh boot after you've DISABLED the NUT start script before reboot, and see what daemons are running on the pure dlink firmware image (see if upsd and upsdrvctl are running already on their own), and then decide where you want to go from there. If they ARE running already, then try this command: upsc <Your Driver Name Here>@localhost  (i.e: mine was : upsc usbhid@localhost ). If you don't know your driver name then go to: vi /usr/local/ups/etc/ups.conf and look for a section that looks like this:

[usbhid]
        driver = usbhid-ups
        port = USB
        desc = "APC Back-UPS 750VA"

And the name in brackets is the name that the driver is referred to as so the command would be: upsc usbhid@localhost and if you get 'unknown ups' then that was not the name. If there are 4 different listings like the one above, then go to TOP again and see what the name of the one that is running there is, and then go back to the ups.conf file and see which name it is in the brackets there, and then type the upsc command.

...and if you get a bunch of output showing UPS statistical data like this:

root@storage:~# upsc usbhid@localhost
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 50
battery.date: 2001/09/25
battery.mfr.date: 2009/10/08
battery.runtime: 11850
battery.runtime.low: 120
battery.type: PbAc
battery.voltage: 13.7
battery.voltage.nominal: 12.0
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: USB
driver.version: 2.2.2
driver.version.data: APC HID 0.92
driver.version.internal: 0.33
input.transfer.high: 139
input.transfer.low: 92
input.voltage: 123.0
input.voltage.nominal: 120
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.firmware: 841.I3 .D
ups.firmware.aux: I3
ups.load: 1
ups.mfr: American Power Conversion
ups.mfr.date: 2009/10/08
ups.model: Back-UPS ES 750
ups.productid: 0002
ups.serial: 3B0941X45063
ups.status: OL
ups.test.result: No test initiated
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.vendorid: 051d
root@storage:~#

...then that means the hardest part of setup is done. Now all you need to get shutdown is to copy the upsmon.conf template ( which all the templates are in /ffp/etc/examples/nut/ and add the line in that shows this: MONITOR usbhid@localhost 1 USERNAME YOURPASSWORD master  (obviously replacing with a valid username/password shown in upsd.users). Use the same username password that you set up in the DNS-323 NUT tutorial.

..and copy it to the path: /ffp/etc/upsmon.conf

Go to /usr/local/ups/etc/upsd.users to see the accepted usernames / passwords. You can cp an updated file here to have the username and password that upsd daemon will accept.

I'd try first what I said above and just load upsmon first by itself with the updated conf file and see if that works first. Below I attached the first start script I used to use that only starts upsmon by itself.
.
.

Last edited by ojosch (2010-02-17 10:08:11)


Attachments:
Attachment Icon OldScriptIranWhenIusedOldFW.sh, Size: 560 bytes, Downloads: 264

Offline

 

#13 2010-02-17 10:09:26

ojosch
Member
Registered: 2010-01-15
Posts: 18

Re: Given up on UPS control. Simple ping shutdown script?

Here's my new /ffp/start/ script I run that works with the beta build 1.08 which also copies over all my conf files to /usr/local/ups/etc which I've tweaked and allow the driver to load now

See attachment
.
.

Last edited by ojosch (2010-02-17 10:11:32)


Attachments:
Attachment Icon NewScriptIrunWithTheBetaFirmware.sh, Size: 1,142 bytes, Downloads: 269

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB