Passing custom info to mongrel_rails start

Posted by whaka on Stack Overflow See other posts from Stack Overflow or by whaka
Published on 2010-04-07T21:08:31Z Indexed on 2010/04/07 21:13 UTC
Read the original article Hit count: 200

Filed under:
|
|
|

One thing I really don't understand is how I can pass custom start-up options to a mongrel instance.

I see that a common approach is the use environment variables, but in my environment this is not going to work because my rails application serves many different clients. Much code is shared between clients, but there are also many differences which I implement by subclassing controllers and views to overload or extend existing features or introduce new ones. To make this all work, I simply add the paths to client specific modules the module load path ($:).

In order to start the application for a particular client, I could now use an environment variable like say, TARGET=AMAZONE. Unfortunately, on some systems I'm running multiple mongrel clusters, each cluster serving a different client. Some of these systems run under Windows and to start mongrel I installed mongrel_services. Clearly, this makes my environment variable unsuitable.

Passing this extra bit of data to the application is proving to be a real challenge. For a start, mongrel_rails service_install will reject any [custom] command line parameters that aren't documented. I'm not too concerned as installing the services using the install program is trivial.

However, even if I manage to install mongrel_services such that when run it passes the custom command line option --target to mongrel_rails start, I get an error because mongrel_rails doesn't recognize the switch.

So here were the things I looked at:

  1. Pass an extra parameter:

    mongrel_rails start --target XYZ ...

  2. use a config file and add target:XYZ, then do:

    mongrel_rails start -C x:\myapp\myconfig.yml

  3. modify the file:

    Ruby\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mswin32-60\lib\mongrel\command.rb

  4. Perhaps I can use the --script option, but all docs that I found on it were for Unix

1 and 2 simply don't work. I played with 4 but never managed it to do anything. So I had no choice but to go with 3. While it is relatively simple, I hate changing ruby library code.

Particularly disappointing is that 2 doesn't work. I mean what is so unreasonable about adding other [custom] options in the config file? Actually I think this is a fundamental piece that is missing in rails. Somehow, the application should be able to register and access command line arguments it expects.

If anybody has a good idea how to do this more elegantly using the current infrastructure, I have a chocolate fish to give away!!!

© Stack Overflow or respective owner

Related posts about rails

Related posts about mongrel