我在部署时遇到Net::SSH::ChannelOpenFailed错误(错误发生在 capistrano 的 assets:precompile 任务 - 请参阅下面的 assets.rb )并且仅在两个服务器上。两台服务器都有类似的安装(Gentoo 内核 3.6、Ruby 1.9.3、rails gem 3.2.12、net-ssh gem 2.6.5),但只有一个给我这个错误。
> 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
运行良好。全新部署(从生产服务器中删除所有以前的版本)没有问题。抛出错误后立即运行迁移(在 assets:precompile 处)。
我找不到任何日志或任何可以帮助我了解正在发生的事情的东西,特别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
部署.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
宝石文件
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