Capistrano

Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH. It uses a simple DSL (borrowed in part from Rake, rake.rubyforge.org/) that allows you to define tasks, which may be applied to machines in certain roles. It also supports tunneling connections via some gateway machine to allow operations to be performed behind VPN’s and firewalls.

Capistrano was originally designed to simplify and automate deployment of web applications to distributed environments, and so it comes with many tasks predefined for that (“update_code” and “deploy”, for instance).

Dependencies

Capistrano depends upon the Net::SSH library by Jamis Buck (net-ssh.rubyforge.org). Net::SSH itself depends on the Needle library (needle.rubyforge.org), also by Jamis Buck.

Assumptions

In keeping with Rails’ “convention over configuration”, Capistrano makes several assumptions about how you will use it (most, if not all, of which may be explicitly overridden):

  • You are writing web applications and want to use Capistrano to deploy them.

  • You are using Ruby on Rails (www.rubyonrails.com) to build your apps.

  • You are using Subversion (subversion.tigris.org/) to manage your source code.

  • You are running your apps using FastCGI, together with Rails’ spinner/reaper utilities.

As with the rest of Rails, if you can abide by these assumptions, you can use Capistrano “out of the box”. If any of these assumptions do not hold, you’ll need to make some adjustments to your deployment recipe files.

Usage

More documentation is always pending, but you’ll want to see the user manual for detailed usage instructions. (The manual is online at manuals.rubyonrails.org/read/book/17).

In general, you’ll use Capistrano as follows:

  • Create a deployment recipe (“deploy.rb”) for your application. You can use the sample recipe in examples/sample.rb as a starting point.

  • Use the cap script to execute your recipe (see below).

Use the cap script as follows:

cap -vvv someaction

By default, the script will look for a file called one of config/deploy, config/deploy.rb, capistrano, or capistrano.rb. You can the -v switch multiple times (as shown) to increase the verbosity of the output. The someaction text indicates which action to execute.