LoginSignup
9
8

More than 5 years have passed since last update.

Capistranoのハングアップ防止

Posted at

Capistranoのハングアップ防止

問題

Capistranoで長い時間がかかる処理があるとハングアップしてしまう。
何のエラーメッセージも出ない。

原因

SSHサーバのタイムアウトでコネクションが切れてしまうとCapistrano側で検知できないらしくずっと待ってしまうようだ。

対策

NULLパケットを定期的に飛ばす設定ができれば解決する。
この設定はサーバ側でもクライアント側でもできる。

クライアント側で設定

普通に考えると~/.ssh/configにServerAliveInterval 60とか設定したくなるけど、RubyのNet::SSHはこの設定は見てくれないらしい。
CapistranoからNet:SSHにオプション渡してくれる口があるので、それをつかう。

deploy.rb
set :ssh_options, :keepalive => true

あるいは

deploy.rb
server "example.com",
       :user => "deployer",
       :roles => %w(web app),
       :ssh_options => {
         :keepalive => true,
         :keepalive_interval => 60 #seconds
       }

サーバ側で設定

サーバ側のopensshの設定でやる場合は下記。

/etc/ssh/sshd_config
ClientAliveInterval 30
ClientAliveCountMax 10

調べるとこっちの方法がたくさんでてくるんだけど、デプロイツールのためにサーバ設定変えるのって本末転倒感あるので個人的にはクライアント側の対応を推奨。

参考

https://stackoverflow.com/questions/11570209/capistrano-deploy-timeout
https://github.com/capistrano/rails/issues/55

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8