Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use a script and launchd task to keep AirDisks spinning Network
As we all know by now, with the 7.3.1 firmware update to the AirPort Extreme (802.11n) Base Station, we finally get decent read/write performance from attached disks. The pre-7.3.1 firmware was buggy and slow, but the new firmware rocks, and AirDisks are finally ready for prime time (as well as supporting Time Machine -- yay!).

One of the energy/disk saving features of the new base station firmware is that it will spin down attached drives if they have not been accessed in approximately 10 minutes. This is good for saving a couple of watts of power, as well as prolonging the life of a hard drive. If a drive is used as a Time Machine volume, the delay in waiting for the drive to spin up and be accessible is quite acceptable.

However, if the drive is being used as a network share for data (in my case, iTunes media and archival data), the five to ten second delay caused by spinning up is not acceptable (at least to me). And since there's no parameter to disable disk sleeping on the AirPort, I wrote a trivial program and launchd plist file to "tickle" the disk every few minutes to keep it spinning (and just that one disk - I have two other USB disks attached to that basestation that are for Time Machine, and I do want them to spin down).

So, here are the main features of TickleDisk:
  • A script named TickleDisk is run every five minutes by launchd
  • This script only runs when you are logged in to your account on the Mac it's installed on.
  • TickleDisk checks to see if it's within a time window that I want to keep the disk spinning (e.g. between 9am and midnight). If it's outside of the time window, it just exits.
  • If it is in the time window to keep spinning, it checks to see if the disk is mounted. If it's not, it just exits.
  • If the disk is mounted, it then touches an invisible zero-length file at the root directory of the disk. This is enough to keep the disk spinning. And my access to the data on the disk immediate.
The script below needs to be saved somewhere on your Mac, and be made executable. With your favourite editor, cut and paste the code below, and save it somewhere convienient (I have mine saved as ~/bin/TickleDisk, you may want it saved as /usr/local/bin/TickleDisk or maybe /Applications/Utilities/TickleDisk):
#!/bin/sh

dir=$1
hour=`date '+%H'`
if [ $hour -ge 1 -a $hour -le 9 ]; then
    exit 0
fi

if [ -d $dir ]; then
    touch "$dir/.com.timofejew.tickledisk"
fi
exit 0
After creating this file, make it executable by typing in chmod 755 ~/bin/TickleDisk (or whatever you ended up calling it) in a Terminal window. You'll notice from the script that I don't want it to "tickle" the disk between 1am and 9am (that's the 1 and 9 you see in the first if statement). Modify this time window to your needs (remember it's a 24 hour clock, from 0 to 23).

The plist file below needs to be placed in the directory ~/Library/LaunchAgents and called something like com.timofejew.TickleDiskNameDrive.plist (where DiskName is the name of the AirDisk that is meaningful to you). There are a couple of things to modify in the plist file to get this to work:
  • The <string> tag in the Label section needs to be the same as the name of the plist filename.
  • The first <string> tag in the ProgramArguments section needs to be the full path to the TickleDisk script.
  • The second <string> tag in the ProgramArguments section is the mounted path of the AirDisk (usually something like /Volumes/NameOfAirDisk, where NameOfAirDisk is the name of the disk that you want to keep spinning.
And, finally, you'll need to log out, log back in, and mount the disk that you want to keep spinning (if it's not mounted, then it won't be touched). BTW, my apologies to those that get a bit lost with the files and instructions here: I've been a UNIX hack for over 20 years, and I always assume at least a bit of nerdy UNIX-ish knowledge. And yes, it's not the most robust script ever coded, but as long as you pass a valid directory, it'll work just fine -- it's not meant to be called manually.

[robg adds: I haven't tested this one. Many years ago, we ran this hint which set up a cron task to tickle a disk; this hint is a modern, more robust version of the same thing, basically.]
    •    
  • Currently 1.71 / 5
  You rated: 5 / 5 (7 votes cast)
 
[11,045 views]  

Use a script and launchd task to keep AirDisks spinning | 6 comments | Create New Account
Click here to return to the 'Use a script and launchd task to keep AirDisks spinning' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use a script and launchd task to keep AirDisks spinning
Authored by: Coumerelli on Apr 08, '08 07:46:02AM

Great hint. How about adding a check to see if iTunes is running? Then the disk can spin down if I'm not interested in using it - even between 9a and 1a, logged in and working, just not listening to my sweet tunez.

---
"The best way to accelerate a PC is 9.8 m/s2"



[ Reply to This | # ]
What is symptom?
Authored by: TF on Apr 08, '08 08:04:27AM

Just curious, what symptoms of storing you iTunes media on an AEBS are you experiencing? I have mine up there and, while I don't exercise it thoroughly, I don't really notice anything. If you're playing music, doesn't that "tickle" the disc enough?

Also, separately, does the Airdisk sleep when its mounted, or just when no users are connected (after 10mins)?



[ Reply to This | # ]
Err, no. Frequent spinup&down _shortens_ hard disk life
Authored by: tempel on Apr 09, '08 12:24:44AM

The article author wrote: "This is good for [...], as well as prolonging the life of a hard drive."

The opposite is true as far as I know (based on hearsea for the past 20 years I use hard disks):

Turning on and off a disk causes changes in heat, and those heat changes lead to stress on the entire meachnism, wearing it out over time. A constanly spinning disk, however, keeps a rather constant temperature, extending its life span.

Also, modern drives do not use ball bearings any more but some fluid which make them spin without abrasion, which further reduces the possibility of a shortened life even if the drive keeps running for days without use. (that'd be quite a waste of energy then, though)



[ Reply to This | # ]
Use a script and launchd task to keep AirDisks spinning
Authored by: thaJack on Apr 10, '08 03:37:00PM

Is a Time Machine disk on a desktop doing the same thing? Every little while I seem to hear my MyBook that I am using for Time Machine spin down and seem to turn off. Same thing going on here?



[ Reply to This | # ]
There was an error connecting to the update server. Check your network settings and try again.
Authored by: Michael.Massing on Apr 21, '08 12:01:39PM
Thanks for pointing out the operational improvements with this update, which I haven't seen discussed elsewhere. Sadly, I invariably get the message above when attempting this update. Neither of the hints or discussions below seem helpful:
http://support.apple.com/kb/HT1218
http://discussions.apple.com/thread.jspa?messageID=7062094&tstart=0

My MacBook Pro is connected directly to the AirPort via ethernet (I've also tried wireless). The AirPort is the LAN router, and connects directly to the cable modem. What might I be missing? Where might I look?

Thanks,
M.

---
If a nation expects to be ignorant and free, in a state of civilization, it expects what never was and never will be. - Thomas Jefferson to Col. C. Yancey, 1816

[ Reply to This | # ]

This probably belongs in the forums. I'll repost there...
Authored by: Michael.Massing on Apr 21, '08 07:11:14PM

...and this strand can be deleted. Best to all, M.

---
If a nation expects to be ignorant and free, in a state of civilization, it expects what never was and never will be. - Thomas Jefferson to Col. C. Yancey, 1816



[ Reply to This | # ]