Jul 2005 09

Starting Tracks at login with Mac OS X Tiger

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.
  • Download the files here and unzip the package. You’ll find two files inside: com.rousette.tracks.plist and start_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_tracks from the default 3030 if you have another app running on that port.
  • Put the start_tracks file in ~/Library/Scripts/Applications/launchd, making the folders if necessary.
  • Make sure start_tracks is executable by issuing this command in the Terminal:
    
    cd ~/Library/Scripts/Applications/launchd
    chmod +x start_tracks
    
    
  • Put the file com.rousette.tracks.plist in ~/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.

4 Comments

I put the scripts in the right places in ~/Library (and set the chmod for the executable).  The script runs, but crashes immediately.  I am using 10.4.1 and can manually start tracks from the command line.  Any idea about what I can do to get this working?  Thanks for a great app!

Mike: Did you make sure that you changed all the paths in both files to the correct ones for your installation? I think that you probably need the full path in all cases (i.e. /Users/you/whatever rather than ~/whatever). You could also try taking a look at any errors in the system log (use the Console app, in /Applications/Utilities). If it still doesn’t work, drop me an email, and I’ll see if I can figure it out.
-----

I am intereted in finding and reading the log that keeps track of when my machine is logged into specifically.  Does this process allow for that?  I want to be able to keep track of this in order to see if unauthorized access has been obtained on my machine.  I am running 10.4.9 on a G4 12” powerbook 1.5.

Thank you

Erik Hilden: If you want to see who has logged into Tracks (specifically), you can look at the logs in the /log directory inside the Tracks directory. But that won’t tell you anything about who has logged into your machine. For that you need to use the Console application (/Applications/Utilities/Console), and use that to open either system.log or console.log.

Name:

Email (not shown on page):

Location (optional):

URL:

Remember my personal information

Notify me of follow-up comments?

Please enter the word you see in the image below: