Several people have asked me if there’s a way to start up Tracks on your own machine when it boots or when you login. The answer if you’re using Mac OS X Tiger is yes — there’s an easy way.
NOTE: There’s now a better way to do this, which only involves one file.
Tiger comes with a new system for starting, stopping and monitoring processes called launchd. I found the discussions on MacOSXHints and Mac Geekery very useful when I was putting this together, and both are well worth reading if you want to find out more about the capabilities for launchd. However, I thought I’d save you a bit of hassle by putting the files together myself.
When you next log in, the WEBrick server should start automatically. If you want to start it manually now, run:
launchctl load Library/LaunchAgents/com.rousette.tracks.plist
or
launchctl unload Library/LaunchAgents/com.rousette.tracks.plist
to unload it. It seems that unloading the script doesn’t actually stop the server, so if you want to stop it, you’ll have to find the process ID and use that to kill it:
ps ax | grep -i "ruby script/server" | grep -v grep | awk '{print $1}'
then note the number you get back (let’s say it’s 1283)
kill 1283
This method starts the server at user login, and doesn’t restart the server if it crashes or is stopped for some other reason. If you want to start the server when the computer boots, put the plist file in the root level Library folder (i.e. /Library/LaunchAgents), and put the start_tracks file in somewhere like /usr/local/bin. If you want the server to re-launch automatically when it gets killed, take a look at the manpage for launchd.plist. I think that it would probably work if you replace the RunAtLoad parameter with OnDemand, which should be set to false — but I haven’t tested that.
This method has started up WEBrick, but you could easily adapt it by replacing the command starting WEBrick in start_tracks with one starting lighttpd.