Using Capistrano Chirb — February 5, 2007 Presentation by Michael H. Buselli

Slides:



Advertisements
Similar presentations
1. What is Subversion? Why do we need CM? Basic concepts Repositories Options Setup Clients Options Setup Operation Troubleshooting Slide 2.
Advertisements

Developing in CAS. Why? As distributed you edit CAS 3 with Eclipse and build with Maven 2 – Best Practice for Release Engineering – Difficult edit-debug.
Getting Started with Capistrano and Ruby on Rails Slides taken from
FILE TRANSFER PROTOCOL Short for File Transfer Protocol, the protocol for exchanging files over the Internet. FTP works in the same way as HTTP for transferring.
A complete web app using flex. You can use the flex builder to generate the php (server side) code for a flex-php application. As before, Php connects.
Virtual Machine and UNIX. What is a VM? VM stands for Virtual Machine. It is a software emulation of hardware. By using a VM, you can have the same hardware.
Ruby on Rails (Slides modified by ements-2ed.shtml)
SubVersioN – the new Central Service at DESY by Marian Gawron.
Automating Drupal Deployment Dominique De Cooman.
Linux Operations and Administration
Capistrano for System Administrators (not rails developers) Bryan McLellan Senior Systems Administrator Widemile.
Installing and Configuring Tomcat A quick guide to getting things set up on Windows.
Servlets Environment Setup. Agenda:  Setting up Java Development Kit  Setting up Web Server: Tomcat  Setting up CLASSPATH.
Basic Programming in Ruby Today’s Topics: Introduction last class irb history log Methods Classes (briefly) Using 3 rd Party Libraries rubygems ‘ require.
Unix Basics Chapter 4.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface What is the directory tree Some UNIX commands.
ATG Environment Setup In this session you will learn – Setting Up ATG environment – Creating new ATG application – Configuring Data Source – Configuring.
Copyright (c) by CNAPTICS Corporation. All rights reserved.1 INFO Oracle Database 11g: Administration II Presented By: Marc S. Paller,
Netbeans 6.0 version control configuration for AUV Workbench & various XMSF projects TODO: check changes in all Netbeans 5 screens Don Brutzman
Network Security: Lab#3 Transport-Level Security Tools J. H. Wang May 12, 2011.
Netbeans 5.0 cvs configuration for AUV Workbench & various XMSF projects Don Brutzman 14 July 2006.
Subversion (SVN) A Revision Control System Successor to CVS Carlos Armas Hervey Allen.
CPSC 233 Run graphical Java programs remotely on Mac and Windows.
Ruby on Rails (Slides modified by ements-2ed.shtml)
Quiz 15 minutes Open note, open book, open computer Finding the answer – working to get it – is what helps you learn I don’t care how you find the answer,
Netbeans 5.5 version control: cvs, svn configuration for AUV Workbench & various X3D, XMSF projects Don Brutzman 1 December 2007.
Ruby on Rails on Ubuntu Bradley Taylor Rails Machine, LLC
Ansible with vCloud Air Workshop
Wordpress with Mina Automated Deployment Solution Jonathan Gravato DIG 4104c.
Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration.
CMap Version 0.16 Ben Faga. CMap CMap Version 0.16 Bug fixes and code optimizations More intuitive menu system Asynchronous loading of comparative map.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
WAMP Server Installatin Shiyun Wen. WAMP Server Installation  WAMP Server is an integrated installation of Apache, MySQL, and PHP for Windows. Following.
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring.
IBM Express Runtime Quick Start Workshop © 2007 IBM Corporation Deploying a Solution.
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
Settings MySQL Database and JDBC configuration Instructor: Sergey Goldman.
NALINI S. NAUTIYAL SYSTEM SOFTWARE DIVISION Subversion.
Apache Web Server v. 2.2 Reference Manual Chapter 2 Starting Apache.
9/21/04 James Gallagher Server Installation and Testing: Hands-on ● Install the CGI server with the HDF and FreeForm handlers ● Link data so the server.
L.A.M.P. İlker Korkmaz & Kaya Oğuz CS 350. Why cover a lecture on LAMP? ● Job Opportunities – There are many hosting companies offering LAMP as a web.
Using Linux Kaya Oğuz Room: 310.
GlassFish Gem Vivek Pandey Sun Microsystems, Inc.
WampServer 2 Installation WAMP is a solution stack of open source programs used together to run dynamic Web sites or servers Most common expansion:  Windows,
Stress Free Deployments with Octopus Deploy
CS1010: Intro Workshop.
Site Administration Tools: Ansible
Chapter 11 Command-Line Master Class
Linux 101 Training Module Linux Basics.
CReSIS Git Tutorial.
NTP, Syslog & Secure Shell
Chapter 9 Router Configuration (Ospf, Rip) Webmin, usermin Team viewer
Andy Wang Object Oriented Programming in C++ COP 3330
Introduction to Ansible
Machine Learning Workshop
IT Atoumation / Conf. Mgmt...
CDT Build/Run/Debug in Container
Lab 1 introduction, debrief
Capistrano David Grayson Las Vegas Ruby Meetup
Dev-Staging-Prod Environment Guidelines
Ansible for Easy Provisioning and Application Deployment
welcome to: Latinx Tech PDX
Lab 7 - Topics Establishing SSH Connection Install SSH Configure SSH
Andy Wang Object Oriented Programming in C++ COP 3330
JENKINS TIPS Ideas for making your life with Jenkins easier
SUSE Linux Enterprise Desktop Administration
VirgoStaging Status F.Carbognani, S. Cortese, E. Pacaud.
Presentation transcript:

