3

デプロイ時にNet::SSH::ChannelOpenFailedエラーが発生し (エラーは capistrano の assets:precompile タスクで発生します - 以下の assets.rb を参照)、2 つのサーバーのうち 1 つのサーバーでのみ発生します。どちらのサーバーにも同様のインストールがあります (Gentoo カーネル 3.6、Ruby 1.9.3、rails gem 3.2.12、net-ssh gem 2.6.5) が、このエラーが発生するのは 1 つだけです。

> cap -vv deploy:update_code

  servers: ["31.131.19.xxx", "network.local"]
  [network.local] executing command
  [31.131.19.xxx] executing command
  command finished in 269ms
* executing "ls -x /home/deployer/apps/network/releases"
  servers: ["31.131.19.xxx"]
  /usr/local/lib64/ruby/gems/1.9.1/gems/net-ssh-2.6.5/lib/net/ssh/connection/channel.rb:524:in
  `do_open_failed': open failed (1) (Net::SSH::ChannelOpenFailed)

cap deploy:checkうまくいきます。新規デプロイ (本番サーバーから以前のリリースをすべて削除) は問題なく実行できます。エラーがスローされた直後に移行を実行すると (資産: プリコンパイル時)。

ls -x /home/deployer/apps/network/releases何が起こっているのか、特にこれがどこから来たのか、assets:precompile タスクで何をしているのか、なぜ上記のエラーが発生するのかを理解するのに役立つログや何かが見つかりません。

v8 と therubyracer の gem が同期していないという考えがありましたがbundle exec rake assets:precompile、サーバー上で実行すると、これらの gem が更新されていることが証明されました。

どこからデバッグを開始しますか?

assets.rb(抜粋)

 task :precompile, :roles => assets_role, :except => { :no_release => true } do
   logger.info "... Runs okay until this point ..."
   run <<-CMD.compact
     cd -- #{latest_release.shellescape} &&
     #{rake} RAILS_ENV=#{rails_env.to_s.shellescape} #{asset_env} assets:precompile &&
     cp -- #{shared_path.shellescape}/assets/manifest.yml #{current_release.shellescape}/assets_manifest.yml
   CMD
   logger.info "... Never gets here ..."
 end

deploy.rb

require 'bundler/capistrano'
load 'lib/deploy/seed'

set :application, "network"
set :rails_env, "production"

server "31.131.19.xxx", :web, :app, :db, primary: true
server "network.local", :web, :app, :db, primary: true

set :bundle_roles, [:app]
set :normalize_asset_timestamps, false

set :user, "deployer"
set :group, "deployer"

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

set :deploy_via, :remote_cache
set :copy_exclude, ".git/*"

set :use_sudo, false
set :scm, "git"

set :repository, "git@bitbucket.org:danchenkov/#{application}.git"

set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"

after 'deploy:update_code', :roles => :app do
  run "rm -f #{current_release}/config/database.yml"
  run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml"
end

after "deploy", "deploy:cleanup"

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/vhosts/#{application}.upstream.conf"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    run "mkdir -p #{shared_path}/log"
    run "mkdir -p #{shared_path}/pids"
    run "mkdir -p #{shared_path}/sockets"
    put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

Gemfile

source 'https://rubygems.org'

gem 'rails'

gem 'pg'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'libv8-3.11.8.13-x86_64-linux', :platform => :ruby
  gem 'therubyracer', :platform => :ruby, :require => 'v8'
  gem 'uglifier'
  gem 'bootstrap-sass'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
gem 'bcrypt-ruby'

# Deploy with Capistrano
gem 'capistrano'

# Style
gem 'haml-rails'
gem 'simple_form'

# Templates
gem 'redcarpet'

# Attachments
gem 'rmagick'
gem 'carrierwave'

# Pagination
gem 'kaminari'

# Auth & Roles
gem 'devise'
gem 'cancan'

gem 'unicode'
gem 'unicorn', :platform => :ruby
4

1 に答える 1

0

これはここでは問題ではありませんが、ローカルの ruby​​ をサーバーと同じバージョンに更新して、次を実行することをお勧めします。

gem update --system (on both: server and local machines)

問題については、次を試してください。

cat ~/.ssh/id_rsa.pub | ssh deployer@xxx.xxx.xxx.xxx 'cat >> ~/.ssh/authorized_keys'

これにより、パスワードを入力せずにサーバーに ssh できるようになり、ローカル マシンにサーバーの ssh が保存されます。以前にこれを行ったことがある場合は、この ssh を publickeys から削除して、このコマンドを再実行してみてください。

于 2013-05-05T06:38:37.127 に答える