9

I am using Capistrano 3:

➜  webapp git:(rails) ✗ cap --version
Capistrano Version: 3.1.0 (Rake Version: 10.1.1)

My Capfile is:

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

require 'capistrano/rails'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

And my deploy.rb is:

set :rvm_type, :user 

set :application, "my_app"

set :scm, :git
set :repo_url,  'git@github.com:nanounanue/my_app.git'
set :scm_passphrase, ""


set :ssh_options, {:forward_agent => true}
set :default_run_options, {:pty => true}
set :stages, ["vagrant"]
set :default_stage, "vagrant"


namespace :deploy do
  task :start do ; end
  task :stop do ; end
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      run "sudo touch #{File.join(current_path,'tmp','restart.txt')}" 
    end
  end

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

end

As you can see I am trying to deploy to a Vagrant VM.

The problem is that when I execute (any) command of Capistrano happens the follwing:

➜  webapp git:(rails) ✗ cap vagrant deploy --trace                                                  
** Invoke vagrant (first_time)
** Execute vagrant
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:check (first_time)
** Execute rvm:check
DEBUG [501eda1d] Running ~/.rvm/bin/rvm version on 192.168.33.10
DEBUG [501eda1d] Command: ~/.rvm/bin/rvm version
DEBUG [501eda1d]    
DEBUG [501eda1d]    rvm 1.25.20 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
DEBUG [501eda1d]    
DEBUG [501eda1d] Finished in 0.446 seconds with exit status 0 (successful).
rvm 1.25.20 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
DEBUG [c7fc23f0] Running ~/.rvm/bin/rvm current on 192.168.33.10
DEBUG [c7fc23f0] Command: ~/.rvm/bin/rvm current
DEBUG [c7fc23f0]    ruby-2.0.0-p247
DEBUG [c7fc23f0] Finished in 0.185 seconds with exit status 0 (successful).
ruby-2.0.0-p247
DEBUG [3fb3aad9] Running ~/.rvm/bin/rvm default do ruby --version on 192.168.33.10
DEBUG [3fb3aad9] Command: ~/.rvm/bin/rvm default do ruby --version
DEBUG [3fb3aad9]    RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [3fb3aad9]    
DEBUG [3fb3aad9]    You need to change your terminal emulator preferences to allow login shell.
DEBUG [3fb3aad9]    Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [3fb3aad9]    Please visit https://rvm.io/integration/gnome-terminal/ for a example.
DEBUG [3fb3aad9]    
DEBUG [3fb3aad9]    ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
DEBUG [3fb3aad9]    
DEBUG [3fb3aad9] Finished in 0.309 seconds with exit status 0 (successful).
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

This continues and when it reaches the bundle install part:

DEBUG [184656ed] Command: cd /home/vagrant/apps/releases/20140313235436 && ~/.rvm/bin/rvm default do bundle install --binstubs /home/vagrant/apps/shared/bin --path /home/vagrant/apps/shared/bundle --without development test --deployment --quiet
DEBUG [184656ed]    RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [184656ed]    
DEBUG [184656ed]    You need to change your terminal emulator preferences to allow login shell.
DEBUG [184656ed]    Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [184656ed]    Please visit https://rvm.io/integration/gnome-terminal/ for a example.
DEBUG [184656ed]    
DEBUG [184656ed]    You are trying to install in deployment mode after changing
DEBUG [184656ed]    your Gemfile. Run `bundle install` elsewhere and add the
DEBUG [184656ed]    updated Gemfile.lock to version control.
DEBUG [184656ed]    
DEBUG [184656ed]    You have added to the Gemfile:
DEBUG [184656ed]    * crossfilter-rails
DEBUG [184656ed]    
cap aborted!
bundle stdout: Nothing written
bundle stderr: Nothing written
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `call'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:164:in `block (2 levels) in _execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `call'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:166:in `block in _execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `tap'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/capistrano-bundler-1.1.2/lib/capistrano/tasks/bundler.cap:30:in `block (5 levels) in <top (required)>'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/abstract.rb:89:in `with'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/capistrano-bundler-1.1.2/lib/capistrano/tasks/bundler.cap:22:in `block (4 levels) in <top (required)>'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/abstract.rb:81:in `within'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/capistrano-bundler-1.1.2/lib/capistrano/tasks/bundler.cap:21:in `block (3 levels) in <top (required)>'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:updated => bundler:install
The deploy has failed with an error: #<SSHKit::Command::Failed: bundle stdout: Nothing written
bundle stderr: Nothing written
>
** Invoke deploy:failed (first_time)
** Execute deploy:failed

I have no idea what this happening...Do you have ant ideas?

EDIT:

In the vagrant virtual machine the .bash_profile is:

vagrant@vagrant-ubuntu-saucy-64:~$ cat .bash_profile 

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

EDIT (March 25, 2014):

After the suggestions of @GhostGambler the new Capfile is:

set :default_environment, {
  'PATH' => "/usr/local/rvm/gems/ree-1.8.7-2012.02@<gemset>/bin:/usr/local/rvm/gems/ree-1.8.7-2012.02@global/bin:/usr/local/rvm/rubies/ree-1.8.7-2012.02/bin:/usr/local/rvm/bin:$PATH",
  'RUBY_VERSION' => 'ree-1.8.7-2012.02',
  'GEM_HOME'     => '/usr/local/rvm/gems/ree-1.8.7-2012.02@<gemset>',
  'GEM_PATH'     => '/usr/local/rvm/gems/ree-1.8.7-2012.02@<gemset>'
 #,
  #'BUNDLE_PATH'  => '/usr/local/rvm/gems/ree-1.8.7-2012.02'  # If you are using bundler.
}



# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'


require 'rvm1/capistrano3'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

And I added in deploy.rb

...

before 'deploy', 'rvm1:install:gems' 


namespace :deploy do
... 

The error still appears (RVM is not a function...) but it can install the gems, but now it fails with another error:

DEBUG [29ba9d5d] Command: cd /home/vagrant/apps/releases/20140325223229 && /tmp/arquimedes/rvm-auto.sh . gem install --file Gemfile
DEBUG [29ba9d5d]    RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [29ba9d5d]    
DEBUG [29ba9d5d]    You need to change your terminal emulator preferences to allow login shell.
DEBUG [29ba9d5d]    Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [29ba9d5d]    Please visit https://rvm.io/integration/gnome-terminal/ for a example.

DEBUG [29ba9d5d]    


DEBUG [29ba9d5d]    Using execjs (2.0.2)
DEBUG [29ba9d5d]    Using json (1.8.1)
DEBUG [29ba9d5d]    Using uglifier (2.4.0)
...
DEBUG [29ba9d5d]    Using bootstrap-sass (3.1.1.0)
DEBUG [29ba9d5d]    
 INFO [29ba9d5d] Finished in 135.237 seconds with exit status 0 (successful).
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper 
** Execute git:check
DEBUG [6f67db51] Running /usr/bin/env git ls-remote git@github.com:opintel/webapp.git on 192.168.33.10
DEBUG [6f67db51] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/arquimedes/  
...
...
DEBUG [6f67db51] Finished in 4.179 seconds with exit status 0 (successful).
** Invoke deploy:check:directories (first_time)
** Execute deploy:check:directories
 INFO [645d5072] Running /usr/bin/env mkdir -pv /home/vagrant/apps/shared /home/vagrant/apps/releases on 192.168.33.10
DEBUG [645d5072] Command: /usr/bin/env mkdir -pv /home/vagrant/apps/shared /home/vagrant/apps/releases
 INFO [645d5072] Finished in 0.011 seconds with exit status 0 (successful).
** Invoke deploy:check:linked_dirs (first_time)
** Execute deploy:check:linked_dirs
** Invoke deploy:check:make_linked_dirs (first_time)
** Execute deploy:check:make_linked_dirs
** Invoke deploy:check:linked_files (first_time)
** Execute deploy:check:linked_files
** Invoke deploy:started (first_time)
** Execute deploy:started
** Invoke deploy:updating 
** Invoke deploy:updated (first_time)
** Execute deploy:updated
** Invoke deploy:publishing (first_time)
** Execute deploy:publishing
** Invoke deploy:symlink:release (first_time)
** Execute deploy:symlink:release
 INFO [bf5c604d] Running /usr/bin/env rm -rf /home/vagrant/apps/current on 192.168.33.10
DEBUG [bf5c604d] Command: /usr/bin/env rm -rf /home/vagrant/apps/current
 INFO [bf5c604d] Finished in 0.011 seconds with exit status 0 (successful).
 INFO [72cfae75] Running /usr/bin/env ln -s /home/vagrant/apps/releases/20140325223229 /home/vagrant/apps/current on 192.168.33.10
DEBUG [72cfae75] Command: /usr/bin/env ln -s /home/vagrant/apps/releases/20140325223229 /home/vagrant/apps/current
 INFO [72cfae75] Finished in 0.011 seconds with exit status 0 (successful).
** Invoke deploy:restart (first_time)
** Execute deploy:restart
cap aborted!
ArgumentError: wrong number of arguments (1 for 0)
nanounanue
  • 7,942
  • 7
  • 41
  • 73
  • It seems you have problems with rvm on your VM. Please try this http://stackoverflow.com/questions/9336596/rvm-installation-not-working-rvm-is-not-a-function to fix it. – ryaz Mar 14 '14 at 10:46
  • @ryaz in the question that you linked, they suggest using `ssh server 'bash -lc "command"'.` In Capistrano 2.x there was an option to run this (`default_run_options[:shell] = '/bin/bash--login'`), but in Capistrano 3 that option doesn't exists any more... Any other suggestion? – nanounanue Mar 14 '14 at 18:45
  • Please look at the 2nd answer in the link above. And you don't need to use capistrano for this. Just ssh to you VW and try to fix rvm. Then try to deploy as usual. – ryaz Mar 17 '14 at 06:29
  • @ryaz I follow the instructions (I put the `if test -f ~/.rvm/scripts/rvm; then [ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm fi` in the `.bashrc` file). If I log in with `ssh` there is no problem, but, when I try to do it with `cap vagrant deploy --trace` the problem appears. What I am doing wrong? (This is getting on my nerves...) – nanounanue Mar 18 '14 at 13:22
  • I have `PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*` in my `~/.bashrc` file. Maybe it would be helpful for you. – ryaz Mar 18 '14 at 13:32
  • @ryaz it didn't work :( – nanounanue Mar 18 '14 at 22:46
  • Have you checked this link `https://rvm.io/integration/gnome-terminal`? The problem with your VM rvm. First of all, you need to fix it. – ryaz Mar 19 '14 at 10:39
  • @ryaz as is stated in the question I am using `Capistrano` for this, I never use a `gnome terminal` ... – nanounanue Mar 20 '14 at 14:22
  • Take a look at [this](http://stackoverflow.com/questions/21360824/to-use-bash-login-by-default-with-capistrano-3-sshkit-rvm). Someone proposed `SSHKit.config.command_map.prefix[:rvm].push("source .bash_profile &&")` – Ulrich Thomas Gabor Mar 20 '14 at 23:39
  • @nanounanue, please ssh to your VM and show your `~/.bash_profile` – ryaz Mar 21 '14 at 09:59
  • @ryaz I just edited the original question and added the `.bash_profile` as you asked – nanounanue Mar 24 '14 at 21:54
  • @GhostGambler Where I have to put the code line that you suggested? Could you put some example? Thanks in advance – nanounanue Mar 24 '14 at 21:55
  • I would try `deploy.rb`. – Ulrich Thomas Gabor Mar 24 '14 at 21:58
  • @GhostGambler Could you be more specific? – nanounanue Mar 24 '14 at 22:00

1 Answers1

7

Have you heard of rvm1-capistrano3?

This is installed by putting into Gemfile

gem 'rvm1-capistrano3', :require => false

(do not forget bundle install) and putting into Capfile

require 'rvm1/capistrano3'

This solved my issues all at once.

While you modify the Capfile you should remove (or comment out)

require 'capistrano/rvm'

since this is not needed with this gem and may break things.

Ulrich Thomas Gabor
  • 6,584
  • 4
  • 27
  • 41
  • I tried your suggestion and I got this error message: `➜ webapp git:(rails) ✗ cap vagrant deploy --trace cap aborted! NoMethodError: undefined method `stages' for Capistrano::DSL:Module ` Any ideas? – nanounanue Mar 24 '14 at 23:19
  • Try uncommenting `require 'capistrano/rvm'` as you do not need it with `rvm1-capistrano3`. Basically I would comment out all modules from there, try if it works and add them back step by step to see if problems arise. – Ulrich Thomas Gabor Mar 24 '14 at 23:33
  • I got now this error: `** Execute deploy:symlink:release INFO [45b] Running /usr/bin/env rm -rf.../current on 192.168.33.10 DEBUG [45b] Command: /usr/bin/env rm -rf.../current INFO [45b] Finished in...with exit status 0 (successful). INFO [6c8] Running /usr/bin/env ln -s.../apps/releases/ .../apps/current on 192.168.33.10 DEBUG [6c8] Command: /usr/bin/env ln -s.../apps/releases/ .../apps/current INFO [6c8] Finished in...with exit status 0(successful). ** Invoke deploy:restart (first_time) ** Execute deploy:restart cap aborted! ArgumentError: wrong number of arguments (1 for 0) ` – nanounanue Mar 25 '14 at 22:00
  • (I ran out of space) It worked, except for the last error... Maybe is a new question? – nanounanue Mar 25 '14 at 22:02
  • Yes, a new question would be good. I would claim this has nothing to do with your rvm problem from above. Also you would have the possibility to post your current `Capfile` and `deploy.rb` and the whole error message in a readable manner. – Ulrich Thomas Gabor Mar 25 '14 at 22:12