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-08-13 20:21:25

noodle
Member
Registered: 2007-07-13
Posts: 62

Safe shutdown and NUT.

Hi All,

I have a question regarding to safe shutdown. I tried to use some idea from fonz fsck package to unload processes, and remount /mnt/HD_* to read only. And I have installed fonz 0.5 fun_plug on a USB, which mount as /mnt/sys. I can remount /mnt/HD_* as read only, however, when I remount /mnt/sys as read only, I got device is busy. probably because my shutdown script located on /mnt/sys/ffp/sbin/? Anybody has idea? Fonz?

BTW, I found that nut tutorial on wiki page is some kind of misleading on some step, for example: create user doesn't always mean create system user (For example: monuser, winmonuser), those are user in NUT only. Also missing step on how to change the permission on USB device. So you probably get upshid not found error then you launch upsdrvctrl.

Fonz, I found that libhid installed some hotplug script under /ffp/etc/hotplug/usb, however, DNS-323 is not using this hotplug, it using /etc/hotplug instead, So basically, its not working. It will not change the permission on usb device. That make it hard to use any user other than "root" for upsdrvctrl and upsd process. You probably expecting to use "root" to run them? How can we make this hotplug work in DNS-323?

Thanks for any advice.

Noodle

Offline

 

#2 2008-08-13 21:15:31

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

Re: Safe shutdown and NUT.

noodle wrote:

Hi

Hi Noodle,

I don't have a UPS myself. Because there was interest, I compiled the nut package. The wiki page was created by rcblackwell. As far as I understand him, he's still pretty new to Linux. So if you can help improve the wiki page, go ahead. I'm sure rcblackwell appreciates it. Also, I welcome (specific) suggestions how to improve the package. So far, I plan to include the start script from the wiki page. Regarding the hotplug stuff: ffp packages can not install files outside of /ffp. So if the hotplug stuff must be in /etc, you might want to extend the start script to create symbolic links.

Regarding read-only remount of your /mnt/sys: Open files are not a problem, unless they opened for writing. After you stopped everything in /ffp/start, there should be nothing left that writes to a file. Maybe you have a fanscript running that writes a log?

Offline

 

#3 2008-08-13 23:36:37

noodle
Member
Registered: 2007-07-13
Posts: 62

Re: Safe shutdown and NUT.

Hi Fonz

Thanks for reply.

Yes, I have fan script, but I changed fan script to not write the log. I'm will do more investigate on it. And probably provide more detail information on how to make nut better.

Thanks again.

Noodle

Offline

 

#4 2008-08-14 14:11:37

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

fonz wrote:

noodle wrote:

The wiki page was created by rcblackwell. As far as I understand him, he's still pretty new to Linux. So if you can help improve the wiki page, go ahead. I'm sure rcblackwell appreciates it.

noodle/fonz,

I am a new comer to Linux and would appreicate any assistance that could be offered during build of the wiki pages.


Bob Blackwell
Pickering, ON

Offline

 

#5 2008-08-14 14:25:40

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

noodle wrote:

I found that nut tutorial on wiki page is some kind of misleading on some step, for example: create user doesn't always mean create system user (For example: monuser, winmonuser), those are user in NUT only. Also missing step on how to change the permission on USB device. So you probably get upshid not found error then you launch upsdrvctrl.

Noodle,

I am a Linux newbie and appreciate all the help I can get.

Please keep in mind that the wiki page is not complete. There's a statement in bold text indicating where I've stopped.

From instruction found at http://networkupstools.org/doc/2.2.0/INSTALL.html I understood it was necessary to create a user, in this case monuser, in order for the monitoring tool (upsmon) to connect to the driver. Please advise if this isn't necessary. The winmonuser was created to allow access to nut from my Windows Vista PC. Again, if this user didn't need to be created, please advise.

I've been unable to determine how to change ownsership on the USB port thus when I attempt to run nut as anything other than root (ie; nut -u ups) I'm presented with an error; No matching HID UPS found. Please refer to message #15 in the post found at http://dns323.kood.org/forum/t2623-suport-this.html for additional detail on the steps I've taken while attempting to resolve this issue.

Any help you  can offer with respect to creation of users and specifically on setting rights on the USB port would be appreciated.

Last edited by rcblackwell (2008-08-14 14:25:55)


Bob Blackwell
Pickering, ON

Offline

 

#6 2008-08-14 14:32:27

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

Re: Safe shutdown and NUT.

rcblackwell wrote:

when I attempt to run nut as anything other than root (ie; nut -u ups) I'm presented with an error; No matching HID UPS found.

Getting the user and permission issues right is important, but not as important as for real multi-user systems exposed to the bad bad Internet. If it works as root, it's a great start.

Offline

 

#7 2008-08-14 22:26:38

noodle
Member
Registered: 2007-07-13
Posts: 62

Re: Safe shutdown and NUT.

rcblackwell wrote:

Noodle,

I am a Linux newbie and appreciate all the help I can get.

Please keep in mind that the wiki page is not complete. There's a statement in bold text indicating where I've stopped.

From instruction found at http://networkupstools.org/doc/2.2.0/INSTALL.html I understood it was necessary to create a user, in this case monuser, in order for the monitoring tool (upsmon) to connect to the driver. Please advise if this isn't necessary. The winmonuser was created to allow access to nut from my Windows Vista PC. Again, if this user didn't need to be created, please advise.

I've been unable to determine how to change ownsership on the USB port thus when I attempt to run nut as anything other than root (ie; nut -u ups) I'm presented with an error; No matching HID UPS found. Please refer to message #15 in the post found at http://dns323.kood.org/forum/t2623-suport-this.html for additional detail on the steps I've taken while attempting to resolve this issue.

Any help you  can offer with respect to creation of users and specifically on setting rights on the USB port would be appreciated.

Hi rcblackwell

Actually, I'm kind of newbie in Linux too.

Yes, you need to create user for monuser and winmonuser, but those are NUT user which be created in "upsd.users" file, not system user account.

"upsmon" run into two process, one process will be system account "root" to issue shutdown command and so on. Another process used to communicate with "upsd" can run as system account "nutmon". So you only need to create system account "nutmon".
And "upsmon" and "winmonuser"  are NUT user that been used to communicate with "upsd". They need to match with the users defined in "upsd.users".

For example: in upsmon.conf
# This is the system account that upsmon process run as. So you need to have a system account "nutmon"
RUN_AS_USER nutmon

# This is the NUT account that upsmon used to communicate with "upsd"
# need to defined in "upsd.users"
MONITOR MY_UPS@localhost 1 monuser <password> master


About permission, it's going to be hard when you use USB, because everytime, you unplug/replug USB device, the device file will change. That's why we need hotplug to modify the permission on USB device.

You can figure out which USB device is your UPS by look at "/proc/bus/usb/devices", it will list all usb devices that connect to your system. Looking for your UPS model number, vender name, to find Dev#
In my system:
T:  Bus=01 Lev=02 Prnt=02 Port=01 Cnt=02 Dev#=  4 Spd=1.5 MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=051d ProdID=0002 Rev= 1.06
S:  Manufacturer=APC
S:  Product=Back-UPS ES 350 FW:823.B1.D USB FW:B1
S:  SerialNumber=3B0717X09302 
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbfs
E:  Ad=81(I) Atr=03(Int.) MxPS=   6 Ivl=10ms

so, dev# is 4, then the USB device for UPS should be: /proc/bus/usb/001/004.

And I agree with fonz, it's just a small device, so run everything under "root" is not that bad.

Offline

 

#8 2008-08-15 00:54:44

noodle
Member
Registered: 2007-07-13
Posts: 62

Re: Safe shutdown and NUT.

Found the reason why I cannot mount it as read only. I'm using file on USB driver for swap. I need to turn remove swap from /proc/swaps in order to mount it as read only.

Offline

 

#9 2008-08-15 02:52:25

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

noodle wrote:

.... you need to create user for monuser and winmonuser, but those are NUT user which be created in "upsd.users" file, not system user account.

"upsmon" run into two process, one process will be system account "root" to issue shutdown command and so on. Another process used to communicate with "upsd" can run as system account "nutmon". So you only need to create system account "nutmon".
And "upsmon" and "winmonuser"  are NUT user that been used to communicate with "upsd". They need to match with the users defined in "upsd.users".

For example: in upsmon.conf
# This is the system account that upsmon process run as. So you need to have a system account "nutmon"
RUN_AS_USER nutmon

# This is the NUT account that upsmon used to communicate with "upsd"
# need to defined in "upsd.users"
MONITOR MY_UPS@localhost 1 monuser <password> master

noodle,

Your explanation has been very helpful. From your description I see that I'll need to remove some unnecessary users ID's from the DNS323 and update the wiki pages accordingly.


noodle wrote:

About permission, it's going to be hard when you use USB, because everytime, you unplug/replug USB device, the device file will change. That's why we need hotplug to modify the permission on USB device.

This is something that I'm not capable of doing thus since running as root is an acceptable alternative I'll configure nut in that way.


Bob Blackwell
Pickering, ON

Offline

 

#10 2008-08-15 02:57:04

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

noodle wrote:

Found the reason why I cannot mount it as read only. I'm using file on USB driver for swap. I need to turn remove swap from /proc/swaps in order to mount it as read only.

Your post got me thinking about how the USB drive on my NAS is unmounted at shutdown. I'm using the cleanboot script and assumed nut calls cleanboot's shutdown function, which I believe unmount's the USB drive prior to shutdown.

Are you using cleanboot to shutdown your system or have you written a script? If the later, would be willing to share and advise on how it would integrate with cleanboot.

Last edited by rcblackwell (2008-08-15 02:57:42)


Bob Blackwell
Pickering, ON

Offline

 

#11 2008-08-15 03:18:46

noodle
Member
Registered: 2007-07-13
Posts: 62

Re: Safe shutdown and NUT.

rcblackwell wrote:

Your post got me thinking about how the USB drive on my NAS is unmounted at shutdown. I'm using the cleanboot script and assumed nut calls cleanboot's shutdown function, which I believe unmount's the USB drive prior to shutdown.

Are you using cleanboot to shutdown your system or have you written a script? If the later, would be willing to share and advise on how it would integrate with cleanboot.

I'm using my own shutdown script, and I shamelessly steal some idea from fonz fsck script.

If you are using swap file on your USB drive, I'm sure cleanboot will not unmount /remount it as read only correctly. Basically, I'm thinking it's wrong to use file on USB driver as swap, I should create a swap partition for that purpose. Because if swap already been used, we may make system into a unstable stage when we switch the swap. But swap partition don't need to unmount clearly.

NUT using /sbin/shutdown to shutdown the system, /sbin/shutdown widely available in regular Linux, but not in DNS-323. So shutdown command in upsmon.conf will not work. You had to provide your own shutdown script.

/ffp/sbin/shutdown.sh

Code:

#!/ffp/bin/bash
export PATH=/ffp/sbin:/ffp/bin:/usr/sbin:/sbin:/usr/bin:/bin

unset LD_LIBRARY_PATH

reverse_list()
{
    _list=
    while [ $# -gt 0 ]; do
        _list="$1 $_list"
        shift
    done
    echo $_list
}

# move to ramdisk and detach
cd /tmp
exec >/dev/console 2>&1 </dev/null
trap 'echo HUP' HUP

# stop ffp 
if [ -d /ffp/start ]; then
    files=$(reverse_list $(rcorder /ffp/start/*.sh))
    for f in $files; do
        if [ -x "$f" ]; then
                echo "$f stop"
            $f stop
        fi
    done
fi

# shutdown samba
killall -TERM smbd
killall -TERM nmbd
sleep 2
killall -KILL smbd
killall -KILL nmbd
sleep 1

# remount filesystems read-only
sync
for f in /mnt/HD_*; do
    mount -o remount -r $f
done
# My USB mount at /mnt/sys, so this is specific to my environment
mount -o remount -r /mnt/sys
mount -o remount -r -a
mount

sleep 2

if [ -f /ffp/etc/killpower ]; then
    echo "Killing the power. bye!"
    upsdrvctl -u ups shutdown

    sleep 120
else
    dns323-poweroff
fi

BTW, my switch swap script under /ffp/start, so it's going to remove swap on USB when it stop ffp.

Last edited by noodle (2008-08-17 06:08:46)

Offline

 

#12 2008-08-15 09:06:28

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

Re: Safe shutdown and NUT.

noodle wrote:

Code:

#!/bin/sh
...
trap 'echo HUP' HUP

Won't work with /bin/sh, afaict it needs /ffp/bin/bash.

Offline

 

#13 2008-08-17 03:50:44

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

noodle wrote:

BTW, I found that nut tutorial on wiki page is some kind of misleading

noodle,

With exception of startup and shutdown scripts the wiki page is complete. See http://dns323.kood.org/howto:nut_ups and let me know what you think.


Bob Blackwell
Pickering, ON

Offline

 

#14 2008-08-17 16:40:19

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

rcblackwell wrote:

With exception of startup .... scripts ....

A NUT startup script is attached. It's contents have also been added to the wiki.

(Script has been modified to correct error pointed out by fonz in next message.)

Last edited by rcblackwell (2008-08-17 18:45:47)


Attachments:
Attachment Icon nut.sh, Size: 526 bytes, Downloads: 311

Bob Blackwell
Pickering, ON

Offline

 

#15 2008-08-17 16:57:46

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

Re: Safe shutdown and NUT.

rcblackwell wrote:

rcblackwell wrote:

With exception of startup .... scripts ....

A NUT startup script is attached. It's contents have also been added to the wiki.

You're getting very good at linux very quickly. I made a small change to the start script on the wiki: it's PROVIDE, not PROVIDES in the start scripts.

Offline

 

#16 2008-08-17 18:44:10

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

fonz wrote:

rcblackwell wrote:

rcblackwell wrote:

With exception of startup .... scripts ....

A NUT startup script is attached. It's contents have also been added to the wiki.

You're getting very good at linux very quickly. I made a small change to the start script on the wiki: it's PROVIDE, not PROVIDES in the start scripts.

Thanks fonz,

If I understand you correctly then I'd have to say the cleanboot.sh script associated with forum message #6 at http://dns323.kood.org/forum/t2346-smal … nboot.html would also be incorrect.

The script starts out with;

#!/ffp/bin/sh

# PROVIDES: cleanboot
# BEFORE: LOGIN


Bob Blackwell
Pickering, ON

Offline

 

#17 2008-08-17 20:34:19

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

Re: Safe shutdown and NUT.

rcblackwell wrote:

If I understand you correctly then I'd have to say the cleanboot.sh script associated with forum message #6 at http://dns323.kood.org/forum/t2346-smal … nboot.html would also be incorrect.

# PROVIDES: cleanboot

Yes. But it's usually no problem as long as there are no dependencies. You can always check the order of execution with a simple 'rcorder /ffp/start/*.sh'.

Offline

 

#18 2008-08-22 23:51:50

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: Safe shutdown and NUT.

noodle wrote:

.................. You had to provide your own shutdown script.

Code:

# move to ramdisk and detach
cd /tmp
exec >/dev/console 2>&1 </dev/null
trap 'echo HUP' HUP

Al little clarity on this segment of the script would be appreciated. Am I correct in stating that what's being moved to ramdisk is the "environment" that this script is running in and that doing so is necessary so that when KILL is issued later in the script, the script will not fail as it has been moved to ramdisk?

Why am I asking? I'd like to understand what we're "detaching" from. Is it the environment as described above or a Telnet session that is being used to run the script?


Bob Blackwell
Pickering, ON

Offline

 

#19 2010-02-14 22:22:06

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

Re: Safe shutdown and NUT.

Thanks for the tutorial on NUT!

I attemped to follow it however there is a new version of NUT around and a few of the config items have changed.  No big deal however I ran into this issue with fw1.07.  I was seemingly unable to stop the firmware's UPS usb driver control and was definitely NOT able to start up driver control for running the new version of nut...

Despite having the exact name ups.conf as comes with 1.07fw I could not load the driver for the new version of nut I was trying to install. 

I attempted to run nut.sh to see if I was doing something wrong in disabling the fw's NUT but it gave the same error, seemingly unable to stop the drivercontrol from the FW.

As a poor second place, anyone have an idea where the 1.07fw would be hiding upsmon.conf? At least I guess I could copy over a new version each bootup like I have been doing to replace my samba config?  Or maybe not?

*** 1.07fw sees my UPS and appears to monitor it from the default web interface

Last edited by caust1c (2010-02-14 22:23:13)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB