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 2007-03-25 19:51:10

nicko
Member
Registered: 2007-03-17
Posts: 45

Shutting DNS down by remote control?

I've just added a UPS to my main server, and the DNS is now on that too... I've installed APC PowerChute Business edition on the server and the UPS is happily talking to that over USB - this means that the server will do a controlled shutdown should the power & UPS fail...

Is there a way to shut the DNS down as part of an APC Smart UPS or similar shutdown?

Thanks

Nick

Offline

 

#2 2007-03-26 08:26:37

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

Re: Shutting DNS down by remote control?

Apcupsd is a program for monitoring UPSes and performing a graceful computer shutdown in the event of a power failure. It runs on Linux, Tru64, Mac OS/X, Win32, Solaris as well as other OSes. http://www.apcupsd.org  This software can do exactly what you want, if you can run apcupsd on the machine that has the UPS connected and the DNS-323

From the apcupsd manual:

NIS (Network Information Server) mode allows for communication between instances of apcupsd running on different hosts. Only one of those hosts, the server, needs to talk to the UPS directly. The others, clients, optain information about the state of the UPS by querying the server. NIS is not related to Sun's NIS/YP services.

Now for the more difficult part (at least for me) the apcupsd source need to be compiled for the DNS-323's arm / uclibc execution environment.  There are several members of this forum which have the development environment setup to cross-compile for the DNS-323 (KRH, fonz and tobyg come to mind), perhaps one of them could try to compile the apcupsd sources and post the compiled binaries.

Ideally, I would like to connect my APC UPS directly to my DNS-323 (via USB) cable.  However, there are several modules which are missing in the stock kernel that will prevent USB to UPS communications.

From the apcupsd manual:

On Linux-2.6.x, make sure the sysfs filesystem is mounted on /sys and do:

     ls -l /sys/bus/usb/drivers/

...where you should get:

     total 0
     drwxr-xr-x    2 root     root            0 May  1 18:55 hid
     drwxr-xr-x    2 root     root            0 May  1 18:55 hiddev
     drwxr-xr-x    2 root     root            0 May  1 18:55 hub
     drwxr-xr-x    2 root     root            0 May  1 18:55 usb
     drwxr-xr-x    2 root     root            0 May  1 18:55 usbfs

...or perhaps something like:

     total 0
     drwxr-xr-x  2 root root 0 Jan  6 15:27 hiddev
     drwxr-xr-x  2 root root 0 Jan  6 15:28 hub
     drwxr-xr-x  2 root root 0 Jan  6 15:28 usb
     drwxr-xr-x  2 root root 0 Jan  6 15:27 usbfs
     drwxr-xr-x  2 root root 0 Jan  6 15:28 usbhid

If your 2.6.x system does not have the /sys/bus/usb directory, either you do not have sysfs mounted on /sys or the USB module(s) have not been loaded. (Check /proc/mounts to make sure sysfs is mounted.)

A USB UPS needs all of these drivers - the USB device filesystem, the USB hub, the Human Interface Device subsystem driver, and the Human Interface Device driver. If you are compiling your own kernel, you want to enable

     CONFIG_USB
     CONFIG_USB_HID
     CONFIG_USB_HIDDEV
     CONFIG_USB_DEVICEFS

...as well as at least one USB Host Controller Driver...

     CONFIG_USB_UHCI_HCD (linux-2.6.x)
     CONFIG_USB_OHCI_HCD (linux-2.6.x)
     CONFIG_USB_UHCI     (linux-2.4.x)
     CONFIG_USB_OHCI     (linux-2.4.x)

However there is hope for a new kernel which could support the UPS UPS modules and sysfs using fonz's reloader technique http://dns323.kood.org/forum/t347-Loader-DNS323.html

//Mig

Last edited by mig (2007-03-26 08:27:13)


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

 

#3 2007-03-26 10:44:08

nicko
Member
Registered: 2007-03-17
Posts: 45

Re: Shutting DNS down by remote control?

What I should have said was that this is a W2K system, so apcupsd is not an option - I'm using PowerChute Business Edition at the moment...

Nick

Offline

 

#4 2007-03-26 18:44:18

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

Re: Shutting DNS down by remote control?

Apcupsd is an option for your OS (win2K)... from the release notes:

Release Notes for Apcupsd 3.14.x

Apcupsd 3.14.x is the latest STABLE release, containing many bug fixes and
new features over the previous 3.12.x stable series. Users of all previous
versions are encouraged to upgrade.

IF YOU USE THE OLD STYLE MASTER/SLAVE NETWORKING MODE, BE SURE TO READ THE
RELEASE NOTES BELOW.


3.14.0 -- 09 February 2007

NEW FEATURES

  * USB support for 3 new platforms:

      - Windows (Win98SE, WinME, Win2000, Win2003 Server, WinXP)
      - Mac OS X (Darwin)
      - Solaris 10 (x86 and SPARC)

        Please see the Apcupsd manual for details on USB configuration for the
        new platforms.


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

 

#5 2007-03-27 16:06:46

nicko
Member
Registered: 2007-03-17
Posts: 45

Re: Shutting DNS down by remote control?

Unfortunatly I'm tied to using the APC Powerchute software on the XP box and I don't think that can co-exist with apcupsd.

However, if I use the http://www.inreto.de/dns323/ distribution, I get dropbear ssh. I can then use PuTTY to talk to the box, and plink root@dnssan1 "shutdown -h now &" or similar in the "command to execute before shutdown" field of the PowerChute actions...

Is this a sensible approach, oh DNS & Linux gurus?

Thanks

Nick

Offline

 

#6 2007-03-27 16:23:38

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: Shutting DNS down by remote control?

nicko wrote:

