capistranoメモ

ディレクトリ構造

/path/to/project
    /capistrano
        /current -> /path/to/project/capistrano/releases/20070220043413
        /releases
            /20070220043413
                /app
                ・・・
                /log -> /path/to/project/capistrano/shared/log
                /public
                    ・・・
                    /system -> /path/to/project/capistrano/shared/system
                /tmp
                    /pids -> /path/to/project/capistrano/shared/pids
        /shared
            /log
            /pids
            /system
    /trunk
        /app
        ・・・

とりあえず、こんな感じで使ってみてます。作り方はこんな感じ。

$ mkdir /path/to/project
$ cd /path/to/project
$ svn checkout /url/to/repository/・・・/trunk ./trunk
$ cap setup

あ、config/deploy.rb には予め適切な設定を入れておいてください。

mongrel_cluster.yml

--- 
cwd: /path/to/project/capistrano/current
port: "8000"
environment: production
address: localhost
pid_file: tmp/pids/dispatch.pid
servers: 3

ポイントはpid_fileの指定。指定しないと/path/to/project/capistrano/current/logに出力するので、

rake deploy

で自動的に再起動してくれません。ちなみに、dispatch.[0-9]*.pid という形式じゃないとダメみたいです。

疑問点

とりあえず、これだけでも便利かなーという気はしますが、いくつか疑問が。

  • 複数のRailsアプリなどを一つのリリースに入れて、それぞれdeployしたい時って、どんな風にディレクトリを作ればいいの?
  • config/deploy.rbにはsvnのURLとしてtrunkのをとりあえず設定したので、リリースによって変更したいんだけどどうするべき?

/path/to/project/branches/RB-xxxxx を自分でチェックアウトしてそこから rake deployするべきなのかな?

  • tmp/sessions は shared/sessions とかにsymlinkしてくれないの?

capistranoのrakeタスク

rake deploy                         # Push the latest revision into production (delegates to remote:deploy)
rake remote:cleanup                 # Removes unused releases from the releases directory.
rake remote:cold_deploy             # Used only for deploying when the spinner isn't running.
rake remote:deploy                  # A macro-task that updates the code, fixes the symlink, and restarts the application servers.
rake remote:deploy_with_migrations  # Similar to deploy, but it runs the migrate task on the new release before updating the symlink.
rake remote:diff_from_last_deploy   # Displays the diff between HEAD and what was last deployed.
rake remote:disable_web             # Disable the web server by writing a "maintenance.html" file to the web servers.
rake remote:enable_web              # Re-enable the web server by deleting any "maintenance.html" file.
rake remote:exec                    # Execute a specific action using capistrano
rake remote:invoke                  # A simple task for performing one-off commands that may not require a full task to be written for them.
rake remote:migrate                 # Run the migrate rake task.
rake remote:restart                 # Restart the FCGI processes on the app server.
rake remote:rollback                # A macro-task that rolls back the code and restarts the application servers.
rake remote:rollback_code           # Rollback the latest checked-out version to the previous one by fixing the symlinks and deleting the current release from all servers.
rake remote:set_permissions         # Sets group permissions on checkout.
rake remote:setup                   # Set up the expected application directory structure on all boxes
rake remote:shell                   # Begin an interactive Capistrano session.
rake remote:show_tasks              # Enumerate and describe every available task.
rake remote:spinner                 # Start the spinner daemon for the application (requires script/spin).
rake remote:symlink                 # Update the 'current' symlink to point to the latest version of the application's code.
rake remote:update                  # Updates the code and fixes the symlink under a transaction
rake remote:update_code             # Update all servers with the latest release of the source code.
rake remote:update_current          # Update the currently released version of the software directly via an SCM update operation
rake rollback                       # Rollback to the release before the current release in production (delegates to remote:rollback)

rollback便利そう、ミスったりしたときとか。rake remote:disable_web/enable_web とか。
rake remote:diff_from_last_deploy でリリースにちゃんと変更箇所が含まれているかどうかを確認したりとか。