Serving Rails with Mongrel

What is Mongrel

Mongrel is an HTTP server for hosting Ruby web applications.

Why Mongrel

Ruby On Rails community experimented with many ways to host applications and wasn’t entirely happy with any. Until Mongrel came out and in a matter of weeks became a de-facto standard way to serve Rails.

Mongrel is stable, reasonably fast, very easy to configure, and can be used in both production and development environments.

Details

RubyWorks stack runs several (by default, four) Mongrel instances. They serve HTTP requests on ports 3002-3005, and execute a Rails application located in /usr/rails.

Mongrel configuration files are /etc/rails/mongrel_300[2-5].config. The only interesting settings in those files are:

Process management

Mongrels are started as runit services, by executing scripts /var/service/mongrel_300[2-5]/run. To control Mongrel processes, run the following commands:

Troubleshooting

The Rails application logs go to /usr/rails/production.log (more precisely, to /usr/rails/[environment_name].log, if you changed the environment name in mongrel configuration files).

If a Mongrel process refuses to start, looking at the ps record of runsvdir process usually gets you to the root cause:

ps -ef | grep runsvdir

runsvdir is the main process of runit, and it shows in the ps record stderr output of services it controls.

If that doesn’t help, tell monit to stop Mongrel:

sudo monit stop mongrel_3002

and run its startup script from the console:

sudo /var/service/mongrel_3002/run

to see the actual stdout/stderr output.

External links