【问题标题】:Capistrano 3 use unknown bundler and stderr with custom taskCapistrano 3 使用未知的捆绑器和标准错误与自定义任务
【发布时间】:2013-10-28 17:00:02
【问题描述】:

我的 Capfile:

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

# Includes default deployment tasks
require 'capistrano/deploy'

# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails/tree/master/assets
#   https://github.com/capistrano/rails/tree/master/migrations
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'sidekiq/capistrano'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

部署.rb:

set :application, 'myapp'
set :user, 'deployer'
set :repo_url, "git@bitbucket.org:citicom/#{fetch :application}.git"

# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

set :deploy_to, "/home/#{fetch :user}/apps/#{fetch :application}"
# set :scm, :git

set :format, :pretty
# set :log_level, :debug
set :pty, true

set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets tmp/sock vendor/bundle public/system}

# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :keep_releases, 3

# for RoR 4
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_flags, ''
set :bundle_without, %w{test development}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
set :bundle_roles, :all
namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      run "cd #{current_path} && /etc/init.d/unicorn_#{fetch :application} restart"
      # 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:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

  after :finishing, 'deploy:cleanup'

end

错误:

git:(master) ✗ cap production bundler:install
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /usr/local/share/npm/lib/node_modules in PATH, mode 040777
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler.rb:284: warning: Insecure world writable dir /usr/local/share/npm/lib/node_modules in PATH, mode 040777
DEBUG [55d61c51] Running if test ! -d /home/deployer/apps/myapp/current; then echo "Directory does not exist '/home/deployer/apps/myapp/current'" 1>&2; false; fi on 134.19.136.197
DEBUG [55d61c51] Command: if test ! -d /home/deployer/apps/myapp/current; then echo "Directory does not exist '/home/deployer/apps/myapp/current'" 1>&2; false; fi
DEBUG [55d61c51] Finished in 0.895 seconds with exit status 0 (successful).
 INFO [166054bd] Running /bin/myapp_bundle --gemfile /home/deployer/apps/myapp/current/Gemfile --path /home/deployer/apps/myapp/shared/bundle  --binstubs /home/deployer/apps/myapp/shared/bin --without test development on 134.19.136.197
DEBUG [166054bd] Command: cd /home/deployer/apps/myapp/current && ( RVM_BIN_PATH=~/.rvm/bin /bin/myapp_bundle --gemfile /home/deployer/apps/myapp/current/Gemfile --path /home/deployer/apps/myapp/shared/bundle  --binstubs /home/deployer/apps/myapp/shared/bin --without test development )
DEBUG [166054bd]    zsh:1: no such file or directory: /bin/myapp_bundle
cap aborted!
bundle stdout: Nothing written
bundle stderr: Nothing written
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/command.rb:94:in `exit_status='
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:147:in `block (2 levels) in _execute'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:149:in `block in _execute'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:20:in `block (4 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/abstract.rb:81:in `within'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:19:in `block (3 levels) in <top (required)>'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `run'
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => bundler:install
(See full trace by running task with --trace)

我使用 capistrano 2,但是当我将 capistrano 更新到版本 3 时,我的两个 ROR 4 应用程序出现此错误。为什么 capistrano 使用'/bin/myapp_bundle'?

----------- 更新 -----------

@mpapis 帮我解决:

cap productiom rvm:hook deploy

它正在工作,但是当我使用 mpapis 帮助创建自定义任务时:

namespace :whenever do
  desc "Update application's crontab entries using Whenever"
  task :update_crontab do
    on roles(:app) do
      execute  "cd /home/deployer/apps/fxfinvis/current/ && bundle exec whenever -w RAILS_ENV=#{fetch :rails_env}"
    end
  end
  before :update_crontab, 'rvm:hook'
end
before "deploy:finishing", "whenever:update_crontab"
# If anything goes wrong, undo.
after "deploy:finishing_rollback", "whenever:update_crontab"

我也有同样的错误:

cap production whenever:update_crontab
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /usr/local/share/npm/lib/node_modules in PATH, mode 040777
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler.rb:284: warning: Insecure world writable dir /usr/local/share/npm/lib/node_modules in PATH, mode 040777
 INFO [1372d0e2] Running cd /home/deployer/apps/fxfinvis/current/ && bundle exec whenever -w RAILS_ENV=production on 134.19.136.197
DEBUG [1372d0e2] Command: cd /home/deployer/apps/fxfinvis/current/ && bundle exec whenever -w RAILS_ENV=production
cap aborted!
cd /home/deployer/apps/fxfinvis/current/ && bundle exec whenever -w RAILS_ENV=production stdout: Nothing written
cd /home/deployer/apps/fxfinvis/current/ && bundle exec whenever -w RAILS_ENV=production stderr: Nothing written
/Users/quatermain/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.1.0/lib/sshkit/command.rb:94:in `exit_status='
....

【问题讨论】:

    标签: ruby-on-rails-4 rvm capistrano bundle bundler


    【解决方案1】:

    你需要运行:

    cap production rvm:hook bundler:install
    

    还将whenever:update_cron 任务更改为:

    within current_path do
      execute :bundle, "exec whenever -w RAILS_ENV=#{fetch :rails_env}"
    end
    

    我不完全确定 :current_path - 但应该可以。

    【讨论】:

    • 谢谢,它正在工作。但是我在执行我的自定义上限任务时遇到了同样的问题(执行'cat Gemfile')
    • 在任何需要 rvm ruby​​ 的自定义任务之前,您需要运行 rvm:hook 的 gem 文档
    • 谢谢,我更新了我的问题,因为我在自定义任务之前添加了 rvm:hook 后遇到了同样的问题。顺便说一句:谢谢你的 RVM
    • 它在 current_path do ... end
    【解决方案2】:

    这对我有用:

    ruby set :default_env, { rvm_bin_path: '~/.rvm/bin' }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      相关资源
      最近更新 更多