However, if I use the http://www.inreto.de/dns323/ distribution, I get dropbear ssh. I can then use PuTTY to talk to the box, and plink root@dnssan1 "shutdown -h now &" or similar in the "command to execute before shutdown" field of the PowerChute actions...

Is this a sensible approach, oh DNS & Linux gurus?

Be careful with my fun_plug, Gonzo reported that it killed his samba config, and I haven't got any feedback from others yet. The dropbear ssh doesn't depend on my fun_plug, so it should work with any fun_plug (though you need to modify the paths in dropbear-start.sh).

If you have dropbear running, shutting down via ssh like you proposed should work. I recommend using public-key authentication, so you don't have to type passwords (typing passwords is more difficult to automate). You could also use telnet, if security is not an issue.

Offline

 

#7 2007-03-27 17:48:53

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

Re: Shutting DNS down by remote control?

nicko wrote:

Unfortunatly I'm tied to using the APC Powerchute software on the XP box and I don't think that can co-exist with apcupsd.

Nick, I think you are right apcupsd an APC Powerchute can't co-exist on the same box, at least both programs can't be monitoring the same UPS.  If you implement fonz's dropbear you could do the remote shutdown with ssh.  Ssh creates it's configuration files under the 'home' directory of the user in a folder called ".ssh" (I assume dropbear does the same) on the DNS the /home directories are in RAM, so you will have to link /home/root/.ssh to a folder on the hard drive /mnt/HD_a2/<some folder> and have your fun_plug script recreate (copy a saved version of the files from the hard drive) the files in root's ~/.ssh

This brings up an aspect about the DNS I am struggling to understand.  What is the right command to shutdown the DNS-323.  I have always used the web gui, but still can't figure out how the web gui shuts down the system?  There is no /sbin/shutdown and the stock busybox has a 'poweroff' and a 'reboot' implemented, with links in /sbin.    The GoAhead webserver executable '/web/webs' has several entries for shutdown

# strings /web/webs | grep -i shutdown
shutdown
sysShutDown
touch /tmp/shutdown
web/tools/shutdown.asp
SSL_shutdown
protocol is shutdown

It also has several entries for DSM-600 (shared code base for D-Link I guess?), so it is unclear which of the "shutdown" entries apply to the DNS-323.

To me the DNS-323 seems to shutdown very quickly.  If you have a serial cables connected, is there any output generated when the web gui shutdown is issued that might give a clue as to what commands the DNS-323 is running?

//Mig


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

 

#8 2007-03-27 21:19:37

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: Shutting DNS down by remote control?

"poweroff" doesn't power off here, but only halts with a message on the serial. When using the web interface, it powers off with only a few messages from md. touching /tmp/shutdown seems to do exactly the same, so I guess the web interfaces uses this method. I suspect that chkbutton is involved in some way... (it contains a "/tmp/shutdown" string and it calls fopen(.. "r") on it) see also http://forum.source.pri.ee/t164-chkbutt … -leds.html

Last edited by fonz (2007-03-27 21:54:46)

Offline

 

#9 2007-03-28 09:53:05

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

Re: Shutting DNS down by remote control?

Wow, looks like # touch /tmp/shutdown  does power down the system (how strange?!) 
I think you would want the ssh command to run a script and to do something like:

sync; sync; sync;
<graceful? shutdown of processes>
umount /dev/<any-USB-devices>
raidstop /dev/md0
touch /tmp/shutdown

But I don't think the raid will stop, because dropbear is running off the raid. 
I think killing the power with the raid active is not a good idea, but I'm not sure if the D-Link software does this?


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

 

#10 2007-03-28 10:28:25

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: Shutting DNS down by remote control?

mig wrote:

I think killing the power with the raid active is not a good idea, but I'm not sure if the D-Link software does this?

I did a bit of debugging yesterday evening, looking at chkbutton. chkbutton tests every 2 seconds whether a number of files exist, one of the files is "/tmp/shutdown". If it exists, it will power off. And before actually powering off (using an ioctl on fd 3), it does a lot of cleanup like e.g. killing any wget and ftpd, running "sync", "raidstop" (or "sataumount" if /tmp/raidup doesn't exist), "smb stop" and more. I have a quite detailed list at home that I can post tonight.

Last edited by fonz (2007-03-28 10:31:51)

Offline

 

#11 2007-03-28 22:59:25

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: Shutting DNS down by remote control?

It's an ioctl on the network interface egiga0 that they use to power off the box. I've written a small program that does only this ioctl (source and binary available at http://www.inreto.de/dns323/utils/). This ioctl interface seems also to control other features (e.g. make the top led blink).

In chkbutton, I also found a number of commands that are run before power off.

First step deals with mounted partitions, I don't understand it completely yet:
mount | grep /sys/mtd1 > /tmp/mount.log
chkbutton then opens /tmp/mount.log and iterates over the lines. Not sure, what it's
doing exactly (it's the code starting at 0x9898 in chkbutton). At the end of the function,
umount /sys/mtd1
is run. At least /proc will be gone when this first function returns (making debugging more tricky).

In a second step (function starting at 0xa200), the following commands are run (using the system() function):
kill -9 `pidof wget` 2 > /dev/null
kill -9 `pidof smbclient` 2 > /dev/null
kill -9 `pidof ftpd` 2>/dev/null
kill -9 `pidof prescan` 2>/dev/null
kill -9 `pidof upnp` 2>/dev/null
kill -9 `pidof mt-daapd` 2>/dev/null
smb stop

Then, if /tmp/raidup exists:
raidstop md0 md1 f
or
/etc/hotplug/sataumount
if it does not exist.

The third step is the function starting at 0xa9cc, which does three ioctls. The first is write,
making the led blink. The second is a read (no idea). The third ioctl powers off.

(edit: updated link to new location of utils package)

Last edited by fonz (2007-05-25 17:14:36)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB