我在我的服务器上使用系统范围的
Ruby安装,并尝试部署到RVM gemset(如rvm使用1.9.2@gemset_name)
当我运行我的Cap文件时,Cap pukes并说没有安装Ruby.
但是,实际上安装了Ruby. (部署用户是rvm组的一部分,可以手动在命令行上使用.)
我可能做错了什么?
Capfile的相关部分
$:.unshift(File.expand_path('./lib',ENV['rvm_path'])) # Add RVM's lib directory to the load path. require "bundler/capistrano" require "rvm/capistrano" require "erb" set(:rvm_type) { :system } set(:ruby_version) { '1.9.2' } set(:rvm_ruby_string) { "#{ruby_version}@#{application}" } set(:rvm_path) { "/usr/local/rvm" } #set(:rvm_bin_path) { "#{rvm_path}/bin" } before "deploy:setup","rvm:debug_gemset" before "deploy:setup","bundle:install_gem" namespace :rvm do desc "Creates gemset for application" task :debug_gemset do disable_rvm_shell do run "/usr/local/rvm/bin/rvm list rubies" do |ch,stream,data| if stream == :err logger.debug "capured output on STDERR: #{data}" else # stream == :out logger.debug "capured output on STDOUT: #{data}" end end end end end # We need this so that we can install rvm first! def disable_rvm_shell(&block) default_shell = self[:default_shell] self[:default_shell] = nil yield self[:default_shell] = default_shell end
上限输出
* executing `deploy:setup' triggering before callbacks for `deploy:setup' * executing `rvm:debug_gemset' * executing "/usr/local/rvm/bin/rvm list rubies" # <----- ran outside of rvm-shell servers: ["XX.XXX.XXX.XXX"] Password: [XX.XXX.XXX.XXX] executing command * capured output on STDOUT: * capured output on STDOUT: rvm rubies * capured output on STDOUT: * ruby-1.8.7-p352 [ x86_64 ] * capured output on STDOUT: * ree-1.8.7-2011.03 [ x86_64 ] * capured output on STDOUT: * ruby-1.9.2-p290 [ x86_64 ] *
好的,太棒了:安装了1.9.2. (这是预期的 – 我手动安装了1.8.7,REE和1.9.2!)
但这并非所有Capistrano都说……
command finished * executing `bundle:install_gem' * executing "gem install bundler" servers: ["XX.XXX.XXX.XXX"] [XX.XXX.XXX.XXX] executing command ** [out ::XX.XXX.XXX.XXX] WARN: ruby ruby-1.9.2-p290 is not installed.
最后一行声称没有安装1.9.2?!!
** [out ::XX.XXX.XXX.XXX] To install do: 'rvm install ruby-1.9.2-p290' *** [err ::XX.XXX.XXX.XXX] ERROR: Gemset 'MY_APP' does not exist,rvm gemset create 'MY_APP' first. *** [err ::XX.XXX.XXX.XXX] Error: RVM was unable to use '1.9.2@MY_APP' command finished Failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2@MY_APP' -c 'gem install bundler'" on XX.XXX.XXX.XXX
使用cap shell进行调试
Jim Gay问道,“用shell shell调试怎么样?”
rvm / capinstrano通过rvm-shell运行命令,rvm-shell在执行命令之前立即查找版本和gemset. (因此我们之前定义的disable_rvm_shell用于执行初始rvm列表rubies.
例如:
cap> which rvm [establishing connection(s) to XX.XXX.XXX.XX] Password: ** [out :: XX.XXX.XXX.XX] WARN: ruby ruby-1.9.2-p290 is not installed. ** [out :: XX.XXX.XXX.XX] To install do: 'rvm install ruby-1.9.2-p290' *** [err :: XX.XXX.XXX.XX] ERROR: Gemset 'MY_APP' does not exist,rvm gemset create 'MY_APP' first. *** [err :: XX.XXX.XXX.XX] Error: RVM was unable to use '1.9.2@MY_APP' error: Failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2@MY_APP' -c 'which rvm'" on XX.XXX.XXX.XX
结论
我显然做错了什么,但是什么?
将1.9.2设置为默认的Ruby不是一个选项,因为我还将在此框中托管1.8.7应用程序(理想情况下).这就是为什么我在系统级别使用RVM开始).
根据RVM文档,我还确保部署用户位于RVM组中.