LightTPD Launchd Item for Tiger

Here is a launchd item that will automatically start-up (and keep alive) LightTPD built using the Hivelogic Ruby/RoR/LightTPD/MySQL installation instructions.

The launchd item provided here is a modified version of the one at TextSnippets, which depends on a Darwin Ports installation and isn’t useful for people who have rolled their own.

Place the Config File

We’re making a big assumption here that we already have a working LightTPD config file.

If not, here’s a great sample config file for a RoR app.

We’ll need to copy the config file (usually called @lighttpd.conf) into a special location using the following commands (note: we’ll be prompted to enter our password when we run the first command):

sudo mkdir /usr/local/etc
sudo cp /replace/this/with/path/to/lighttpd.conf /usr/local/etc/

The first command makes sure that we’ve got a folder to contain the configuration file. If we already have the folder, we’ll see an error that looks like:

mkdir: /usr/local/etc/: File exists

For the second command, we’ll want to replace the /replace/this/with/path/to/lighttpd.conf bit with the actual path to the LightTPD configuration file (which might be ~/Desktop/lighttpd.conf if we’ve saved it on our Desktop).

Create the launchd File

Open Terminal (located in the /Applications/Utilities folder).

If you’re lucky enough to be running TextMate, just type the following command to create the new launchd file, ready for content:

mate /Library/LaunchDaemons/net.lighttpd.plist

If we’re using BBEdit, the command would be:

bbedit /Library/LaunchDaemons/net.lighttpd.plist

And if we’re a vi user, we’d type:

sudo vi /Library/LaunchDaemons/net.lighttpd.plist

Note: Because of the file’s special location in the /Library/LaunchDaemons folder, we’ll need to enter our password before Mac OS X will allow us to save it. Both TextMate and BBEdit do this when you save the file, while vi prompts you for the password right away.

Paste the Text

Cut and paste the following text into the new file we’ve just opened:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
<plist version="1.0">

Load the Config

We now need to tell launchd about the new file using the following command:

sudo launchctl load net.lighttpd.plist

This should immediately start up the LightTPD server. We can verify this by attempting to connect to the application (using the URL and port specified in the config file).

Now, launchd will start our application at boot time and keep our application running even if the process should die unexpectedly.

Sell Our Web 2.0 App to Google/AOL/Yahoo!

More on this once we work out all the little details …

More articles in the Archive →