views:

50

answers:

2

The Setup

I have a Ruby on Rails application that I manage from a sysadmin perspective. This application in installed on a pool of load balanced application servers. These application servers a running Apache 2 and Passenger 3.0. The application files are stored in a ramdisk because IO on the application servers are ridiculously slow.

Database configuration

The backend database is stored on a pair of MySQL clusters (active/passive). Several clients use our application and each have a separate MySQL database.

Currently, we have X copies of the application (X being the number of clients). The difference between each copy is just the database.yml. Since we are using ramdisks, "disk" space is expensive and I'm thinking that there has to be a better way to solve this problem.

Potential solutions

Ideally, I would like to be able to specify the database.yml in the Apache virtualhost but that doesn't look possible with my current setup. The database.yml would be attached to the domain name accessed. If there is a way to do this, it would really be really fantastic.

Another approach would be to make a whole lot of symbolic links instead of storing copies of the application. I guess that doesn't sound too bad but I don't really like this solution.

How would you approach this problem and solve it ?

If you need more information, just ask and I'll be happy to answer. I'm not so sure whether this belongs to SF or SO but smells more SO to me.

A: 

Perhaps you can use the same database.yml, but use different environments? You should be able to set different Rails environments using different RailsEnv parameter in your virtualhost setting.

Mladen Jablanović
Ah great idea ! Would the creation of environments with random name not pose a problem ? Would they be production environments with just a different DB ?
Antoine Benkemoun
You can set individual options for each environment in `/config/environments/`, take a look at existing ones. Not sure if you can somehow "inherit" production environment, but for start you can just copy `production.rb` into `production1.rb` and `production2.rb` and just use different database settings in `environment.rb`. I haven't tried any of this, but I expect it to work that way, and POLS has been working so far. ;)
Mladen Jablanović
+2  A: 

As Mladen said, you can use RailsEnv. It's pretty much the ideal solution to your problem, it's intended to be used that way. Just don't forget to set different PassengerAppGroupName values for each env because Phusion Passenger normally uniquely identifies an application based on its path only. Also don't forget to make the config/initializers/[env name].rb file.

Hongli
You get the answer as it is more complete but Mladen deserved it also :-) PassengerAppGroupName is Passenger v3 and up only.
Antoine Benkemoun