capistrano部署错误 - 新手

时间:2013-10-30 18:00:19

标签: ruby terminal capistrano

我是ruby的新手,目前在使用capistrano进行部署时遇到了问题。低于我得到的错误。

cap aborted!
Operation timed out - connect(2)
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `initialize'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `open'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `block in initialize'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `initialize'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `new'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `start'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:156:in `ssh'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:109:in `block in _execute'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/abstract.rb:75:in `within'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.0/lib/capistrano/tasks/git.rake:44:in `block (3 levels) in <top (required)>'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `run'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:create_release => git:update
(See full trace by running task with --trace)

2 个答案:

答案 0 :(得分:0)

不是解决方案,而是解决方法的解释:

Capistrano 3,以及它的sshkit,不会重用现有的SSH连接,而是为每个任务开始一个新的连接(参见https://github.com/capistrano/sshkit/issues/34)。

某些服务器(分别是防火墙)似乎会阻止新的连接请求,如果它们来得快或者打开连接太多。

解决方案:

  • 修复SSHKit / Capistrano以重用连接
  • 配置您的服务器/防火墙以允许大量并行ssh会话(对于简单的rails应用程序大约15个)
  • 在下面使用我的黑客(免责声明:不,不要使用它):

我们将在gems / sshkit-1.1.0 / lib / sshkit / backends / netssh.rb中扩展(monkeypatch)执行方法。这可以通过Capfile完成:

# Overwrite execute method to avoid timeouts
class SSHKit::Backend::Netssh
  def execute(*args)
    _execute(*args).success?
  rescue Errno::ETIMEDOUT
    @tries ||= 0
    raise "Nope, no way" if @tries > 5
    puts "Timeout. yeah. Try it again (#{@tries})" 
    sleep 5
    @tries += 1
    execute(*args)
    end
end

这让服务器有机会呼吸......

答案 1 :(得分:0)

Capistrano现在使用SSH连接池: https://github.com/capistrano/sshkit/pull/70