Ruby internal DSL (Domain Specific Language)
Automate System Administration Tasks
Run shell commands over SSH
Upload and Download small files (over SSH)
Application Deploy
Management Tasks
System Bootstraping
(Uncle Ben - Spiderman)
Check servers uptime
Check mail queues
Run a script as workaround to an incident
Install/Uninstall packages
ruby
ruby-dev
rubygems
# gem install capistrano
...
# capify
Please specify the directory to capify, e.g. `capify .'
$ 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
1 | load 'deploy' if respond_to?( :namespace ) # cap2 differentiator |
2 | Dir [ 'vendor/plugins/*/recipes/*.rb' ]. each { |plugin| load(plugin) } |
3 |
4 | load 'config/deploy' # remove this line to skip loading any of the default tasks |
01 | set :application , "set your application name here" |
02 | set :repository , "set your repository location here" |
03 |
04 | set :scm , :subversion |
05 | # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` |
06 |
07 | role :web , "your web-server here" # Your HTTP server, Apache/etc |
08 | role :app , "your app-server here" # This may be the same as your `Web` server |
09 | role :db , "your primary db-server here" , :primary => true # This is where Rails migrations will run |
10 | role :db , "your slave db-server here" |
11 |
12 | # If you are using Passenger mod_rails uncomment this: |
13 | # if you're still using the script/reapear helper you will need |
15 |
16 | # namespace :deploy do |
17 | # task :start {} |
18 | # task :stop {} |
19 | # task :restart, :roles => :app, :except => { :no_release => true } do |
20 | # run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" |
21 | # end |
22 | # end |
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.
send simultaneously one command to all servers
$ cap invoke COMMAND="echo 'Hello World'"
$ cap invoke COMMAND="echo 'Hello World'" SUDO=1
all connections that are established during the duration of the shell session are cached and reused
1 | # load 'deploy' if respond_to?(:namespace) # cap2 differentiator |
2 | Dir [ 'vendor/plugins/*/recipes/*.rb' ]. each { |plugin| load(plugin) } |
3 |
4 | load 'config/deploy' # remove this line to skip loading any of the default tasks |
01 | set :application , "My Big Service" |
02 | set :user , "root" |
03 |
04 | role :web_server , "web.mydomain" |
05 | role :db_server , "db.mydomain" |
06 |
07 | desc "Hello World task" |
08 | namespace :hello do |
09 | task :world , :roles => [ :db_server ] do |
10 | puts "Hello world, from capistrano" |
11 | run "ls -l" |
12 | end |
13 | end |
refactoring, debugging and integrating
(define functions and/or classes)
it’s a system automation tools
for full Configuration Management evaluate a complete solution as
Homepage:
http://www.capify.org/index.php/Capistrano
Capistrano Handbook:
http://github.com/leehambley/capistrano-handbook/blob/master/index.markdown
Getting Started:
http://www.capify.org/index.php/Getting_Started
Railsless Capistrano Extension:
http://github.com/leehambley/railsless-deploy/
Deploy Drupal with Capistrano: