0
我的deploy.rb設置了一些環境變量來使用常規用戶的本地Ruby,而不是系統範圍的。如何防止由Capistrano的sudo操作設置default_environment變量?
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系統調用」。
我該如何避免這種情況?