× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

Sleeper script to sleep/halt 30 mins after the HDDs spin dow

SANGER_A2
Follower

Sleeper script to sleep/halt 30 mins after the HDDs spin dow

I've had a Buffalo LinkStaion LS-VL for years and spent a lot of time hacking around on it. I've just got my ReadyNAS NV+ NV2 and have put 4 x 2TB Seagate HDDs in it. I use this as a file store/backup server/media server so I don't need it on all the time. I need to be able to wake it up using WOL and for it to spin the hard drives down after 30 mins and go to sleep after an hour.

The spin-down and WOL were easy as that is just in the web interface in the power section. Getting the box to respond to WOL is harder. If you double-press the power button or use the web interface to shutdown, the NAS shuts off completely and ignores WOL signals.

I made up a script that runs on startup and checks for when the hard drives go into idle. 30 minutes after the hard drives go into idle, it tells the computer to halt (sleep if you run windows) and then it hardly uses any power. The fan is off, the hard drives are off, the lights are off - but it will wake up quickly when a WOL signal is sent.

Remember: if you brick your NAS or anything, it's not my fault. Be careful you follow the commands exactly. I'm happy to try and help if you get into any difficulty. If you want to change the times between spin-down and idle, just change the number in the line below in the sleeper file. It's multiples of 10 minutes so 3 = 30 mins before sleep:-
	while [  "$count" -lt 3 ]; do


You will need to have the media share active on your NAS and be able to use Putty or console in linux to SSH into the box and run commands. I installed the "Enable Root" (http://www.readynas.com/?p=4203) addon and it worked perfectly.

Copy the script to the media share on your ReadyNAS, then execute the commands below in SSH to copy it to the startup folder and make it executable:-
cp /c/media/sleeper /etc/init.d/
chmod 755 /etc/init.d/sleeper
ls -l /etc/init.d/sleeper

This should produce a line of text like the below (note all the r's, w's and x's)
 	-rwxr-xr-x 1 root root 945 2013-01-28 19:30 /etc/init.d/sleeper

Then run the command below to make it run on startup:-
update-rc.d sleeper defaults
ls -l /etc/rc2.d/

This should produce a line of text like the below (note all the r's, w's and x's)
lrwxrwxrwx 1 root root 17 2013-01-28 19:34 S03sleeper -> ../init.d/sleeper

Then run the commands below to test it
/etc/rc2.d/S03sleeper &
top

Top lists the running processes, press the shift button on your keyboard and the comma key 5 or so times. This changed what the view is sorted by. We want to sort by PID (the highest PIDs are the process that were last run). Then you should see something like:-
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
2655 root 20 0 2548 1160 932 R 0.3 0.5 0:00.41 top
2654 root 20 0 5032 484 436 S 0.0 0.2 0:00.00 sleep
2652 root 20 0 6120 1180 1032 S 0.0 0.5 0:00.00 S03sleeper

Press the "q" key to quit
Type the command below to restart the box and make sure it loads on startup:-
shutdown -r now

Wait for the ReadyNAS to start and then SSH in and run the command below:-
top

This time, press shift and full stop (period for you americans) a lot and it will sort by process name and you should see:-
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
634 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 usbhid_resumer
725 root 20 0 3128 264 192 S 0.0 0.1 0:00.00 udhcpc
801 root 16 -4 2568 1224 384 S 0.0 0.5 0:00.38 udevd
2480 root 20 0 2548 1172 936 R 0.0 0.5 0:00.51 top
1654 root 20 0 1676 624 524 S 0.0 0.3 0:00.08 syslogd
779 root 20 0 1916 744 616 S 0.0 0.3 0:00.00 startpar
782 root 20 0 1916 332 204 S 0.0 0.1 0:00.00 startpar
2439 root 20 0 1460 336 284 S 0.0 0.1 0:00.00 startpar
1541 root 20 0 5824 976 612 S 0.0 0.4 0:00.01 sshd
2470 root 20 0 13640 3216 2564 S 0.0 1.3 0:00.13 sshd
1714 root 20 0 15296 3068 2496 S 0.0 1.2 0:00.10 smbd
1735 root 20 0 15296 1784 1184 S 0.0 0.7 0:00.02 smbd
2463 root 20 0 15384 3440 2836 S 0.0 1.4 0:00.05 smbd
784 root 20 0 2648 1076 928 S 0.0 0.4 0:00.00 sleeper
2462 root 20 0 1588 416 368 S 0.0 0.2 0:00.00 sleep

Now press the "q" key to quit top and close SSH. You may want to check the the box has turned itself off after an hour or so.

Remember: YMMV. I have turned off all the services (including photos 2) except the HTTPS (because it won't let me), SMB and DLNA. Anything that accesses the hard drives often (eg transmission) will stop them from going into idle. Also, I only have the ReadyNAS NV+ V2 running RAIDiator 5.2.7 so other NAS's or other versions may not work.

If you have two RAID arrays or JBOD setup in your box (ie c and d etc) then this script should probably not be used. When ONE of the disks/arrays goes into idle the script will halt the system even though the other disks may be reading/writing data.

For the wake-on-lan side of things, I have created a batch file on Windows that sends a wake on lan signal every 5 seconds and continuously checks until the specified share is active. It's attached if anyone wants to use it. You can also use the Advanced Wake on LAN plugin in XBMC (it's in the program section) and it works for waking the NAS up. You can find the mac address of the NAS using the RAIDar application. It looks something like 75:81:3f:fe:80:38 (remove the colons if you're using my batch file).

If someone wants to make this into an addon that anyone can use I'm perfectly happy for you to do this as long as I get credit for the original code. You will want to have a changeable setting somewhere that lets people change the multiples of 10 minutes that it waits before sleeping. I just don't have the interest or need for this to be a addon.

You can download a zip file of my wake-on-lan batch file, the application needed, an icon you may want to use and the sleeper script from my website here http://sangera2.com/main/misc/sleeper
Message 1 of 1
Top Contributors
Discussion stats
  • 0 replies
  • 2744 views
  • 0 kudos
  • 1 in conversation
Announcements