at posts/single.html

Debian Sarge で Capistrano 1.4.0 を動かす

Debian Sarge で Capistrano が動かないという昨日の話の続き。

  • Debian を sid (unstable) にする
  • Debian をやめて Ubuntu にする
  • いっそ Mac OS X にする

とか色々考えた挙句、結局Re: Capistrano and Media Temple (gs) - Grid Serverに書かれている方法で Capistrano のソースを修正して対応した。

$ cd /usr/lib/ruby/gems/1.8/gems/capistrano-1.4.0/lib/capistrano/scm
$ diff -u subversion.rb.org subversion.rb
--- subversion.rb.org   2007-02-20 00:27:50.445393872 +0900
+++ subversion.rb       2007-02-20 00:29:00.804370024 +0900
@@ -20,7 +20,7 @@
       def latest_revision
         @latest_revision ||= begin
             configuration.logger.debug "querying latest revision..."
-            match = svn_log(configuration.repository).scan(/r(\d+)/).first or
+            match = svn_info(".").scan(/Revision: (\d+)/).first or
               raise "Could not determine latest revision"
             match.first
           end
@@ -87,6 +87,10 @@
           `svn log #{authorization} -q --limit 1 #{path}`
         end

+        def svn_info(path)
+          `svn info #{path}`
+        end
+
         def svn_password
           configuration[:svn_password] || configuration[:password]
         end

svn log --limit 1 の代わりに svn info を使ってリビジョン番号を取得している。 なるほど。

これでもう一度、 deploy に挑戦。

$ cap deploy
  * executing task deploy
  * executing task update
 ** transaction: start
  * executing task update_code
  * querying latest revision...
  * executing "if [[ ! -d /home/machu/deploy/releases/20070219153034 ]]; then\n              svn co   -q -r85 ssh+svn://example.com/svn/test_capistrano /home/machu/deploy/releases/20070219153034 &&\n              (test -e /home/machu/deploy/revisions.log || (touch /home/machu/deploy/revisions.log && chmod 666 /home/machu/deploy/revisions.log)) && echo `date +\"%Y-%m-%d %H:%M:%S\"` $USER 85 20070219153034 >> /home/machu/deploy/revisions.log;\n            fi"
    servers: ["localhost"]
    [localhost] executing command
    command finished

      (中略)

 ** transaction: commit
  * executing task restart
  * executing "sudo  /home/machu/deploy/current/script/process/reaper"
    servers: ["localhost"]
    [localhost] executing command
 ** [out :: localhost] Couldn't find any pid file in '/home/machu/deploy/current/tmp/pids' matching 'dispatch.[0-9]*.pid'
 ** [out :: localhost] (also looked for processes matching "/home/machu/deploy/current/public/dispatch.fcgi")
    command finished

今度は成功したっぽい。ただ、 deploy 先でサーバが動いていなかったので、サーバの再起動には失敗してる。 まぁ、これは今回はいい。

次に、 deploy 先を見てみる。

$ ls -l ~/deploy
total 12
lrwxrwxrwx  1 machu machu   42 Feb 20 00:30 current -> /home/machu/deploy/releases/20070219153034/
drwxrwxr-x  3 machu machu 4096 Feb 20 00:30 releases/
-rw-rw-rw-  1 machu machu   44 Feb 20 00:30 revisions.log
drwxrwxr-x  5 machu machu 4096 Feb 18 16:18 shared/

current という symlink が、 releases に格納された最新のバージョンを指すようになっている。 バージョンアップしても、最新版は常に current に入っている。

TextDrive の場合、これまでは

~/web/public/

に配置していたコンテンツが、

~/web/public/current/

になっちゃう訳か。 眠くなってきたので、今日はここまで。

関連する日記