[Mongrel] Sharing a mongrel cluster in a multi-url environment

Will Green will at hotgazpacho.com
Thu Jan 29 22:17:19 EST 2009


I'm not sure that instance-specific connections are supported by
ActiveRecord (you can, however, use class-specific connections). From the
ActiveRecord documentation,
http://api.rubyonrails.org/classes/ActiveRecord/Base.html, the database
connection information is tied to your model at the class level. I don't
think you can accomplish what you have described without a separate Mongrel
cluster for each virtual host.

Here's an alternate idea:

Assuming you're deploying to a *nix server, what you might try instead is
having your rails app live in one location on the file system. Then, since
the only thing that is different is the configuration, for each domain,
symlink in all but the config directory. The config directory will then be
unique for each app, but all the code will be shared. When you update the
application code, simply restart all the mongrel clusters.

Another idea: you may want to reconsider your application architecture. Do
you really need a separate database for each host? Could you instead
introduce a ClientAccount class (that has the value from X_CLIENT_ID as the
Primary Key), and tie it into the other models with has_many relationships
and a before_filter on the ApplicationController? This way, you don't need
separate configs, you could point each VirtualHost at the same Mongrel
cluster, AND you could manage the Client Account within rails.

==
Will Green



More information about the Mongrel-users mailing list