Using rvmsudo with Capistrano

I am trying to configure capistrano to quickly deploy my rails3 application. I am new to rails.

Everything works as it should, except that I am trying to restart the stand-alone passenger server.

I run redmine on the same server, so I ran http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/ to run several versions of ruby ​​/ rails. This works fine until I try to get capistrano to restart the passenger server.

The problem is that 'sudo' does not pass the environment settings through (as found on: sudo changes PATH - why? )

Everything works if I can use 'rvmsudo' instead of 'sudo' since rvmsudo conveys the correct environment information. But, if I use "rvmsudo" in my Captistrano deployment, it hangs waiting for my sudo password.

I would like to implement try_rvmsudo, which works exactly the same as try_sudo, where it sends the password if asked. but I can not find any information about this.

here is the restart command I'm trying to use:

desc "Restart Passenger server" task :restart, :roles => :app, :except => { :no_release => true } do run <<-CMD if [[ -f #{release_path}/tmp/pids/passenger.#{passenger_port}.pid ]]; then cd #{deploy_to}/current && #{passenger_path}passenger stop -p #{passenger_port} --pid-file #{release_path}/tmp/pids/passenger.#{passenger_port}.pid; fi CMD # restart passenger standalone on the specified port/environment and as a daemon run "cd #{deploy_to}/current && rvmsudo #{passenger_path}passenger start -e #{rails_env} -p #{passenger_port} -a 127.0.0.1 -d --pid-file #{release_path}\ /tmp/pids/passenger.#{passenger_port}.pid" end 

And it freezes, saying:

  ** [out :: snapshotroulette.com] [sudo] password for deployer: 
+4
source share
2 answers

Ok, I found out that I can send Capistrano the sudo password first (by running the sudo command). Sudo remembers your password for a short time (default is 5 minutes). And, rvmsudo just calls sudo with some environment variables set, so it also remembers your password.

This is not very pretty, but it works:

 desc "Restart Passenger server" task :restart, :roles => :app, :except => { :no_release => true } do # Hack to have capistrano enter the sudo password (for rvmsudo later) sudo "whoami" run <<-CMD if [[ -f #{release_path}/tmp/pids/passenger.#{passenger_port}.pid ]]; then cd #{deploy_to}/current && rvmsudo passenger stop; fi CMD # restart passenger standalone on the specified port/environment and as a daemon # The sleep 1 is to give the server enough time to spawn. The session was closing before it spawned, so it never actually spawned run "cd #{deploy_to}/current && rvmsudo passenger start -e #{rails_env} -p #{passenger_port} -a 127.0.0.1 -d --pid-file #{release_path}/tmp/pids/passeng\ er.#{passenger_port}.pid && sleep 1" end 

Any other solutions are welcome!

+3
source

The rvmsudo hanging capistrano issue seems to have been fixed in later versions of rvm. For my launch of "rvm get stable" on target computers, the problem is fixed.

0
source

All Articles