gpt4 book ai didi

ruby-on-rails - 如何调试 cap 部署错误并查找 Net::SSH::ChannelOpenFailed 网络错误的日志文件?

转载 作者:行者123 更新时间:2023-12-02 09:08:59 26 4
gpt4 key购买 nike

我在部署时遇到 Net::SSH::ChannelOpenFailed 错误(错误发生在 capistrano 的 asset:precompile 任务 - 请参阅下面的 asset.rb),并且仅在两台服务器中的一台服务器上。两台服务器都有类似的安装(Gentoo kernel 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 运行良好。全新部署(从生产服务器中删除所有以前的版本)不会出现任何问题。抛出错误后立即运行迁移(在 asset:precompile 处)。

我找不到任何日志或任何可以帮助我了解正在发生的事情的内容,特别是这个 ls -x/home/deployer/apps/network/releases 来自哪里,什么它是在 asset:precompile 任务中执行的吗?为什么会出现上述错误。

我知道 v8 和 therubyracer gems 不同步,但在服务器上运行 bundle exec rake assets:precompile 证明这些 gems 已更新。

从哪里开始调试?

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

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

最佳答案

这不是问题,但你最好将本地 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,然后重新运行此命令。

关于ruby-on-rails - 如何调试 cap 部署错误并查找 Net::SSH::ChannelOpenFailed 网络错误的日志文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15220453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com