[英]Capistrano 3 and Rbenv installed system wide using Chef ( bash: bundle: command not found )
[英]Bundle with capistrano installed by chef
我正在使用Chef配置一個無用的盒子,然后使用capistrano部署我的應用程序。
我的廚師安裝捆綁程序的方法如下:
include_recipe "rbenv"
include_recipe "rbenv::ruby_build"
rbenv_ruby node[:rbenv][:ruby] do
global true
end
rbenv_gem "bundler" do
ruby_version node[:rbenv][:ruby]
end
當我嘗試使用帶有capistrano的bundle
,我發現執行的捆綁軟件是預先安裝在盒子上的捆綁軟件,而不是廚師安裝的捆綁軟件。
這是問題所在:
$ which bundle
/opt/rbenv/shims/bundle
$ sudo which bundle
/usr/bin/bundle
$ sudo su -
root# which bundle
/opt/rbenv/shims/bundle
基本上,如果Capistrano使用/usr/bin/bundle
,則似乎使用第二種形式運行命令。
我試過跑步:
$ sudo bundle
/usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8:in `require': no such file to load -- rubygems (LoadError)
from /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8
from /usr/lib/ruby/vendor_ruby/bundler.rb:11:in `require'
from /usr/lib/ruby/vendor_ruby/bundler.rb:11
from /usr/bin/bundle:4:in `require'
from /usr/bin/bundle:4
並且獲得了與Capistrano完全相同的例外。
如果我手動卸載bundler
那么我將獲得以下信息:
$ bundle
Bundler::GemfileNotFound
$ sudo bundle
sudo: bundle: command not found
$ sudo su -
root# bundle
Bundler::GemfileNotFound
更新
我發現整個紅寶石版本不適用於sudoers:
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
$ sudo ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
甚至更多的麻煩。
你能幫助我嗎 ?
謝謝。
問題不在於sudoers無法使用rbenv
Ruby。 問題在於,默認情況下使用系統Ruby,除非被其他東西覆蓋-通常是.bashrc
或/etc/profile.d/*
等。
由於capistrano
不提供任何這些文件,因此它使用系統Ruby。
您應該通過添加以下內容來告訴cap
在系統路徑之前使用rbenv
bin路徑:
set :default_environment, {
'PATH' => "/opt/rbenv/shims:/opt/rbenv/bin:$PATH"
}
到您的deploy.rb
文件。
在Capistrano v3中, :default_environment
已重命名為:default_env
。
顯然,可以使用default_env
調整,但不是首選方式。
如:
set :default_environment, {
'PATH' => "/opt/rbenv/shims:/opt/rbenv/bin:$PATH"
}
不是由capistrano維護的,甚至可能很危險。
首選的方法是調查要運行的程序,以解決此問題。
特別是我的問題:RVM需要在外殼啟動時初始化,並且任何RVM安裝工具都將在文件末尾包含.bashrc以及對正確的初始化腳本的調用。 同樣在.bashrc的開頭,有一個命令可以在非交互式shell上調用腳本時退出該腳本。
偶然地Capistrano在非交互式shell上運行腳本,因此當它調用RVM命令時,腳本不會在非交互式shell中初始化。
在我的情況下,解決方案是在Chef中編輯.bashrc文件,以便在退出之前調用RVM初始化腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.