Buffalo NAS-Central Forums

Welcome to the Linkstation Wiki community
It is currently Mon Aug 20, 2018 7:27 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Overriding the shutdown
PostPosted: Fri Mar 18, 2011 10:04 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
EDIT: The completed working way to do this is explained here - you can ignore the rest of this thread!

This is probably a horrible way of doing it, but it took me quite a while to work out and I thought I'd share it in case anyone else want to use this technique. You need root access via ssh and I would not advise doing it unless you have previous linux experience.

Basically, I wanted to be able to wake my linkstation up whenever I want to use it or download a torrent and have it stay on until 8am on weekdays when it will shutdown until it is woken up again. This combination of things cannot be done with the stock settings.

Few basics before I start: any scripts put inside the /etc/init.d folder will be run at startup. Cron is the lnux version of scheduled tasks to run commands at specified intervals. Wake-on-lan is a special packet of data sent over a network to wake-up a computer - it has to be send to port 9 for it to work on the linkstation.

Firstly I discovered that the linkstation will ignore a wake-on-lan signal unless it's on auto-made. So I had to use auto-mode. Problem is, it shuts down after a while if there is not a PC sending a Wake-On-LAN signal. I didn't want this so I found out that there are two processes running when the box is in auto mode that are not in normal mode:-
Code:
/usr/local/sbin/pwrmgr -bdm -l /etc/pwrmgr/pclist -p 9 -p 2304
/bin/bash2 /usr/local/sbin/pmcd_exec.sh start


I created a new sh file in the folder /etc/init.d to run on startup and keep the box alive:-
Code:
#!/bin/bash

sleep 10
killall pwrmgr
killall pmcd_exec.sh


The sleep makes it wait for 10 seconds before running to make sure the processes have already started.

So now the box powers on when I send a wake-on-land and stays on.

The next step was to make it shutdown when I wanted it to (on weekdays at 08:00). The built-in scheduler doesn't work in auto-mode, but the way I do it shouldn't be run if you have backups running or torrents downloading.

Use the command
Code:
crontab -e
and it loads up the cron listings. Then I added the line below.
Code:
00 07 * * 1,2,3,4,5 /usr/local/sbin/pwrmgr -u


pwrmgr -u is the only way I found to get the linkstation to shutdown and stay shutdown. Normally you would use shutdown or poweroff in linux, but they just restart the linkstation.


Last edited by SANGERA2 on Wed Jul 25, 2012 6:29 pm, edited 2 times in total.

Top
   
PostPosted: Sat Mar 19, 2011 7:18 am 
Offline
Moderator

Joined: Fri Jun 29, 2007 10:39 am
Posts: 2604
You made the right step into the right direction
and then you turned 90 degrees and went the
wrong way. ;)
If you had examined the script pmcd_exec.sh, you
would have found the following line:
Code:
pwrmgr -c localhost act

This line keeps the box alive without any possible
trouble. You do not need to kill the pwrmgr process
or anything else.
Just call this line once within 3 minutes and the box
will stay alive in auto mode even without a client
sending WoL packets.
So a small script sending this line once every 3 minutes
until 8am on a weekday would have solved the problem
in a clean "Buffalo" like way. You then just have to start
this script whenever you need your box to stay on until
8am.
Another way to keep the box alive, which can also be
found in the script you spoted, is to create a file named
"/var/lock/zero_filling".
As long as this file exists, the box will stay alive.

The best solution (imho) would be to add the pwrmgr line
into the script you use to download your torrents as the
last line to execute when finished the download. The same
should be done in every other script you use to do stuff on
the box, you need the box to stay alive for.
Then you can just start the scripts and be sure that whichever
of them finishes last, will keep the box alive until then.

[Update]
I made a small page in the wiki for this:
http://buffalo.nas-central.org/wiki/Left_overs_for_%27X%27_and_%27V%27_series

_________________
Please do not use private mail (PN/M) to ask questions. Use the proper forum instead. (me)

If there is no verified backup of a dataset, the dataset, by definition, is unimportant. (c't 2012)

RAID (no matter which level) never ever substitutes a backup. (me)


Top
   
PostPosted: Sun Mar 20, 2011 8:49 am 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
kenatonline wrote:
You made the right step into the right direction
and then you turned 90 degrees and went the
wrong way. ;)

[Update]
I made a small page in the wiki for this:
http://buffalo.nas-central.org/wiki/Left_overs_for_%27X%27_and_%27V%27_series

Your way is pretty good too and the guide on the wiki is easy to follow. I especially like the way that you explain what each process does. Thanks.

I just chose to do it my way because it saves as much resources and network traffic as possible and it's the simplest. I know that the box will never be downloading or using the disk etc at the time I tell the linkstation to shutdown so the checks for locks etc. It may not be best for everyone, but it works for me. It would be better to stop the processes running at all instead of killing them afterwards, but frankly I was too lazy! :)


Top
   
PostPosted: Sun Mar 20, 2011 8:55 am 
Offline
Moderator

Joined: Fri Jun 29, 2007 10:39 am
Posts: 2604
SANGERA2 wrote:
...
It would be better to stop the processes running at all instead of killing them afterwards, but frankly I was too lazy!
...

That's ok with me.
Your description was a nice motivation to have a deeper
look into the mechanism. I always wanted to do this but
never found the motivation before. ;-)

_________________
Please do not use private mail (PN/M) to ask questions. Use the proper forum instead. (me)

If there is no verified backup of a dataset, the dataset, by definition, is unimportant. (c't 2012)

RAID (no matter which level) never ever substitutes a backup. (me)


Top
   
PostPosted: Sun Mar 20, 2011 7:50 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
SANGERA2 wrote:
It would be better to stop the processes running at all instead of killing them afterwards, but frankly I was too lazy! :)

I'm not sure why, but putting my script into the /etc/init.d folder didn't make it run on startup. It was executable and worked fine when ran manually from the console. I tried doing u
Code:
pdate-rc.d kill_pwr.sh defaults
, but it didn't do a thing! I also tried making it fit the debian recommended layout of init.d scripts with start/stop etc, but it still didn't work.

Instead, I moved it into the /usr/sbin/ folder and created a link in the cronttab of
Code:
@reboot /usr/sbin/kill_pwr.sh


I thought this would fix it, but now I get the following in the cron log file in /var/log/cron:-
Code:
Mar 20 18:44:06 LinkStation crond[2158]: crond 1.7.0 started, log level 8
Mar 20 18:44:06 LinkStation crond[2158]: failed user root parsing @reboot /usr/sbin/kill_pwr.sh
Mar 20 18:44:10 LinkStation crond[2365]: crond 1.7.0 started, log level 8
Mar 20 18:44:10 LinkStation crond[2365]: failed user root parsing @reboot /usr/sbin/kill_pwr.sh
Mar 20 18:45:01 LinkStation crond[2365]: USER root pid 3358 cmd /etc/cron/cron.d/logrotate


I may have to give up now and use kenat's way! This is what irritates me about linux. Despite using it for years there are always things that don't work and I can find no way to work out how! :(


Top
   
PostPosted: Sun Mar 20, 2011 8:04 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
SANGERA2 wrote:
I may have to give up now and use kenat's way! This is what irritates me about linux. Despite using it for years there are always things that don't work and I can find no way to work out how! :(

I should add that I tried putting the full paths in the sh file so it has /bin/sleep instead of just sleep and it's still no go! :( The paths are right as it runs manually fine.


Top
   
PostPosted: Sun Mar 20, 2011 8:12 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
kenatonline wrote:
Code:
pwrmgr -c localhost act

This line keeps the box alive without any possible
trouble. You do not need to kill the pwrmgr process
or anything else.
Just call this line once within 3 minutes and the box
will stay alive in auto mode even without a client
sending WoL packets.

I have added the line below to crontab instead of my rubbish way of trying to kill the processes after they have loaded. It makes the box stay awake at 2 min intervals.
Code:
*/2 * * * * pwrmgr -c localhost act


It works! :)

Thank you very much kenat. I would probably just have given up when my startup AND cron tasks both didn't work!


Top
   
PostPosted: Mon Mar 21, 2011 7:21 am 
Offline
Moderator

Joined: Fri Jun 29, 2007 10:39 am
Posts: 2604
There is a "rule" for crontab scripts: ALWAYS load the profile before
doing anything.
Nearly all stock crontab implementations start a crontab entry WITHOUT
loading the profile of the user before. This is a task of the script author.
In addition to this, I do not know if, in the implementation Buffalo is using,
@reboot is a valid activation parameter.
Buffalo is using a initv version which is NOT automatically calling scripts
in /etc/init.d but only /etc/rc{X}.d (with X: 0-6).
Nevertheless, the right way to start ones own script is /etc/extensions.d.
Put a script with a name starting with "S" into this directory and it will get
started AFTER all Buffalo scripts needed for startup were started.

_________________
Please do not use private mail (PN/M) to ask questions. Use the proper forum instead. (me)

If there is no verified backup of a dataset, the dataset, by definition, is unimportant. (c't 2012)

RAID (no matter which level) never ever substitutes a backup. (me)


Top
   
PostPosted: Mon Mar 21, 2011 7:32 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
kenatonline wrote:
Nevertheless, the right way to start ones own script is /etc/extensions.d.
Put a script with a name starting with "S" into this directory and it will get
started AFTER all Buffalo scripts needed for startup were started.

This is a really useful bit of advice. Today I realised my box would not shutdown on the scheduled
Code:
pwrmgr -u
command. My idea of running
Code:
pwrmgr -c localhost act
every 2 mins meant that it wouldn't stay shutdown. It also seems like a resource hog. It definitely made a MASSIVE cron logfile! :o

I only want the box to come on when I send a wake-on-lan to it. It will not need to be on every weekday evening so I cannot try to keep it alive using cron. The best policy in my case is to kill pwrmgr and pmcd_exec or stop them from starting instead of trying to trick them into keeping the box alive as I don't know what time I will want the box on. Because I had so much trouble getting the script to run on startup I gave up on my way. After your advice on using
Code:
/etc/rc.d/extensions.d
(I'm quite pleased I get to correct you there!) :) I have managed to get my kill_pwr.sh script to work by putting a sym-link to it (using ln -s) in the folder you told me about. I called it S99_kill_pwr.sh and it works brilliantly.

I think the information on adding a script to the extensions.d folder may be very valuable information to add to the wiki as I bet I won't be the only person to try and get a script to run on startup by trying the various ways I did before giving up!

Anyway it seems to all work now. The script can be seen killing the two processes 30 seconds after startup if I ssh in quick. Also, the scheduled shutdown works and it stays off. When I send a wake-on-lan using either the batch file my torrent files are associated with or the shortcut on my desktop it turns the machine on and it stays on! Wow! I never thought I'd be so pleased by something so basic. It was simplicity itself with the windows XP machine I used to use as my torrent machine. :roll:

Thanks again. Hopefully this thread can now rest! :up:


Top
   
PostPosted: Wed Jul 25, 2012 1:14 pm 
Offline
Total Newbie

Joined: Wed Jul 25, 2012 12:57 pm
Posts: 2
step 1
create S99_kill_pwr.sh script
Code:
#!/bin/bash

sleep 10
killall pwrmgr
killall pmcd_exec.sh

under
Code:
/etc/rc.d/extensions.d


step 2
wake-on-lan Buffalo

step 3
shutdown Buffalo
Quote:
pwrmgr -u


AM I RIGHT?

Qustion is how to wake-on-lan Buffalo by IPAD?


Top
   
PostPosted: Wed Jul 25, 2012 1:47 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
miiol wrote:
step 1
create S99_kill_pwr.sh script
Code:
#!/bin/bash

sleep 10
killall pwrmgr
killall pmcd_exec.sh

under
Code:
/etc/rc.d/extensions.d


step 2
wake-on-lan Buffalo

step 3
shutdown Buffalo
Quote:
pwrmgr -u


AM I RIGHT?

Qustion is how to wake-on-lan Buffalo by IPAD?

Get a wake on lan program. There are loads. I use one on my android phone that works on my home wifi network.


Top
   
PostPosted: Wed Jul 25, 2012 2:35 pm 
Offline
Total Newbie

Joined: Wed Jul 25, 2012 12:57 pm
Posts: 2
SANGERA2 wrote:
Get a wake on lan program. There are loads. I use one on my android phone that works on my home wifi network.

Thank you!
And is it correct of above listed steps?


Top
   
PostPosted: Wed Jul 25, 2012 6:27 pm 
Offline
Newbie
User avatar

Joined: Thu Feb 24, 2011 9:59 am
Posts: 43
Location: Southampton, UK
In summary...

The switch on the back needs to be in the "auto" mode (top position).

My extensions.d folder looks like the below (I moved files out I didn't want starting):-
Code:
root@LinkStation:/etc/rc.d/extensions.d# ls
K05transmission.sh  K60_pocketu.sh      S40_flickrfs.sh
K40_twonky.sh       K60_sshd.sh         S40_lighttpd.sh
K40_webaxs.sh       K61_foolwatch.sh    S40_mysql.sh
K60_bittorrent.sh   K99_sxuptp.sh       S40_pocketu.sh
K60_eyefid.sh       S01_sxuptp.sh       S40_sshd.sh
K60_flickrfs.sh     S39_foolwatch.sh    S40_webaxs.sh
K60_lighttpd.sh     S40B_twonky.sh      S99_kill_pwr.sh
K60_mysql.sh        S40_eyefid.sh
root@LinkStation:/etc/rc.d/extensions.d#


My S99 script looks like (note the capital S):-
Code:
root@LinkStation:/etc/rc.d/extensions.d# cat S99_kill_pwr.sh
#!/bin/bash

  /bin/sleep 30
  /usr/bin/killall pwrmgr
  /usr/bin/killall pmcd_exec.sh
root@LinkStation:/etc/rc.d/extensions.d#




If you want the linkstation to turn off at a certain time use the command
Code:
crontab -e
and add the lines below (google crontab for an explanation of the times - don't ask me):-
Code:
18 07 * * 1,2,3,4,5 /usr/bin/kill_apps
20 07 * * 1,2,3,4,5 /usr/local/sbin/pwrmgr -u
18 12 * * 1,2,3,4,5 /usr/bin/kill_apps
20 12 * * 1,2,3,4,5 /usr/local/sbin/pwrmgr -u


I made a script to kill anything that might keep the box alive (maybe not needed)
Code:
root@LinkStation:/etc/rc.d/extensions.d# cat /usr/bin/kill_apps
#!/bin/bash


/etc/init.d/daemonwatch.sh

/etc/init.d/bittorrent.sh stop
/etc/init.d/bonjour.sh stop
/etc/init.d/clientUtil_servd.sh stop
/etc/init.d/clientUtil_servd.sh stop
/etc/init.d/diskmon_exec.sh stop
/etc/init.d/ftpd.sh stop
/etc/init.d/httpd.sh stop
/etc/init.d/inetd.sh stop
/etc/init.d/lighttpd.sh stop
/etc/init.d/lprng.sh stop
/etc/init.d/lsprcvd.sh stop
/etc/init.d/ltbootd.sh stop
/etc/init.d/mdadm.sh stop
/etc/init.d/micon_setup.sh stop
/etc/init.d/miconmon.sh stop
/etc/init.d/mount_share.sh stop
/etc/init.d/mysql.sh stop
/etc/init.d/smb.sh stop
/etc/init.d/sxuptp.sh stop
/etc/init.d/twonky.sh stop
/etc/init.d/update_ntp.sh stop
/etc/init.d/upnpd.sh stop
/etc/init.d/xl2tpd.sh stop
/etc/init.d/xmlrpc.sh stop

/etc/rc.d/extensions.d/K05transmission.sh stop

root@LinkStation:/etc/rc.d/extensions.d#


Top
   
PostPosted: Thu Jul 26, 2012 9:50 am 
Offline
Moderator

Joined: Fri Jun 29, 2007 10:39 am
Posts: 2604
Wow, you did nearly everthing to thwart Buffalos mechanisms. ;-)
I, personally, would recommend to use Buffalos mechanisms to keep
the box alive.
Put a script into extensions.d which idles for two minutes between
checks for a specific file in /tmp and calls the powermanager for the
"keeping alive" request, if the file was found.
Remove the file, if you whish the box to shutdown.
This way, you can use the box as designed by Buffalo regarding the
"auto" feature.
See this link for some more information (beware that the script there,
is NOT what you want (endless loop), but should be more than easy
to adapt):
http://buffalo.nas-central.org/wiki/Left_overs_for_%27X%27_and_%27V%27_series

_________________
Please do not use private mail (PN/M) to ask questions. Use the proper forum instead. (me)

If there is no verified backup of a dataset, the dataset, by definition, is unimportant. (c't 2012)

RAID (no matter which level) never ever substitutes a backup. (me)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 14 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited