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 2008-01-23 03:21:13

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

Automated UPS shutdown - well - sort of

Like the title says - I've created a way to do an unattended shutdown of my DNS-323 when there is a power failure - this may not work for all of you, but it looks like it will work for me.

Specifically - you will need fun_plug, telnet, a UPS and a Windows system to monitor that UPS and send a command to the DNS-323 to shut it down.

My DNS-323 is powered from the same UPS (a PowerWare NetUPS) that powers my Windows 2003 server, and for several years I have used PowerWare's LANSafe software package to automatically shut the server down five minutes after the utility power fails.  LANSafe has the capability to execute a command of your choice based on one (or more) of several "events" - I believe APC's PowerChute has similar capabilities, but it's been many, many years since I've used it, so I could be wrong.

Using a freeware scripting tool called TST10 - available here and a script that goes like this ....

192.168.0.32
WAIT "#"
SEND "touch /tmp/shutdown\m"
WAIT "#"
SEND "exit\m"

This is tied to the "Shutdown in 1 minute" event in LANSafe - so assuming that there is a power failure lasting more than 4 minutes, when LANSafe sends the "Shutdown in 1 minute" message, TST10 executes and starts a telnet session to 192.168.0.32 (obviously you need to use the appropriate ip address here), waits for the prompt, sends the touch command to create the /tmp/shutdown file that initiates the shutdown of the DNS-323, waits a second time for the prompt and then sends an exit command to terminate the telnet session.

This works when I use the "test" feature in LANSafe - I'll do an actual power failure test tomorrow (I'll pull the plug) and let you know how it went.

I have some questions for the linux folks now - should I be dismounting the drives before I shut this thing down?  Can I actually do that - is the /tmp/ directory in the ram disk or on one of the drives?  What exactly is the syntax to be used umount \dev\????

Oh - the syntax to use TST10 goes like this tst10/r:whatever-you-called-the-script - and - I'm sure the basic concept can be used from whatever platform you like, if you're not into Windows.

Offline

 

#2 2008-01-23 19:46:17

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

Re: Automated UPS shutdown - well - sort of

So far - so good.

I configured LANSafe to broadcast shutdown alerts and configured my desktop to receive them, and then pulled the plug - watching both the server and the desktop screens, I received the shutdown alert messages and simultaneously with the "Shutdown in 1 minute message" on the desktop, there was a brief flash of a CLI screen on the server and a few seconds later the DNS-323 turned itself off.

Now - dismounting the drives - any attempt to dismount the drives from the CLI results in a "device is busy" message and the dismount fails - is this something I need to worry about?

Offline

 

#3 2008-01-25 10:03:29

Gambit
Member
Registered: 2008-01-05
Posts: 10

Re: Automated UPS shutdown - well - sort of

Dismounting things in Windows is very problematic; any open file explorer windows, browser windows, files, and so forth will prevent it from closing down "intelligently".  I'd probably schedule the DNS to shut down at 5 or so minutes -- experimentally derived based on shutdown time, natch -- so that it closes up after the windows box has safely (makes gun gesture at head) closed all it's shares.

On this related note, has anyone just set up apcupsd compiled for the DNS kernel so you can just plug the UPS right into it?  I don't know if the LANsafe has linux drivers (what doesn't, nowadays?) but that might be an amusing day or so for someone with more spare time then me atm smile

Offline

 

#4 2008-01-25 15:45:18

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

Re: Automated UPS shutdown - well - sort of

I'm not certain that I understand that "dismounting things in Windows".

The way I see it - Windows is not actually involved here - apart from being the platform through which the commands are channelled, and that telnet session could have come from any other device or OS - if you think it makes a difference I can boot Ubuntu or similar and try them there.

At the time I was trying to dismount the drives, none of the Windows boxes were actually "connected" to the DNS-323 - as in not having drives mapped (as a general rule, I don't use drive mappings here), not having explorer or browser windows open and not having files open - the only connection to the DNS-323 was the telnet session.

For what it's worth LANSafe does have a linux/unix version - but I've never gotten it to work (on a x86 system) - there is some sort of a problem with the install scripts, and PowerWare's tech support have not been particularly helpful here - my UPS also does not have a USB connection, it's one of the older serial communication units.

Shutting the DNS-323 down after the Windows system would require some sort of a script running on the DNS-323 to create a time delay after being called by the Windows box, I suppose I could do it, but the question is do I really need to?  According to another thread here - the "touch /tmp/shutdown" process possibly includes a "sataumount" command, that appears to dismount the drives (running it from the CLI causes the shares to become unavailable) but I'm not sufficently "linuxsmart" to be able to decide for myself.

Offline

 

#5 2008-01-26 09:46:39

mig
Member
From: Seattle, WA
Registered: 2006-12-21
Posts: 532

Re: Automated UPS shutdown - well - sort of

fordem - in case you didn't see this, there is a post on the D-Link "beta"
Forum http://forums.dlink.com/index.php?topic … 20#msg4620
which describes another way to remotely invoke shutdown using the following
code technique to call the shutdown web page directly.

Code:

DNS_323IP=192.168.1.193
/usr/bin/GET http://$DNS_323IP/goform/sysShutDown 2>&1

Last edited by mig (2008-01-26 09:47:09)


DNS-323 • 2x Seagate Barracuda ES 7200.10 ST3250620NS 250GB SATAII (3.0Gb/s) 7200RPM 16MB • RAID1 • FW1.03 • ext2 
Fonz's v0.3 fun_plug http://www.inreto.de/dns323/fun-plug

Offline

 

#6 2008-01-26 10:59:07

jayas
Member
Registered: 2008-01-24
Posts: 151

Re: Automated UPS shutdown - well - sort of

Looks like *anyone* on the network can shutdown the DNS-323 without being authenticated?


H/W=B1 F/W=1.04; RAID1: SAMSUNG HD501LJ T166 (500GB, SATA 3.0Gb/s 16MB)

Offline

 

#7 2008-01-26 14:34:37

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

Re: Automated UPS shutdown - well - sort of

jayas

1)  Using the telnet method you can secure the telnet and that way control who can shut the box down - you will of course have to modify the script to include the authentication.

2)  Is that such a big problem?  Given the intended application of the device - SOHO - the majority of environments will operate with minimal security anyway - situations where, just as an example, everyone has administrator level access and/or everyone knows everyone else's password.

mig - Thanks, I didn't check the chance to visit that board yesterday so I missed that.

Offline

 

#8 2008-01-26 15:29:17

jayas
Member
Registered: 2008-01-24
Posts: 151

Re: Automated UPS shutdown - well - sort of

Hi Fordem,

I am planning on deploying these boxes in schools and as such I would not if activities like shutting down or rebooting cannot be restricted to those with administrator privileges.

I have been using Maxtor NAS for years works quite nicely with better user/group interface than the what DNS-323 web interface provide at the moment.  I wanted to migrate to DNS-323 for its raid 1 capability.

While 1.03 firmware is not really up to scratch, and neither is D-LINK technical support here in Austalia,  what is useful for me is that the fun_plug interface allows me to lock down the box with 1.04 beta restricted to only SAMBA and all other interfaces including telnet/web turned off.

Kind regards,

Jaya


H/W=B1 F/W=1.04; RAID1: SAMSUNG HD501LJ T166 (500GB, SATA 3.0Gb/s 16MB)

Offline

 

#9 2008-01-27 04:06:01

Gambit
Member
Registered: 2008-01-05
Posts: 10

Re: Automated UPS shutdown - well - sort of

fordem wrote:

I'm not certain that I understand that "dismounting things in Windows".

The way I see it - Windows is not actually involved here - apart from being the platform through which the commands are channelled, and that telnet session could have come from any other device or OS - if you think it makes a difference I can boot Ubuntu or similar and try them there.

I'm refering to when Windows actually flushes all it's data back to the remote disk.  Think about the problems you have unplugging USB drives if you still have windows open, etc.  The reason I suggest the delay is that when you actually do have a power failure moment, the active user may have files open to the remote DNS drive.  You want those to flush to disk before shutting the DNS down, hence waiting long enough for the windows box to clear out before dropping the DNS.

fordem wrote:

For what it's worth LANSafe does have a linux/unix version - but I've never gotten it to work (on a x86 system) - there is some sort of a problem with the install scripts, and PowerWare's tech support have not been particularly helpful here - my UPS also does not have a USB connection, it's one of the older serial communication units.

Heh.  I hope you've recycled the battery recently :)

fordem wrote:

Shutting the DNS-323 down after the Windows system would require some sort of a script running on the DNS-323 to create a time delay after being called by the Windows box, I suppose I could do it, but the question is do I really need to?  According to another thread here - the "touch /tmp/shutdown" process possibly includes a "sataumount" command, that appears to dismount the drives (running it from the CLI causes the shares to become unavailable) but I'm not sufficently "linuxsmart" to be able to decide for myself.

Both 'halt' and 'poweroff' offer a delay option.  Also, a little script like "sleep 300; touch /tmp/shutdown;" called via nohup "nohup delayshutdown.sh>/dev/null 2>&1" would do the same thing.  There's lots of more/less complicated ways of doing that as well.

I would definitely want the DNS box to be shutdown well after the Windows box has cleaned up it's caches and the user has had a chance to save any pending documents.

Cheers,
--G

Offline

 

#10 2008-01-27 05:00:54

jayas
Member
Registered: 2008-01-24
Posts: 151

Re: Automated UPS shutdown - well - sort of

Gambit wrote:

I would definitely want the DNS box to be shutdown well after the Windows box has cleaned up it's caches and the user has had a chance to save any pending documents.

Here is one solution I can think off-hand.  Install fun_plug that will start a cron job which will wake up every minute and look for a file "shutdown" in the root directory of the first drive.

When the cron job detects this file it deletes it and the executes your shutdown sequence.

This way, the shutdown of the DNS-323 is controlled by your Windows servers.   I presume when the Windows server receives message from UPS, it does "shutdown -l" first, then cleanup, followed by creating the empty file "shutdown" in DNS-323 volume.

Jaya


H/W=B1 F/W=1.04; RAID1: SAMSUNG HD501LJ T166 (500GB, SATA 3.0Gb/s 16MB)

Offline

 

#11 2008-01-27 16:45:14

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

Re: Automated UPS shutdown - well - sort of

Thanks Gambit, I've added that to my script to delay the shutdown of the DNS-323 so that it occurs after the Windows server shuts itself down - I've initally set it to sleep for 120 seconds, and I'll do some trial & error runs to get the actual timing correct - I've also removed the last wait and send commands from the script since that would have the Windows server waiting for a response from the DNS-323.

As regards the UPS battery - it's no more than a year old - and since we average one maybe two outages a day here, it's known to be in good shape.

jayas - Why would you create a cron job to look for a file and shutdown the UPS when there is already a similar task running?  Creating an empty file called shutdown in /tmp triggers the shutdown - from my limited understanding of this device, that's how it's done from the front panel button.

Last edited by fordem (2008-01-27 16:49:56)

Offline

 

#12 2008-01-28 01:37:29

jayas
Member
Registered: 2008-01-24
Posts: 151

Re: Automated UPS shutdown - well - sort of

Hi Fordem,

fordem wrote:

jayas - Why would you create a cron job to look for a file and shutdown the UPS when there is already a similar task running?  Creating an empty file called shutdown in /tmp triggers the shutdown - from my limited understanding of this device, that's how it's done from the front panel button.

Sorry I was too brief.  I was referring to the situation where you have (say) Windows servers and DNS box on UPS, and the Windows servers can receive messages from UPS of power failure, and that you want to gracefully shutdown the DNS (and servevers) while UPS has juice.

In this case, it would be convenient to have a means by which the Windows server can shutdown the DNS equivalent to someone going to the DNS box and pushing holding the power button for five seconds.

The web interface is one way to do this, and the method I suggested is arguably simpler from the Windows server, but needs the extra script running on the DNS.  I run the DNS with web turned off (actually disabled) and thus the file method works nicely in this instance.

Regards,

Jaya


H/W=B1 F/W=1.04; RAID1: SAMSUNG HD501LJ T166 (500GB, SATA 3.0Gb/s 16MB)

Offline

 

#13 2008-01-28 04:05:40

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

Re: Automated UPS shutdown - well - sort of

jayas

I don't know if you've been following the thread, but it shouldn't be too hard to recognize that shutting the DNS-323 down from a Windows server under the control of a UPS is exactly what I'm doing - without using the web interface and without creating an additional script or cron job on the DNS-323 to do it.

Gambit's post was a suggestion to improve on my method by incorporating a delay which would ensure that any files held open by the Windows server would be closed before the DNS-323 shutdown.

Your method will cause the DNS-323 to shutdown within a matter of seconds of the Windows server creating the file - exactly the same situation that Gambit is suggesting a way around.

Last edited by fordem (2008-01-28 04:13:58)

Offline

 

#14 2008-01-28 05:02:25

jayas
Member
Registered: 2008-01-24
Posts: 151

Re: Automated UPS shutdown - well - sort of

Hi Fordem,

Essentially what I was suggesting was, if you like, an alternative approach which may be simpler as far as Windows box is concerned to initiate the shutdown by just dropping a file in the admin share.  It does not need web or telnet interface.

The server does this only after all its shares have been sync'ed and dismounted (by users logging off) etc, and the script on DNS does the right thing stopping SMB first, sync disks, etc and finally powering off on its own.

Jaya

PS: Enabling and disabling telnet to my DNS is simply a matter of creating or deleting the file 'telnet' in the admin share.  This (to me) has the benefit of controlling DNS box from any server without having to install anything on these servers.


H/W=B1 F/W=1.04; RAID1: SAMSUNG HD501LJ T166 (500GB, SATA 3.0Gb/s 16MB)

Offline

 

#15 2008-11-03 07:26:59

mealto
Member
Registered: 2008-02-02
Posts: 95

Re: Automated UPS shutdown - well - sort of

I have been trying to get the 323 to take a command and shut down during power outages. We know this works ONLY if you have been authenticated and have not been logged out of the admin console.

Accessing this via web browser: http://DNS-323 IP/goform/sysShutDown

These both seem to work (based on other feedback) in a linux environment:

wget -q -O /dev/null --user=user --password=password http://DNS323IP/goform/sysShutDown

How would we APC's PowerChute to run a command file to initiate a shutdown without authentication? Can anyone share batch file syntax that we can run in a .bat file? Any tips would be appreciated!

Running storck firmware (FW1.05) with no hacks.

Offline

 

#16 2008-11-03 08:56:06

Dlink
Member
Registered: 2007-11-21
Posts: 106

Re: Automated UPS shutdown - well - sort of

mealto wrote:

I have been trying to get the 323 to take a command and shut down during power outages. We know this works ONLY if you have been authenticated and have not been logged out of the admin console.

Accessing this via web browser: http://DNS-323 IP/goform/sysShutDown

These both seem to work (based on other feedback) in a linux environment:

wget -q -O /dev/null --user=user --password=password http://DNS323IP/goform/sysShutDown

How would we APC's PowerChute to run a command file to initiate a shutdown without authentication? Can anyone share batch file syntax that we can run in a .bat file? Any tips would be appreciated!

Running storck firmware (FW1.05) with no hacks.

1.06 Adds UPS support if your willing to wait smile.

Offline

 

#17 2008-11-03 10:13:48

mealto
Member
Registered: 2008-02-02
Posts: 95

Re: Automated UPS shutdown - well - sort of

I can wait but in the meantime, there has got to be a way to send a shutdown signal to the 323 from the UPS's control panel. I even tried going in directly like so:

http://DNSIP/goform/formLogin?f_LOGIN_NAME=user&f_LOGIN_PASSWD=pw


Typing it directly in IE7, it works to authenticate but running a .bat file using "start iexplore" does not work! So frustrating. Is there no simple way?

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB