2

I am using Capistrano to bootstrap an empty Ubuntu VM.

I have a base recipe that installs base requirements:

recipes/base.rb

def set_default(name, *args, &block)
  set(name, *args, &block) unless exists?(name)
end

namespace :deploy do
  desc "Install everything onto the server"
  task :install do
    run "#{sudo} apt-get -y update"

    # Common dependencies
    run "#{sudo} apt-get -y install curl git-core build-essential python-software-properties"
    run "#{sudo} apt-get -y install sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion"

    # Set timezone to UTC
    run "#{sudo} bash -c 'echo UTC > /etc/timezone'"
    run "#{sudo} cp /usr/share/zoneinfo/UTC /etc/localtime"
    run "#{sudo} dpkg-reconfigure -f noninteractive tzdata"
  end
end

I also have a recipe for installing rvm. I use the rvm-capistrano gem for this:

recipes/rvm.rb

set_default(:rvm_ruby_string) { "1.9.3@#{application}" }
set_default(:rvm_install_type, :stable)
set_default(:rvm_type, :user)

require 'rvm/capistrano'

after 'deploy:setup', 'rvm:install_rvm'
after 'deploy:setup', 'rvm:install_ruby'

It appears as if the rvm-capistrano gem is modifying the default shell for every task and appending:

rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3@application'

The repercussion of this is that my base recipe is no longer working since it is runned before installing rvm:

cjoudrey (master) app$ cap deploy:install
  * executing `deploy:install'
  * executing "sudo -p 'sudo password: ' apt-get -y update"
    servers: ["33.33.33.10"]
    [33.33.33.10] executing command
    [33.33.33.10] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3@app' -c 'sudo -p '\''sudo password: '\'' apt-get -y update'
 ** [out :: 33.33.33.10] bash: /home/vagrant/.rvm/bin/rvm-shell: No such file or directory
    command finished in 45ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3@app' -c 'sudo -p '\\''sudo password: '\\'' apt-get -y update'" on 33.33.33.10
cjoudrey (master) app$

deploy.rb

require 'bundler/capistrano'

load 'config/recipes/base'
load 'config/recipes/rvm'
load 'config/recipes/nginx'
load 'config/recipes/mysql'
load 'config/recipes/nodejs'

server '33.33.33.10', :web, :app, :db, primary: true

set :user, 'vagrant'
set :application, 'app'
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, 'git'
set :repository, 'git@github.com:cjoudrey/test.git'
set :branch, 'master'

default_run_options[:pty] = true
ssh_options[:forward_agent] = true
ssh_options[:keys] = `vagrant ssh-config | grep IdentityFile`.split(' ').last

after 'deploy', 'deploy:cleanup'

Has anyone had this issue before? Is there a way to control when rvm-capistrano modifies the default shell? i.e. Is there a way to have it not modify the default shell for deploy:install?

Should I just make my own rvm recipe instead of using rvm-capistrano?

Christian Joudrey
  • 3,441
  • 25
  • 25

1 Answers1

4

I had a similar problem, and ended up writing a disable_rvm_shell function in my deploy.rb. I documented this in a blog entry: Capistrano, system wide RVM and creating gemsets as part of deploy:setup.

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60
  • 2
    make a gem of it - very useful thing, also you could do `run "...", :shell=>"bash"` – mpapis Mar 30 '12 at 16:58
  • @RyanWilcox blog.wilcoxd.com is down – matt May 23 '12 at 08:15
  • I'd be very interested in knowing how you did that. I have a production system that I don't want to install RVM on but still want to use the same set of recipes for controlling it... What I eventually did was to write a simple version of git-shell https://gist.github.com/2785833 and install it at ~/.rvm/bin/rvm-shell – Jamie Cook May 25 '12 at 04:54
  • For those that thirst for information while my blog is down, I grabbed a gist of it: https://raw.github.com/gist/2788518/2850cdcd255513a1bd662306650520144978094e/capistrano_rvm_and_gemsets.html – RyanWilcox May 25 '12 at 16:54