Section 3.2. Using Mongrel


3.2. Using Mongrel

Now that you've installed Mongrel (and probably spent twice as long reading about it), you can take a look at what it gives you. Mongrel uses commands to do business with your application. You can see which commands come with Mongrel out of the box:

$ mongrel_rails Usage: mongrel_rails <command> [options] Available commands are:  - restart  - start  - stop Each command takes -h as an option to get help.


You'll notice we're calling the mongrel_rails executable. This is just a Ruby script that comes with Mongrel and includes the three basic commands you need to run a Rails application: start, stop and restart. Each command takes optional configuration parameters, which default to values that will be familiar to Rails developers and are similar to what you'll see available in Rails' script/server command. We'll get into the details of how you can use these options in Section 4. For now, let's just see what the options for the start command are.

$ mongrel_rails start -h Usage: mongrel_rails <command> [options]     -e, --environment ENV            Rails environment to run as     -d, --daemonize                  Whether to run in the background or not     -p, --port PORT                  Which port to bind to     -a, --address ADDR               Address to bind to     -l, --log FILE                   Where to write log messages     -P, --pid FILE                   Where to write the PID     -n, --num-procs INT              Number of processors active before clients denied     -t, --timeout TIME               Timeout all requests after 100th seconds time     -m, --mime PATH                  A YAML file that lists additional MIME types     -c, --chdir PATH                 Change to dir before starting (will be expanded)     -r, --root PATH                  Set the document root (default 'public')     -B, --debug                      Enable debugging mode     -C, --config PATH                Use a config file     -S, --script PATH                Load the given file as an extra config script.     -G, --generate CONFIG            Generate a config file for -C         --user USER                  User to run as         --group GROUP                Group to run as         --prefix PATH                URL prefix for Rails app     -h, --help                       Show this message         --version                    Show version


We want to just get our vanilla Rails application running on Mongrel, so all we need to do is run:

$ cd ~/code/examples/ $ mongrel_rails start ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ** Rails loaded. ** Loading any Rails specific GemPlugins ** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart). ** Rails signals registered. HUP => reload (without restart). It might not work well. ** Mongrel available at 0.0.0.0:3000 ** Use CTRL-C to stop.


You can see Mongrel loads Rails in the following way:

  1. Start the HttpServer, listening on port 3000

  2. Load the Rails-specific configuration values and plugins, then mount the Rails application at "/"

  3. Set up the signals

A common practice is to daemonize Mongrel so it runs in the background, and use that same terminal to tail the Rails development log. You can stop it using the stop command. Once you get Mongrel running, you can configure it to suit your particular needs.

3.2.1. Where Mongrel Puts Files

When running a Rails app, Mongrel will store its log and PID file in RAILS_ROOT/log by default. Mongrel's log file mongrel.log stores Mongrel-related messages only. It is not intended to replace a request log (e.g., apache.log) or the Rails' logs (e.g., development.log). See Section 7 for more info about enabling robust logging features.




Mongrel. Serving, Deploying, and Extending Your Ruby Applications
Mongrel. Serving, Deploying, and Extending Your Ruby Applications
ISBN: 9812836357
EAN: N/A
Year: 2006
Pages: 48

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net