views:

112

answers:

1

I would like to be able to start a mongrel or webrick server by passing an extra command line argument that I can read somewhere inside my rails application. An example would be:

ruby script/server -p3000 --target=FOO

Here, --target is a custom switch who's value I would like to intercept in my rails application.

However, this yields the error:

server: invalid option: --target=FOO

I found mongrel documentation which mentions a -C (--config=PATH) argument specifying a full path to a yml configuration file, but specifying that switch gives the same error as above. I presume this option is deprecated.

Is there another way to accomplish this?

A: 

You can't pass mongrel/webrick an extra command line argument without rewriting the argument processing code. If mongrel/webrick doesn't recognize the option, it will complain and give an error.

Rather than rewriting the argument processing, why not put the custom value in an environment variable and have your app query the variable? You could add your own script to handle starting mongrel/webrick and setting the environment so a single command would kick off everything.

Fred
We're running under Windows Server and in production are using mongrel_service. If there is ONE place where I can add a command line processor that sucks the options out that I'm interested in and works in mongrel, webrick, mongrel_service and maybe even phusion passenger I'd like to do that.
whaka
Really frustrating is that if I use the -C switch to specify a config YAML file, it too is rejected if it contains anything mongrel_rails doesn't understand.
whaka