Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano deploying to system wide RVM not seeing installed Rubies

I'm using a system wide Ruby install on my server, and trying to deploy to a RVM gemset (like rvm use 1.9.2@gemset_name)

When I run my Cap file, Cap pukes and says a Ruby is not installed.

However, in reality that Ruby is installed. (The deploying user is part of the rvm group and can rvm use on the command line manually.)

What might I be doing wrong?

Relevant parts of 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

Cap output

* 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 ]
* 

Ok, awesome: 1.9.2 is installed. (This is to be expected - I installed 1.8.7, REE and 1.9.2 manually!)

But that's not all Capistrano says...

    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.

That last line claims that 1.9.2 not installed?!!

 ** [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

Debugging with cap shell

Jim Gay asks, "what about debugging with cap shell?"

rvm/capinstrano runs commands through rvm-shell, which immediately goes looking for the version and gemset essentially before the command can be executed. (Thus the disable_rvm_shell defined earlier that we used for doing the initial rvm list rubies.

For example:

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

Conclusion

I'm obviously doing something wrong, but what?

Setting 1.9.2 to be the default Ruby is not an option, as I'm also going to host a 1.8.7 app on this box (ideally). This is why I'm using RVM at the system level to begin with).

I also made sure that the deploy user is in the RVM group, per the RVM documentation.

like image 363
RyanWilcox Avatar asked Aug 04 '11 21:08

RyanWilcox


1 Answers

This WARN about not installed ruby is a misleading msg, it should say could not find ruby@gemset pair. If you would use this command on server:

rvm use 1.9.2@MY_APP

You would see the messages in reverse order - first error that the gemset can not be found, to solve it please go to server and run:

rvm --create use 1.9.2@MY_APP

Which will create a gemset for you, if you need any more help with it please contact IRC channel #rvm on FreeNode servers.

like image 101
mpapis Avatar answered Oct 19 '22 23:10

mpapis