Question

i just stumbled across a posing on the mongodb-user list where there was a discussion about passenger and forking when using mongoDB with MongoMapper.

I just wanted to remind that Rails developers need to tweak their 'environment.rb' if they use MongoDB with Passenger.

By default, Passenger spawns Ruby processes with fork(). And, as fork () shares file descriptors, the Rails app has to reopen the connection to MongoDB in the fresh new "process".

http://groups.google.com/group/mongodb-user/browse_thread/thread/f31e2d23de38136a

anyone knows if there are still issues with mongoDB and passenger or what is the best way to serve a mongoDB-rails-application with passenger?

Was it helpful?

Solution

I think this "issue" is still around, but I think the fix was provided in both the thread you linked to (a link in the first message) and in a gist by John Nunemaker (http://gist.github.com/232953).

I believe the relevant bit of information is in the following block of code which you will place in an intializer:

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    # if using older than 0.6.5 of MM then you want database instead of connection
    # MongoMapper.database.connect_to_master if forked
    MongoMapper.connection.connect_to_master if forked
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top