SlideShare a Scribd company logo
1 of 21
Download to read offline
Capistrano 2
  Rocks my world
       Graeme Mathieson, Rubaidh Ltd
           <mathie@rubaidh.com>
http://woss.name/ & http://www.rubaidh.com/
What’s the plan?
•   So, what is it?

•   Installing 2.0

•   What’s new in Cap 2?

•   Stuff I’ve done with cap 2
What is it?
•   A Rails deployment tool

•   A Java deployment tool

•   A troubleshooting tool

•   An ad-hoc systems management tool
Without a Capfile

$ cap2 invoke COMMAND=uname HOSTS=macallan,cardhu
   * executing `invoke'
   * executing quot;unamequot;
     servers: [quot;macallanquot;, quot;cardhuquot;]
     [macallan] executing command
     [cardhu] executing command
  ** [out :: cardhu] SunOS
  ** [out :: macallan] Linux
     command finished
$
Using cap shell
$ cap2 shell HOSTS=balvenie,cardhu
  * executing `shell'
cap> uptime
[establishing connection(s) to balvenie, cardhu]
 ** [out :: balvenie] 19:33:52 up 211 days, 7:25, 1 user, load
average: 0.06, 0.07, 0.07
 ** [out :: cardhu] 7:33pm up 10 day(s), 6:47, 2 users, load
average: 0.18, 0.16, 0.15
cap> uname -r
 ** [out :: balvenie] 2.4.21-47.0.1.EL
 ** [out :: cardhu] 5.10
cap>
Installing 2.0
$   gem   install -y net-ssh net-ftp highline
[   ...   ]
$   gem   install -s http://gems.rubyonrails.com/ capistrano
[   ...   ]




                             Done!
Co-existing with 1.x

# In ~/.bashrc
alias cap1=quot;`which cap` _1.4.1_quot;
alias cap2=quot;`which cap`quot;
alias cap=quot;echo 'Please explicitly choose cap1 or cap2.'quot;
New in 2.0?
•   More rake-like

    -   Use `cap2 -T` to list tasks

    -   Namespaces

•   Deployment strategies

•   Dependencies

•   Generic hooks
New task names
•   deploy    well, umm, deploy

•   deploy_with_migrations     deploy:migrations

•   diff_from_last_deploy    deploy:pending:diff

•   setup    deploy:setup

•   Same idea, just with namespaces
New Deployment Tasks
•   Subversion log of undeployed changes
    •   deploy:pending

•   Command, gem, file, directory dependencies
    • deploy:check
What I’ve been up to
Recipes in plugins

# New Capfile
Dir['vendor/plugins/*/recipes'].each do |plugin|
  load_paths << plugin
end
load 'deploy' if respond_to?(:namespace)
load 'config/deploy'
Daemon Strategies
•   Default uses spin/spawner/reaper

•   Solaris Service Management Framework

•   runit

•   daemontools

•   Autogenerate script/spin
Staging
•   Separate clusters for staging & deployment

•   Use svnmerge to manage branches

•   Trunk is deployed to staging server

•   Production branch gets deployed live
General Strategy


•   Create a rake task to do what you want.

•   Create a Capistrano task that runs the rake
    task.

•   Hook it into the deployment.
DB Backup - Rake
desc quot;Dumps the database into db/env-data.sql.quot;
task :dump => :environment do
  abc = ActiveRecord::Base.configurations[RAILS_ENV]
  cmd = ['mysqldump']
  cmd << quot;--host='#{abc['host']}'quot; unless abc['host'].blank?
  cmd << quot;--user='#{abc['username']}'quot;
  cmd << quot;--password='#{abc['password']}'quot;
  cmd << abc['database']
  cmd << quot; | gzip > #{RAILS_ROOT}/db/#{RAILS_ENV}-data.sql.gzquot;
  sh cmd.flatten.join ' '
end
DB Backup - Capfile

desc “Back up the production database”
task :backup, :roles => :db, :only => { :primary => true } do
  rake = fetch(:rake, 'rake')
  rails_env = fetch(:rails_env, 'production')

  run quot;cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} db:dumpquot;
  get quot;#{current_path}/db/#{rails_env}-data.sql.gzquot;, quot;db/#
{rails_env}-data.sql.gzquot;
end
Hook into deployment


before quot;deploy:migratequot;,   quot;db:backupquot;
All in a plugin


$ script/plugin install -x 
http://svn.rubaidh.com/plugins/trunk/rubaidh_platform
“I checked out your slides, and they look great!
Best of luck on your presentation.”

                                   - Jamis Buck
What else do you want
      to know?

More Related Content

What's hot

What's hot (20)

Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Background processing with Resque
Background processing with ResqueBackground processing with Resque
Background processing with Resque
 
Background Jobs with Resque
Background Jobs with ResqueBackground Jobs with Resque
Background Jobs with Resque
 
Capistrano 3 Deployment
Capistrano 3 DeploymentCapistrano 3 Deployment
Capistrano 3 Deployment
 
DATABASE AUTOMATION with Thousands of database, monitoring and backup
DATABASE AUTOMATION with Thousands of database, monitoring and backupDATABASE AUTOMATION with Thousands of database, monitoring and backup
DATABASE AUTOMATION with Thousands of database, monitoring and backup
 
Backing up thousands of containers
Backing up thousands of containersBacking up thousands of containers
Backing up thousands of containers
 
Config managament for development environments ii
Config managament for development environments iiConfig managament for development environments ii
Config managament for development environments ii
 
Puppet
PuppetPuppet
Puppet
 
Scaling HBase (nosql store) to handle massive loads at Pinterest by Jeremy Carol
Scaling HBase (nosql store) to handle massive loads at Pinterest by Jeremy CarolScaling HBase (nosql store) to handle massive loads at Pinterest by Jeremy Carol
Scaling HBase (nosql store) to handle massive loads at Pinterest by Jeremy Carol
 
PowerShell: Automation for everyone
PowerShell: Automation for everyonePowerShell: Automation for everyone
PowerShell: Automation for everyone
 
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Php resque
Php resquePhp resque
Php resque
 
Altitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshopAltitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshop
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, EverAltitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 

Viewers also liked (8)

QUE ES EL Spam OSCAR E OSPINA
QUE ES EL Spam OSCAR E OSPINAQUE ES EL Spam OSCAR E OSPINA
QUE ES EL Spam OSCAR E OSPINA
 
Riads Essaouira Maroc Hotel Maison 002
Riads Essaouira Maroc Hotel Maison 002Riads Essaouira Maroc Hotel Maison 002
Riads Essaouira Maroc Hotel Maison 002
 
Sample
SampleSample
Sample
 
Riads Essaouira Maroc Hotel Maison 01
Riads Essaouira Maroc Hotel Maison 01Riads Essaouira Maroc Hotel Maison 01
Riads Essaouira Maroc Hotel Maison 01
 
Kaleido02
Kaleido02Kaleido02
Kaleido02
 
Vickyandsunny V2
Vickyandsunny V2Vickyandsunny V2
Vickyandsunny V2
 
Medula Espinal
Medula EspinalMedula Espinal
Medula Espinal
 
TPTP
TPTPTPTP
TPTP
 

Similar to Capistrano 2 Rocks My World

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Jesse Vincent
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
Deploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoDeploying Rails Applications with Capistrano
Deploying Rails Applications with Capistrano
Almir Mendes
 

Similar to Capistrano 2 Rocks My World (20)

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Capistrano2
Capistrano2Capistrano2
Capistrano2
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
Useful Kafka tools
Useful Kafka toolsUseful Kafka tools
Useful Kafka tools
 
Capistrano
CapistranoCapistrano
Capistrano
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Deploying Rails Applications with Capistrano
Deploying Rails Applications with CapistranoDeploying Rails Applications with Capistrano
Deploying Rails Applications with Capistrano
 
EC2
EC2EC2
EC2
 
Virtual Infrastructure
Virtual InfrastructureVirtual Infrastructure
Virtual Infrastructure
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Capistrano 2 Rocks My World

  • 1. Capistrano 2 Rocks my world Graeme Mathieson, Rubaidh Ltd <mathie@rubaidh.com> http://woss.name/ & http://www.rubaidh.com/
  • 2. What’s the plan? • So, what is it? • Installing 2.0 • What’s new in Cap 2? • Stuff I’ve done with cap 2
  • 3. What is it? • A Rails deployment tool • A Java deployment tool • A troubleshooting tool • An ad-hoc systems management tool
  • 4. Without a Capfile $ cap2 invoke COMMAND=uname HOSTS=macallan,cardhu * executing `invoke' * executing quot;unamequot; servers: [quot;macallanquot;, quot;cardhuquot;] [macallan] executing command [cardhu] executing command ** [out :: cardhu] SunOS ** [out :: macallan] Linux command finished $
  • 5. Using cap shell $ cap2 shell HOSTS=balvenie,cardhu * executing `shell' cap> uptime [establishing connection(s) to balvenie, cardhu] ** [out :: balvenie] 19:33:52 up 211 days, 7:25, 1 user, load average: 0.06, 0.07, 0.07 ** [out :: cardhu] 7:33pm up 10 day(s), 6:47, 2 users, load average: 0.18, 0.16, 0.15 cap> uname -r ** [out :: balvenie] 2.4.21-47.0.1.EL ** [out :: cardhu] 5.10 cap>
  • 6. Installing 2.0 $ gem install -y net-ssh net-ftp highline [ ... ] $ gem install -s http://gems.rubyonrails.com/ capistrano [ ... ] Done!
  • 7. Co-existing with 1.x # In ~/.bashrc alias cap1=quot;`which cap` _1.4.1_quot; alias cap2=quot;`which cap`quot; alias cap=quot;echo 'Please explicitly choose cap1 or cap2.'quot;
  • 8. New in 2.0? • More rake-like - Use `cap2 -T` to list tasks - Namespaces • Deployment strategies • Dependencies • Generic hooks
  • 9. New task names • deploy well, umm, deploy • deploy_with_migrations deploy:migrations • diff_from_last_deploy deploy:pending:diff • setup deploy:setup • Same idea, just with namespaces
  • 10. New Deployment Tasks • Subversion log of undeployed changes • deploy:pending • Command, gem, file, directory dependencies • deploy:check
  • 12. Recipes in plugins # New Capfile Dir['vendor/plugins/*/recipes'].each do |plugin| load_paths << plugin end load 'deploy' if respond_to?(:namespace) load 'config/deploy'
  • 13. Daemon Strategies • Default uses spin/spawner/reaper • Solaris Service Management Framework • runit • daemontools • Autogenerate script/spin
  • 14. Staging • Separate clusters for staging & deployment • Use svnmerge to manage branches • Trunk is deployed to staging server • Production branch gets deployed live
  • 15. General Strategy • Create a rake task to do what you want. • Create a Capistrano task that runs the rake task. • Hook it into the deployment.
  • 16. DB Backup - Rake desc quot;Dumps the database into db/env-data.sql.quot; task :dump => :environment do abc = ActiveRecord::Base.configurations[RAILS_ENV] cmd = ['mysqldump'] cmd << quot;--host='#{abc['host']}'quot; unless abc['host'].blank? cmd << quot;--user='#{abc['username']}'quot; cmd << quot;--password='#{abc['password']}'quot; cmd << abc['database'] cmd << quot; | gzip > #{RAILS_ROOT}/db/#{RAILS_ENV}-data.sql.gzquot; sh cmd.flatten.join ' ' end
  • 17. DB Backup - Capfile desc “Back up the production database” task :backup, :roles => :db, :only => { :primary => true } do rake = fetch(:rake, 'rake') rails_env = fetch(:rails_env, 'production') run quot;cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} db:dumpquot; get quot;#{current_path}/db/#{rails_env}-data.sql.gzquot;, quot;db/# {rails_env}-data.sql.gzquot; end
  • 18. Hook into deployment before quot;deploy:migratequot;, quot;db:backupquot;
  • 19. All in a plugin $ script/plugin install -x http://svn.rubaidh.com/plugins/trunk/rubaidh_platform
  • 20. “I checked out your slides, and they look great! Best of luck on your presentation.” - Jamis Buck
  • 21. What else do you want to know?