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 originally came bundled with a set of tasks designed for deploying Rails applications. The deployment tasks are now (as of Capistrano 2.0) opt-in and require clients to explicitly put “load ‘deploy’” in their recipes.

2.5.6 Warning

_Warning_: while every care has been taken to make sure you do not feel too much disruption from existing deploys when upgrading to 2.5.6 unless you alter your capfile (see “New Style Capification” towards the end of the readme for more) will require a couple more lines to keep compatibility with old recipes.

The changes in 2.5.6 include bug fixes, but importantly also remove a number of rails assumptions. This has been done both to ensure that people who aren’t deploy Rails applications aren’t put-off using Capistrano, and also that those of us that do use Rails have a choice about certain things. (starting our app, restarting it, stopping it, do we want cap to manage migrations, etc..)

As a result failure to read this document thoroughly could lead to problems, if you do install 2.5.6 and your recipe breaks, please either uninstall the gem and file a bug report (we will try to fix them within hours if received through our lighthouse app account.) or invoke cap in the following way to dictate which version you wish to use:

cap _2.5.5_ deploy
cap _2.5.5_ staging my:task:here
cap _2.5.5_ -vT
cap _2.5.6_ -vT

Please open issues on the bug tracer at capistrano.lighthouseapp.com/ if you experience problems

Documentation

We know that documentation is something that really lets us down, that’s why there is a repository for a handbook below, please open an issue on it if you would like something documented:

If you prefer the wiki style of documentation, then please see our wiki

Due to a failure of MySQL with PHP, searches shorter than three characters are all but ignored, we’re going to rectify this, but in the meantime, please do what you can, tickets opened on the handbook for the wiki will be answered too, so please let us know if you don’t find something you needed.

We take bug reports via lighthouse app, you can find that page here:

More documentation is on the way, if in doubt try opening the recipes that ship with capistrano.

DEPENDENCIES

If you want to run the tests, you’ll also need to have the following dependencies installed:

ASSUMPTIONS

Capistrano is “opinionated software”, which means it has very firm ideas about how things ought to be done, and tries to force those ideas on you. Some of the assumptions behind these opinions are:

  • You are using SSH to access the remote servers.

  • You either have the same password to all target machines, or you have public keys in place to allow passwordless access to them.

Do not expect these assumptions to change.

USAGE

In general, you’ll use Capistrano as follows:

  • Create a recipe file (“capfile” or “Capfile”).

  • Use the cap script to execute your recipe.

Use the cap script as follows:

cap sometask

By default, the script will look for a file called one of capfile or Capfile. The someaction text indicates which task to execute. You can do “cap -h” to see all the available options and “cap -T” to see all the available tasks.

Capistrano Edge

If you want to try Capistrano code that hasn’t been formerly released yet, this repository now includes a gemspec that should build what you need, here’s how to get a copy:

git clone git://github.com/capistrano/capistrano.git capistrano-capistrano
cd capistrano-capsitrano
gem build capistrano.gemspec
sudo gem install capistrano-*.gem

This will install the most recent version of capistrano and make it available for both cap, and capify.

We recommend that you capify a new test application, as the resulting files are different to previous versions.

If you have multiple versions of capistrano (or indeed any gem with a binary) installed, you can call ‘cap` like so to specify which version to use:

cap _2.5.5_ deploy
cap _2.5.6_ deploy:setup

New Style Capification

When calling ‘capify` on a new application, the result will look something like the following, this is a big change to previous versions, please take this as a warning and read the following thoroughly:

set :application, "set your application name here"
set :repository,  "set your repository location here"

# If you have previously been relying upon the code to start, stop 
# and restart your mongrel application, or if you rely on the database
# migration code, please uncomment the lines you require below

# If you are deploying a rails app you probably need these:

# load 'ext/rails-database-migrations.rb'
# load 'ext/rails-shared-directories.rb'

# There are also new utility libaries shipped with the core these 
# include the following, please see individual files for more
# documentation, or run `cap -vT` with the following lines commented
# out to see what they make available.

# load 'ext/spinner.rb'              # Designed for use with script/spin
# load 'ext/passenger-mod-rails.rb'  # Restart task for use with mod_rails
# load 'ext/web-disable-enable.rb'   # Gives you web:disable and web:enable

# If you aren't deploying to /u/apps/\#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/\#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion
# see a full list by running "gem contents capistrano | grep 'scm/'"

role :web, "your web-server here"

When adding or removing extensions, where you have previously tested a ‘deploy:setup` we recommend that you perform another, especially for example when adding the rails-shared-directory code.

LICENSE:

(The MIT License)

Copyright © 2005-2008 Jamis Buck <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.