Ruby on rails 3.2 为什么Capistrano执行';耙子';从/usr/bin/env而不是/usr/local/rvm/gems/ruby-2.1.0/bin/rake?

Ruby on rails 3.2 为什么Capistrano执行';耙子';从/usr/bin/env而不是/usr/local/rvm/gems/ruby-2.1.0/bin/rake?,ruby-on-rails-3.2,rubygems,gem,capistrano,Ruby On Rails 3.2,Rubygems,Gem,Capistrano,当我执行cap production deploy Capistrano的任务时,它尝试从/usr/bin/env执行rake,但我的gem安装到了/usr/local/rvm/gems/ruby-2.1.0/bin/rake 版本: Ruby 2.1/Capistrano 3.0.1/Rake 10.1.1/Rails 3.2.16/rvm 1.25.12 我在myserver上使用rvm来促进ruby的安装,但是我使用用户rvm_admin手动安装和udate gems。 rvm已安装在“系

当我执行cap production deploy Capistrano的任务时,它尝试从/usr/bin/env执行rake,但我的gem安装到了/usr/local/rvm/gems/ruby-2.1.0/bin/rake

版本: Ruby 2.1/Capistrano 3.0.1/Rake 10.1.1/Rails 3.2.16/rvm 1.25.12

我在myserver上使用rvm来促进ruby的安装,但是我使用用户rvm_admin手动安装和udate gems。 rvm已安装在“系统范围”。 我不使用capistrano rvm,也不使用capistrano rails,因为我手动更新ruby、gems、资产和迁移

平台: 在XUbuntu 12.04.4 LTS上工作 部署到Debian喘息

文件:

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
deploy.rb
set :application, 'odpf'
set :repo_url, 'git@github.com:myrepo/myapp.git'
set :branch, 'production_1.01'
set :deploy_to, '/var/www/odpf'
set :pty, false
set :scm, :git
set :format, :pretty


namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # l'exemple correspond à ce qu'il faut pour restart passenger :
      # http://www.modrails.com/documentation/Users%20guide%20Apache.html#_redeploying_restarting_the_ruby_on_rails_application
      execute :mkdir, '-p', "#{release_path}/tmp"
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end


  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # Conformément à : http://guides.rubyonrails.org/v3.2.14/command_line.html#tmp
      within release_path do
        execute :rake, 'tmp:cache:clear'
      end
    end
  end

  # Create symlink to database.yml after publication
  before 'deploy:published', 'db_access:create_symlinks'

  after :finishing, 'deploy:cleanup'
end
暂存文件(production.rb、staging.rb)

当我执行
cap生产部署时
,它一直运行良好,直到输出末尾的soem点:

INFO [0a0dbcb0] Running /usr/bin/env rake tmp:cache:clear on myserver.net
DEBUG [0a0dbcb0] Command: cd /var/www/odpf/releases/20140129101515 && /usr/bin/env rake tmp:cache:clear
DEBUG [0a0dbcb0] /usr/bin/env: rake
DEBUG [0a0dbcb0] : Aucun fichier ou dossier de ce type
cap aborted!
rake stdout: Nothing written
rake stderr: Nothing written
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.0.0/lib/sshkit/command.rb:94:in `exit_status='
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
Capistrano尝试从
/usr/bin/env
但我的gem安装在这里:

rvm_admin@myserver:/var/www/odpf/current$ bundle show rake
/usr/local/rvm/gems/ruby-2.1.0/gems/rake-10.1.1
rvm_admin@myserver:/var/www/odpf/current$ which rake
/usr/local/rvm/gems/ruby-2.1.0/bin/rake

我做错了什么?

很确定你没有做错什么,这是capistrano的问题-
rake
在没有
bundle exec
的情况下执行。请参见此处的问题:

在该线程的末尾还有一个建议的解决方案-

SSHKit.config.command_map[:rake] = "bundle exec rake"

谢谢,这很有效!正如信息一样,我还收到了另一个同样适用于此处的答案:。解决方法是使用该命令:SSHKit.config.command_map[:rake]=“/bin/rake tmp:cache:clear”
SSHKit.config.command_map[:rake] = "bundle exec rake"