Running Mongrel under DaemonTools

February 27, 2009 · 1 min read

I use DaemonTools to keep my services running and behaving themselves. Since I run plenty of Rails applications, here's the DaemonTools run script I use to keep Mongrel humming along:

#!/bin/sh
exec 2>&1

echo "Starting..."

ENVIRONMENT=production
PORT=8000
IP=0.0.0.0

CHDIR=/var/www/www.application.com
USER=application_user

exec softlimit -m 134217728 \
     setuidgid $USER \
     env HOME=$CHDIR \
     mongrel_rails start -e $ENVIRONMENT -p $PORT -a $IP -c $CHDIR 2>&1

The softlimit caps memory usage at 128MB, setuidgid drops privileges to the application user, and the rest is standard Mongrel configuration. Create a separate DaemonTools service for each Mongrel instance you want to run and just change the PORT variable in each script.