Saturday, May 3, 2008

Deployment: Part 3

We finally have everything up and running... at least the basics. However, we needed something more, such as starting/stopping/restarting our other servers. This was easily achieved using our own custom tasks in deploy.rb.

However, there was one odd one, which was backgrounDRb. To start the server, you must use:

./script/backgroundrb start -e production

The first problem we encountered was that after Capistrano had finished executing, the backgrounDRb daemon would disappear. After some research, an easy fix was found, which was to run the script through the nohup function:

nohup ./script/backgroundrb start -e production

This enabled backgroundrb to exist after Capistrano was complete. There was also another oddity that I found through research which I also implemented, which was to cd to the root directory before executing the script:

cd path/to/root && nohup ./script/backgroundrb start -e production

I never tested whether or not I could run the script without cd-ing... but the above command works for me without a problem, so why fix something that's not broken?

Next came environment problems. Backgroundrb was, for some odd reason, accessing the database in the development environment. However, I was clearly running the script in production!

Looking through the code, I realized that in bdrb_config.rb, it was setting the ENV["RAIL_ENV"] using the -e flag (which I stated production). However, when the master and meta workers were initialized, they were loading the rails environment without checking the ENV["RAILS_ENV"]. They were using the config file instead!

To fix this problem, simply change line 262 of master_worker.rb and line 350 of meta_worker.rb from:

run_env = CONFIG_FILE[:backgroundrb][:environment] || 'development'

to:

run_env = ENV["RAILS_ENV"] || CONFIG_FILE[:backgroundrb][:environment] || 'development'

This should check all the possible places that the environment could have been set and now everything should be running in the production environment!

Hope this helps anyone that was just as stumped as I was!


W

No comments: