开发者

Using rvmsudo with Capistrano

I am trying to setup capistrano to deploy my rails3 app easily. I'm pretty new to rails.

Everything is working as it should except that I am trying to restart the standalone passenger server.

I am running redmine on the same server, so I followed http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/ to get multiple versions of ruby/rails to run. This works fine until开发者_JS百科 I try and get capistrano to restart the passenger server.

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

Everything works if I can use 'rvmsudo' instead of 'sudo', since rvmsudo passes along 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 a try_rvmsudo that works exactly like try_sudo does, where it sends the password if it is asked for. but I can't seem to find any information on doing this.

here is the restart command that I am 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 hangs saying:

 ** [out :: snapshotroulette.com] [sudo] password for deployer:


Well, I found out that I can have Capistrano send the sudo password first (by running a sudo command). Sudo remembers your password for a small time (5 minutes by default). And, rvmsudo simply calls sudo with some environment variables set, so it too remembers your password.

It's not really 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!


The problem of rvmsudo hanging capistrano seems to have been fixed in more recent versions of rvm. For my running 'rvm get stable' on the target machines fixed the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