Easy Button for Mongrel

July 21st, 2006

If you’ve hopped on the Mongrel bandwagon, you know how convenient and efficient the Mongrel server can be for running Ruby on Rails applications.

The only thing that’s not so convenient about Mongrel is the way you start it when you’re working in development mode. Typing that long command (mongrel_rails start -d -p 3000 -e development) every time you want to start your web app can be a real pain.

So I came up with this quick shell script (UNIX/Linux only – sorry Windows folks) that does the same thing as the script/server command.

The script/mongrel file


#!/bin/sh
/usr/local/bin/mongrel_rails start \
 -d \
 -p 3000 \
 -e development \
 -c /path/to/your/web/app

To use it:

  1. Go to your Rails app and make a file in your script directory called mongrel (no file extension – just “mongrel”).
  2. Paste the above code inside the file, modifying it as necessary. Save the file.
  3. Go out to your terminal, and navigate to the root of your web app.
  4. Run script/mongrel.
  5. That’s it! Your web server should be running! Test it by browsing to http://0.0.0.0:3000.

To shut down the web app, just run mongrel_rails stop from the root of your web app.


4 Responses to “Easy Button for Mongrel”

  1. Scott Raymond Says:
    Nice! FYI, in Edge Rails "script/server" will use Mongrel, if you've got it installed. (http://dev.rubyonrails.org/ticket/5475)
  2. Ryan Says:
    Cool - that's a good reason to upgrade to Edge Rails.
  3. DHH Says:
    On Edge Rails, script/server will run mongrel like this if its installed.
  4. Ryan Says:
    Thanks guys - I'm playing with Edge Rails now, and it does indeed work as advertised. Compared to the standard Lighttpd script/server, Mongrel seems _fast_.

Sorry, comments are closed for this article.