Use the left/right arrow keys to navigate, 's' to enable/disable scrolling.

System Automation

with

Capistrano

Capistrano

  • What is it?
  • When it can be useful?
  • Install
  • Create your first script
  • Config files
  • Run
  • Debug
  • Advanced
  • Link

What is it?

Ruby internal DSL (Domain Specific Language)

Automate System Administration Tasks

Run shell commands over SSH

Upload and Download small files (over SSH)

When it can be useful?

Application Deploy

Management Tasks

System Bootstraping

When it can be DANGEROUS?

Remember, with great power comes great responsibility

(Uncle Ben - Spiderman)

Common Use Cases

Check servers uptime

Check mail queues

Run a script as workaround to an incident

Install/Uninstall packages

Install capistrano

prereqs

ruby

ruby-dev

rubygems


# gem install capistrano
...

# capify 
Please specify the directory to capify, e.g. `capify .'

Create your first Capistrano script


$ mkdir hello_capistrano
$ capify hello_capistrano
[add] writing 'hello_capistrano/Capfile'
[add] making directory 'hello_capistrano/config'
[add] writing 'hello_capistrano/config/deploy.rb'
[done] capified!

hello_capistrano ----> Capfile
                    |
                    --> config ---> deploy.rb

Capfile

config/deploy.rb

Run


hello_capistrano$ cap -T
cap deploy               # Deploys your project.
cap deploy:check         # Test deployment dependencies.
cap deploy:cleanup       # Clean up old releases.
cap deploy:cold          # Deploys and starts a `cold' application.
cap deploy:migrate       # Run the migrate rake task.
cap deploy:migrations    # Deploy and run pending migrations.
cap deploy:pending       # Displays the commits since your last deploy.
cap deploy:pending:diff  # Displays the `diff' since your last deploy.
cap deploy:restart       # Restarts your application.
cap deploy:rollback      # Rolls back to a previous version and restarts.
cap deploy:rollback:code # Rolls back to the previously deployed version.
cap deploy:setup         # Prepares one or more servers for deployment.
cap deploy:start         # Start the application servers.
cap deploy:stop          # Stop the application servers.
cap deploy:symlink       # Updates the symlink to the most recently deployed ...
cap deploy:update        # Copies your project and updates the symlink.
cap deploy:update_code   # Copies your project to the remote servers.
cap deploy:upload        # Copy files to the currently deployed version.
cap deploy:web:disable   # Present a maintenance page to visitors.
cap deploy:web:enable    # Makes the application web-accessible again.
cap invoke               # Invoke a single command on the remote servers.
cap shell                # Begin an interactive Capistrano session.

Some tasks were not listed, either because they have no description,
or because they are only used internally by other tasks. To see all
tasks, type `cap -vT'.

Extended help may be available for these tasks.
Type `cap -e taskname' to view it.

cap invoke

send simultaneously one command to all servers


$ cap invoke COMMAND="echo 'Hello World'"
$ cap invoke COMMAND="echo 'Hello World'" SUDO=1

cap shell

all connections that are established during the duration of the shell session are cached and reused

Disable Rails Stuff in the Capfile

Minimal capistrano scripting

Advanced Capistrano

refactoring, debugging and integrating

capistrano IS ruby

(define functions and/or classes)

debug capistrano scripts as ruby applications

and

you can use it as a library

CAPISTRANO is NOT a Configuration Management system

it’s a system automation tools

for full Configuration Management evaluate a complete solution as

CFENGINE, BCFG2, Puppet or Chef

Copyright 2010 - Alca Soc. Coop.


http://learn.alcacoop.it - learn@alcacoop.it



released under CreativeCommons 2.5 by-nc-sa