Using Capistrano Chirb — February 5, 2007 Presentation by Michael H. Buselli

What is Capistrano? ● A tool to deploy applications remotely. ● Uses SSH to contact remote systems and issue commands in a POSIX shell. ● Also uses SFTP if available. ● Can tunnel SSH connections through a gateway host. ● Comes from Jamis Buck of 37signals, the same team that brings us Rails. ● Latest version is

About Capistrano ● Like Rails, makes default assumptions about your environment to reduce configuration. ● If your environment is identical to 37signals's, you probably don't need a configuration file. [just kidding :)] ● Default assumes Rails, Subversion, Apache 1.x, FastCGI. ● Future versions will de-couple Rails support from the Capistrano core.

Getting Capistrano ● sudo gem install capistrano -y ● You should also make sure to pick up the following optional gems: – net-sftp ● for reliable file transport – termios ● so your password doesn't echo to the screen

Capistrano Commands runExecute a remote command sudoSame as run, but as root putUpload a file deleteRemove a remote file renderReturn string from ERb template getDownload a file (but only from one system)

run run 'uname -a' run ”mv #{some_file} /path/to/somewhere” ● Give run a block to process output: run ”find /path” do |chan, strm, data| if strm == :err and data =~ /denied/ logger.info ”bad perm on #{chan[:host]}: #{data}” end

sudo ● Run commands as root with sudo: sudo 'apachectl restart' sudo ”cp #{staging_area}/file /etc/file” ● Like run, sudo can also take a block for additional processing.

put put ”Hello World\n”, '/remote/path/hello_world' put File.read('/local/file'), '/remote/file'

render ● Render a local ERb template file: render ”template.file” ● Render ERb template string: render :template => ”Hello ”, :place => 'world' ● Use with put: put render('config'), ”/path/to/#{app}/config”

delete delete ”/file/we/dont/like” delete ”/directory/we/dont/like”, :recursive => true get get ”/remote/file/to/get”, ”/where/to/put/it”

Add your own Commands! module CapExtension def hello_world (greeting) run ”echo hello #{greeting} world” end Capistrano.plugin :ext, CapExtension ● Now call it from within a task: ext.hello_world 'cruel'

Capistrano Tasks ● Commands are organized into tasks: desc ”Tell the world hello, then destroy it.” task :hello_world_destroy do run 'echo ”hello world”' delete '/path/to/the/world' end

Capistrano Tasks ● Commands are organized into tasks: desc ”Tell the world hello, then destroy it.” task :hello_world_destroy do run 'echo ”hello world”' delete '/path/to/the/world' end All systems run this concurrently

Capistrano Tasks ● Commands are organized into tasks: desc ”Tell the world hello, then destroy it.” task :hello_world_destroy do run 'echo ”hello world”' delete '/path/to/the/world' end Runs on success of previous command on all systems.

Tasks Calling Tasks ● Tasks often call other tasks: task :hello_world do run 'echo ”hello world”' end task :destroy_world do delete '/path/to/the/world' end task :hello_world_destroy do hello_world destroy_world end

Task Hooks ● When a task, say the_task, is called Capistrano looks for other tasks called before_the_task and after_the_task and calls them before and after the the_task respectively. task :before_hello_world do run 'echo ”prepare to be greeted”' end task :after_hello_world do run 'echo ”you have been greeted”' end

Capistrano Roles ● Machines are grouped into roles that define what tasks apply to which systems. role :web, 'www1', 'www2' role :app, 'app1', 'app2' role :db, 'db-master', :primary => true role :db, 'db-slave1', 'db-slave2'

Limit Tasks by Role ● Each task can be limited to what role(s) it applies to. task :hello_web_servers, :roles => :web do run 'echo ”hello web server”' end task :hello_app_servers, :roles => :app do run 'echo ”hello web server”' end task :hello_world do hello_web_servers hello_app_servers end

Limit Tasks by Role ● Each task can be limited to what role(s) it applies to. task :hello_web_servers, :roles => :web do run 'echo ”hello web server”' end task :hello_app_servers, :roles => :app do run 'echo ”hello web server”' end task :hello_world do hello_web_servers hello_app_servers end Runs only on web servers

Limit Tasks by Role ● Each task can be limited to what role(s) it applies to. task :hello_web_servers, :roles => :web do run 'echo ”hello web server”' end task :hello_app_servers, :roles => :app do run 'echo ”hello web server”' end task :hello_world do hello_web_servers hello_app_servers end Runs only on app servers

Capistrano Variables ● Variables are used by various tasks and methods. set :scm, :subversion set :deploy_to, '/path/to/application' ● If a block is passed, it is evaluated on first use and result cached for further uses. set :deploy_to do "/path/to/#{application}" end

Capistrano with Rails ● In your RAILS_HOME run cap –-apply-to. AppName ● Edit config/deploy.rb – Configure mandatory variables ● :application, :repository – Configure roles ● :web, :app, :db, and one primary :db – Optional settings ● :scm, :deploy_to, ssh_options, and many more

Run Capistrano ● Run Capistrano directly (preferred): cap setup ● Run via Rake (deprecated): rake remote:cold_deploy ● Capistrano sets up deploy and rollback targets directly in rake (deprecated): rake deploy ● Run arbitrary tasks via Rake with remote:exec (deprecated): rake remote:exec ACTION=my_task

Important Tasks for Rails These some important Capistrano tasks for deploying a Rails application: ● setup ● cold_deploy ● deploy ● rollback ● cleanup Run cap show_tasks or rake --tasks to see more of what's available.

setup Creates initial directories in the deployment area. % cap setup * executing task setup * executing "umask 02 &&\n mkdir -p /u/apps/myapp /u/apps/myapp/releases /u/apps/myapp/shared /u/apps/myapp/shared/system &&\n mkdir -p /u/apps/myapp/shared/log &&\n mkdir -p /u/apps/myapp/shared/pids" servers: ["localhost"] [localhost] executing command command finished

cold_deploy Deploys application and starts FastCGI processes by calling script/spin ● Make sure you create script/spin: #!/bin/sh /u/apps/myapp/current/scripts/process/spinner -c '/u/apps/myapp/current/scripts/process/spawner -p i 5' -d ● Note use of spinner and spawner to keep the FastCGI processes alive.

deploy ● Deploy your application to your servers. ● Takes care of copying files out of Subversion (or other SCM) and to the deployment area, then restart necessary processes. % cap deploy 2>&1 | grep 'executing task' * executing task deploy * executing task update * executing task update_code * executing task set_permissions * executing task symlink * executing task restart

Deployment Path /u/apps/myapp/ ● current -> releases/ ● releases/ – / – / – / ● This directory is RAILS_ROOT. ● revisions.log ● shared/ – log/ – pids/ – system/

Deployment Path /u/apps/myapp/ ● releases/ – / ● app/ ● config/ ● db/ ● script/ ● public/ – system -> /u/apps/myapp/shared/system ● log -> /u/apps/myapp/shared/log ● tmp/ – pids -> /u/apps/myapp/shared/pids

rollback Oops! We screwed up. Retreat! % cap rollback ● Re-links current to previous deployed release. ● Deletes the release rolled back from.

cleanup % cap cleanup ● Deletes old releases, only retaining the previous five.

Resources ● Capistrano Manual: ● Capistrano Mailing List: ● LRUG Presentation by Tom Ward: Bad Things With Capistrano.pdf

Resources ● Capistrano Screencast ($9): ● O'Reilly Online Book (requires subscription): ● My page on this presentation:

Using Capistrano Chirb — February 5, 2007 Presentation by Michael H. Buselli