Starting Tracks at login with Mac OS X Tiger
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 calledlaunchd. 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.
- Download the files here and unzip the package. You’ll find two files inside:
com.rousette.tracks.plistandstart_tracks. - You need to edit both (using a text editor) and replace ‘YOURUSERNAME’ with your real user name. Unless your actual user name is ‘YOURUSERNAME’—some people have a funny sense of humour. You might also want to change the port in
start_tracksfrom the default 3030 if you have another app running on that port. - Put the
start_tracksfile in~/Library/Scripts/Applications/launchd, making the folders if necessary. - Make sure
start_tracksis executable by issuing this command in the Terminal:cd ~/Library/Scripts/Applications/launchd chmod +x start_tracks - Put the file
com.rousette.tracks.plistin~/Library/LaunchAgents, again, making the folders if necessary.
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.



Tue, 12 Jul 2005 @ 13:47 ¶