edit: final fix to monitorio.sh is on page two of this post.
edit: added mount noatime solution by Rac8006
So after rummaging through all the scripts, I am starting to get the big picture of how this tiny linux NAS box works. The non-sleeping issue has been a major problem since the WD-live days of 2011. In fact the WD-live and the WD-Cloud has the same problems since they run almost identical OS’es with slightly different program names.
Cron jobs!!
If you check /etc/cron.d, you will see probably most of the nightly wake up jobs, including the 20-checkRaid that runs at 3:05 everynight and the auto-update that runs at 3:00 regardless of the fact that you un-check the auto update option. Other jobs include system stats that indicates that it reports every 10 minutes everyday and at 23:59 it rotates the statistics files. In total there are 10 jobs for cron.d and 12 similar jobs in cron.daily.
I’m not sure how many of these jobs are necessary, however if I stop the cron before putting the drive to sleep,
/etc/init.d/cron stop
My New Sleep Pattern
I get the following sleep pattern.
Mar 3 21:16:48 WDMyCloud logger: “Enter Standby in 30 seconds”
Mar 3 22:29:19 WDMyCloud logger: exit standby after 4351 (since 2014-03-03 21:16:48.940000001 -0800)
Mar 3 22:34:21 WDMyCloud logger: “Enter Standby in 30 seconds”
Mar 4 00:50:35 WDMyCloud logger: exit standby after 8174 (since 2014-03-03 22:34:21.650000001 -0800)
Mar 4 00:55:38 WDMyCloud logger: “Enter Standby in 30 seconds”
Mar 4 05:17:54 WDMyCloud logger: exit standby after 15736 (since 2014-03-04 00:55:38.180000001 -0800)
Mar 4 05:22:58 WDMyCloud logger: “Enter Standby in 30 seconds”
Mar 4 08:06:47 WDMyCloud logger: exit standby after 9830 (since 2014-03-04
which is a big reduction in the number of wake-ups (I use to get at least 1 wakeup per hour), now I get 4.
My Stopped Services
Now, of course, I have stopped all the services that I had deemed un-needed and they are as follows:
/etc/init.d/nfs-kernel-server stop
/etc/init.d/nfs-common stop
/etc/init.d/upnp_nas stop
/etc/init.d/mDNSResponder stop
/etc/init.d/wdphotodbmergerd stop
/etc/init.d/wdnotifierd stop
/etc/init.d/wdmcserverd stop
/etc/init.d/wddispatcherd stop
/etc/init.d/cron stop
and of course I re-wrote monitorio.sh, or rather I peeled of the “threshold trigger code” that monitors your hard drive for changes and if the change is more then 1GB it sets a flag for MEDIACRAWLER_REWALK (at least I think it does).
Monitorio.sh
Basically Monitorio is your sleep loop.
It has two infinite loops that the inner loop at one minute intervals watches your drive for activity and when the sleep countdown has been reached it issues a hdparm -y (putting your drive on standby) and turns on the flashing LED then exits the inner loop back to the outer loop.
The outer loop watches for your drives to wake up using hdparm -C on all your drives. Once it detects that all your drives have woken, it turns your blinky LED light back into a solid blue light.
The 7 Second Wakeup
Now I noticed a problem. In my other Sleep threads, there is always a series of 7 seconds wakeups; put the drive to sleep and 7 seconds later, if you query the drive, it is awake. Not always though. It seems like it is always the first couple of times before settling down into a longer sleep.
The problem comes from here in /usr/local/sbin/monitorio.sh
At the bottom of monitorio.sh the file /tmp/standby is created when we go into standby by
touch /tmp/standby
.
.
.
for i in ${drivelist[@]}; do
hdparm -y $i >/dev/null
done
The Solution
Apparently the touch even though is accessing a Ramdisk causes a delay write in the hardware (not always) and by immediately performing a hard drive standby after a touch, you get the 7 seconds wake up.
This seems to fix it.
touch /tmp/standby
sync <======= new solution, this sync seems to work better
sync <======= second sync suggested by Rac8006 reduces the total wakeups down to 1 or 2 per night
sleep 5 <======= sleep 5 seconds waiting for the access to settle
.
.
.
for i in ${drivelist[@]}; do
hdparm -y $i >/dev/null
done
My Routine
My daily routines now is once the device awakes in the morning, I turn off the power saver and leave the drive running for the whole day; thus I don’t have to worry about spin-ups and spin-downs during the day.
I also turn on the cron so the daily jobs has a chance to run. I even run /etc/init.d/ramlog restart to ensure the ramlogs gets written to disk.
Before I head for bed, I turn on sleep and the LED, disable cron, and un-map my drive.
Although it may be a satisfactory solution for my needs, it is an unnecessary chore to do everyday. I am tempted just leave the device On rather then go through the rituals of putting it to sleep. As a WD Red drive, the NAS drive is meant to be left on indefinitely.
edit: 5 minute Sleep Delay
I also change my 10 minute sleep timer in /etc/standby.conf to 5 minutes simply for the fact that I would waste 10 minutes and more, every night waiting for my device to sleep; this way I only waste 5
standby_enable=enabled
standby_time=5
edit: adding mount noatime
Final ingrediants to Sleep (credits goes to Rac8006, so give him the kudos for being persistent)
-
adding an extra sync to the monitorio script helps a lot with reducing the number of 7 second wake ups down to only one or two per night.
-
after SSH’ing into the device issue the following mount command… don’t worry nothing untoward will happen and if it does, blame Rac8006 please…
mount -o remount,noatime,nodiratime /dev/root /
you could also use mine
mount -o remount,noatime /dev/root /
The difference is that I assume noatime encompassing nodiratime.