在Capistrano中使用rvmsudo [英] Using rvmsudo with Capistrano

查看:78
本文介绍了在Capistrano中使用rvmsudo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置capistrano以轻松部署我的rails3应用程序。我对Rails很陌生。

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.

我在同一台服务器上运行redmine,所以我遵循了 http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/ 来运行多个版本的ruby / rails。在我尝试让capistrano重新启动乘客服务器之前,该方法可以正常工作。

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 I try and get capistrano to restart the passenger server.

问题是'sudo'无法通过环境设置(如:< a href = https://stackoverflow.com/questions/257616/sudo-changes-path-why> sudo更改PATH-为什么?)

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

如果我可以使用 rvmsudo而不是 sudo,那么一切都会起作用,因为rvmsudo会传递正确的环境信息。但是,如果我在Captistrano部署中使用 rvmsudo,它将挂起,等待我的sudo密码。

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.

我想实现一个try_rvmsudo,其功能与try_sudo完全一样,如果需要,它将密码发送到哪里。

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

它挂着说:

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


推荐答案

好吧,我发现Capistrano可以首先发送sudo密码(通过运行sudo命令)。 Sudo会记住您的密码一小段时间(默认为5分钟)。而且,rvmsudo只是调用了设置了一些环境变量的sudo,因此它也记住了您的密码。

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!

这篇关于在Capistrano中使用rvmsudo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