Use a script and launchd task to keep AirDisks spinning

Apr 08, '08 07:30:00AM

Contributed by: finitesquid

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:

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).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.timofejew.TickleAirDiskDataDrive</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Users/peter/bin/TickleDisk</string>
                <string>/Volumes/Data</string>
        </array>
        <key>StartInterval</key>
        <integer>300</integer>
</dict>
</plist>
There are a couple of things to modify in the plist file to get this to work: 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.]

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080331184914894