title: How to debug a cap deploy error and find log files for Net::SSH::ChannelOpenFailed network error?
body: <p>I run into <em>Net::SSH::ChannelOpenFailed</em> error when deploying (the error occurs at capistrano's assets:precompile task - see assets.rb below) and only on one server of two. Both servers have similar installation (Gentoo kernel 3.6, Ruby 1.9.3, rails gem 3.2.12, net-ssh gem 2.6.5), but only one gives me this error.</p>
  
  <pre><code>&gt; 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)
  </code></pre>
  
  <p><code>cap deploy:check</code> runs well. Fresh deploy (with all previous releases removed from the production server) goes without problems. Running migrations immediately after throws the error (at assets:precompile).</p>
  
  <p>I can't find any logs or anything that would help me to understand what is going on, particularly where this <code>ls -x /home/deployer/apps/network/releases</code> came from, what is it doing in assets:precompile task and why do I get the error above.</p>
  
  <p>I had an idea of v8 and therubyracer gems being out of sync, but running <code>bundle exec rake assets:precompile</code> on the server proved these gems are updated.</p>
  
  <p>Where do I start debugging?</p>
  
  <p><strong>assets.rb (excerpt)</strong></p>
  
  <pre><code> task :precompile, :roles =&gt; assets_role, :except =&gt; { :no_release =&gt; true } do
     logger.info "... Runs okay until this point ..."
     run &lt;&lt;-CMD.compact
       cd -- #{latest_release.shellescape} &amp;&amp;
       #{rake} RAILS_ENV=#{rails_env.to_s.shellescape} #{asset_env} assets:precompile &amp;&amp;
       cp -- #{shared_path.shellescape}/assets/manifest.yml #{current_release.shellescape}/assets_manifest.yml
     CMD
     logger.info "... Never gets here ..."
   end
  </code></pre>
  
  <p><strong>deploy.rb</strong></p>
  
  <pre><code>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 =&gt; :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
  </code></pre>
  
  <p><strong>Gemfile</strong></p>
  
  <pre><code>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 =&gt; :ruby
    gem 'therubyracer', :platform =&gt; :ruby, :require =&gt; '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 &amp; Roles
  gem 'devise'
  gem 'cancan'
  
  gem 'unicode'
  gem 'unicorn', :platform =&gt; :ruby
  </code></pre>