1.20. Capistrano

Capistrano is a standalone utility that is used for automating tasks via SSH on remote servers. It was originally created by Jamis Buck (http://jamisbuck.org) and developed to help manage application deployment processes.

Capistrano uses tasks, similar to Rake. These tasks can include commands that are executed on servers. In addition, you can define roles for your servers and designate certain tasks to specific roles.

One of the common misunderstandings of Capistrano is where it needs to be installed. Because Capistrano runs commands via SSH, it needs to be installed only on the machines from which the server is being deployed.

Capistrano is a gem and can be installed by running:

sudo gem install capistrano

Two files are required to use Capistrano in a Rails application. You can generate these files by using the capify script. For example, if you are already in the Rails root folder:

$ capify .
[add] writing `./Capfile'
[add] writing `./config/deploy.rb'
[done] capified!

To view the available tasks, type:

cap -T

To view detailed descriptions of a specific task, you can use:

cap -e [task] # Example: cap -e deploy:cold

The default tasks are as follows (and can be run with cap [task]):


Deploys your project. This calls both update and restart. Note that this will generally only work for applications that have already been deployed once. For a cold deploy, you’ll want to take a look at the deploy:cold task, which handles the cold start specifically.


Tests deployment ...

Get Rails Pocket Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.