Amir
Amir

Reputation: 1872

Capistrano deploy fails with rake run (rails3 + rvm)

EDIT: The issue here was that I used RVM on my local machine and rbenv on the server. This is highly not recommended, if you're managing several ruby installation (or upgrading your ruby version but do not want to change the system's) use either RVM or rbenv on all environments! /EDIT

So I'll start with a bit history: I'm in the process of upgrading our rails2 website to rails3. Most of the things are working properly by now, except Capistrano's deploy script. The current setup I have is:

(by now if you see anything that doesn't make sense, please let me know)

Nothing changed in the deploy script, yet when I try to deploy to my testing server (let's call it beta) I get this error:

* executing `deploy:restart'
* executing "cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers"
        servers: ["208.0..."]
        [208.0...] executing command
    *** [err :: 208.0...] rake aborted!
    *** [err :: 208.0...] no such file to load -- bundler/setup
    *** [err :: 208.0...] /home/foo/bar/releases/20120630161947/Rakefile:5
    *** [err :: 208.0...] (See full trace by running task with --trace)
     ** [out :: 208.0...] (in /home/foo/bar/releases/20120630161947)
        command finished in 1183ms
    failed: "sh -c 'cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers'" on 208.0...

The relevant part on deploy.rb looks like this:

  task :restart do
    run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} queue:restart_workers"
    run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} db:migrate"
    run "touch #{deploy_to}/current/tmp/restart.txt"
  end   

Needless to say, rake RAILS_ENV=beta queue:restart_workers' works perfectly when run manually on the server. Also, the application gets deployed (the code was copied from git, it's just the last part of the deploy fails).

Lastly, the error didn't change since before I installed rvm-capistrano and added to the Gemfile, so I'm not even sure it's related to rvm, I'm just guessing from looking online.

Thanks

Upvotes: 2

Views: 695

Answers (1)

systho
systho

Reputation: 1161

In order to work correctly, rbenv must override all the ruby and gem-related executables with the shims it provides.

Usually this is done with a startup script (this is why it works when you login to your server) but Capistrano logs in without shell and thus does not run those scripts.

You must add the following to your deploy.rb :

set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}

and do not use anything rvm related on your server, rbenv and rvm really do not like each other

PS : a little more explanation on this topic : http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/

Upvotes: 1

Related Questions