デプロイツールを色々選定してて、Fabric を試してみようとサンプルを作った。
#!/usr/bin/env python # -*- coding: utf-8 -*- from fabric.api import local, env, run env.user = 'root' env.hosts = ['192.168.1.2'] def local_date(): local('/bin/date') def remote_date(): run('/bin/date')
これで以下のようなコマンドを入力。
$ fab remote_date
$ fab remote_date [192.168.1.2] run: /bin/date Password for root@192.168.1.2: [192.168.1.2] out: 2010年 9月 2日 木曜日 22:03:51 JST Done. Disconnecting from 192.168.1.2... done.
で、このリモートサーバとのコネクションの切断がめちゃくちゃ遅い。
色々調べた結果オフィシャルのドキュメントの FAQ に以下のように書いてた。
If you’re on Python 2.6.5, the issue may be a change in that version of Python which triggered a latent bug in our SSH layer, Paramiko. Fabric currently bundles Paramiko 1.7.4, but users report that upgrading to Paramiko 1.7.6 (which will overwrite the bundled version) seems to fix the problem.
http://docs.fabfile.org/0.9.1/faq.html#fabric-sometimes-takes-a-long-time-to-disconnect-at-the-end-of-a-session-why
Paramiko 1.7.4 に原因があるからバージョンあげろって書いてあるので、
$ pip install -U Paramiko
を実行したところ、コネクションの切断が早くなった。
ところで、MacOSX でローカルマシンの日付を出す local_date を実行したら、何も結果が帰ってこなかった。
$ fab local_date [localhost] run: /bin/date Done.
何が原因なんだろ…。