Welcome Guest | Login

Problem setting environment to "production" with mongrel and capistrano

Hey guys,

I've spent the past couple of days setting up svn, mongrel, and capistrano to deploy my app, and I finally got it working with one caveat.  When I attempt to deploy my app from my local machine (cap deploy), the app won't start correctly because the line in environment.rb:

# ENV['RAILS_ENV'] ||= 'production'

is commented out.  If I uncomment this line, everything works correctly.  However, I would like to leave this uncommented because I do not want to develop locally in production mode, and I would like to not have to comment/uncomment this line everytime I get ready to deploy or test something locally.

I believe that when you start mongrel, it should set the environment on its own:

run "cd #{current_path} && mongrel_rails start -e production -p #{mongrel_port} -d"

but this doesn't seem to be working.  Has anyone experienced this problem?  It's the last little thing that's keeping me from having a hassle-free deployment!  TIA

2007-05-30 09:06 PM

Setting set :rails_env, :production could set the environment to production. Have you set it up properly ?

Also please ensure that you've everything set up properly in with your deploy.rb file from the link given below.
http://www.hostingrails.com/forums/wiki_thread/5

In regards to your mongrel problem -
The set up for mongrel restart in deploy.rb is as given below.
=================
desc "Restart Mongrel"
# task :restart, :roles => :app do
#   run "cd #{current_path} && mongrel_rails stop"
#   run "cd #{current_path} && mongrel_rails start -e production -p #{mongrel_port} -d"
#   cleanup
# end
=============

Also what does your mongrel.log say about the restarts ?



2007-05-30 11:23 PM

I'm experiencing the same problem as the original poster (except I deploy my app on fcgi). My deploy.rb script includes the line "set :rails_env, :production" but it doesn't seem to make any difference. I am forced to uncomment "# ENV['RAILS_ENV'] ||= 'production'" in environment.rb to make it work... but I'd prefer if the environment could be set the proper way.

Any idea?

2007-06-10 12:58 PM

Please make sure that you have the directive given below set properly in your deploy.rb
set :rails_env, :production
Did you uncomment the line before deploying ?

2007-06-10 02:34 PM

I double checked and the line is there. the environment stays at "development". weird

2007-06-10 02:49 PM

Ok i found a fix to this problem. In my after_udpate_code task, I added the following :

 run "mv #{release_path}/config/environment.rb #{release_path}/config/environment.rb~"
 run "ruby -e 'readlines.each{ |l| if( l.include?(%q(RAILS_ENV)) ) then puts l[/[^# ]+.*/] else puts l end } ' #{release_path}/config/environment.rb~ > #{release_path}/config/environment.rb "  

Basically, it just uncomment the "#ENV['RAILS_ENV'] ||= 'production'" line in environment.db

I found this workaround here : http://forums.asmallorange.com/lofiversion/index.php/t8892.html

2007-06-10 04:04 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.