我的deploy.rb设置了一些环境变量来使用常规用户的本地Ruby而不是系统范围的Ruby。
set :default_environment, {
:PATH => '/home/myapp/.rvm/bin:/home/myapp/.rvm/bin:/home/myapp/.rvm/rubies/ruby-1.9.1-p378/bin:/home/myapp/.rvm/gems/ruby-1.9.1-p378/bin:/home/myapp/.rvm/gems/ruby-1.9.1-p378%global/bin:/home/myapp/bin:/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/bin:/usr/games',
:RUBY_VERSION => 'ruby-1.9.1-p378',
:GEM_HOME => '/home/myapp/.rvm/gems/ruby-1.9.1-p378',
:GEM_PATH => '/home/myapp/.rvm/gems/ruby-1.9.1-p378:/home/myapp/.rvm/gems/ruby-1.9.1-p378%global'
}
当然,当任务使用sudo时,我希望可以使用系统范围的ruby。但似乎无论如何都要设置环境变量,这显然对root用户无效并返回错误:
executing "sudo -p 'sudo password: ' /etc/init.d/god stop"
servers: ["myapp.com"]
[myapp.com] executing command
command finished
failed: "env PATH=/home/myapp/.rvm/bin:/home/myapp/.rvm/bin:/home/myapp/.rvm/rubies/ruby-1.9.1-p378/bin:/home/myapp/.rvm/gems/ruby-1.9.1-p378/bin:/home/myapp/.rvm/gems/ruby-1.9.1-p378%global/bin:/home/myapp/bin:/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/bin:/usr/games RUBY_VERSION=ruby-1.9.1-p378 GEM_HOME=/home/myapp/.rvm/gems/ruby-1.9.1-p378 GEM_PATH=/home/myapp/.rvm/gems/ruby-1.9.1-p378:/home/myapp/.rvm/gems/ruby-1.9.1-p378%global sh -c 'sudo -p '\\''sudo password: '\\'' /etc/init.d/god stop'" on myapp.com
使用capistrano的 sudo“系统调用”或常规运行“sudo系统调用”没有区别。
我该如何避免这种情况?
答案 0 :(得分:2)
一种简单的方法可能是带外,因为在Capistrano中回收连接(不是)的方式,像这样的环境变量不限于一次调用(正如人们所期望的那样!)< / p>
我建议使用vanilla Net :: SSH(http://net-ssh.rubyforge.org/ssh/v2/api/index.html)进行带外连接,这可能很简单:
Net::SSH.start('host', 'user', :password => "password") do |ssh|
ssh.exec!("my-task-here")
end
只是一个想法!