nesquena / cap-recipes

Battle-tested capistrano recipes for ruby, rubygems, apache, passenger, delayed_job, juggernaut, thinking_sphinx, mongodb, whenever, among other popular tools
MIT License
358 stars 23 forks source link

h1. cap-recipes

A collection of useful capistrano recipes I have been using in production on a number of sites.

This gem is best suited for ruby (and rails) projects which deploy using Apache and Phusion Passenger. Worth noting is that the installation tasks are for systems using aptitude package management.

The overall vision for this project is simply to collect a number of classic, generic recipes for common issues which can then be used by the community.

Feel free to improve upon this recipe collection by adding your own!

Currently included recipes in this gem:

Check out the USAGE section below for specific tasks included in the recipes.

h2. INSTALLATION

To install the gem, execute:

@$ sudo gem install cap-recipes --source http://gemcutter.org@

Then, include into your @deploy.rb@ configuration file for Capistrano:


  # use the complete deployment process (NOT RECOMMENDED)
  require 'cap_recipes'

  # RECOMMENDED
  # require necessary recipes according to your needs
  # (use hooks which tie all the recipes into the deployment process,
  # tasks for managing and tasks for installing):
  require 'cap_recipes/tasks/memcache'
  require 'cap_recipes/tasks/passenger'
  require 'cap_recipes/tasks/thinking_sphinx'
  require 'cap_recipes/tasks/rails'
  require 'cap_recipes/tasks/delayed_job'
  # or ruby, rubygems, apache, mongodb, juggernaut, backgroundrb, aptitude, gitosis, whenever

  # OR
  # only use managing tasks:
  require 'cap_recipes/tasks/memcache/manage'

  # OR
  #only use install tasks:
  require 'cap_recipes/tasks/memcache/install'

You can find full examples of what your @deploy.rb@ file should look like in the @examples@ folder.

h2. USAGE

h3. Apache

These recipes manage the apache web server

h4. Configuration

h4. Tasks

manage.rb

install.rb

h3. Ruby

h4. Configuration

h4. Tasks

install.rb

h3. Rubygems

h4. Configuration

h4. Tasks

manage.rb

install.rb

h3. Passenger

These recipes manage the passenger module for apache

h4. Configuration

The following files and folders are expected to exist:

h4. Tasks

manage.rb

install.rb

h3. Aptitude

h4. Tasks

manage.rb

h3. Rails

These recipes support rails-specific functionality

h4. Tasks

manage.rb

hooks.rb


after "deploy:update_code", "rails:symlink_db_config" # copy database.yml file to release path
after "deploy:update_code", "rails:sweep:cache" # clear cache after updating code
after "deploy:restart"    , "rails:repair_permissions" # fix the permissions to work properly
after "deploy:restart"    , "rails:ping" # ping passenger to start the rails instance

h3. DelayedJob

These recipes are for tobi's delayed_job plugin for background job queue processing

h4. Configuration

h4. Tasks

manage.rb

hooks.rb


after "deploy:start",   "delayed_job:start"
after "deploy:stop",    "delayed_job:stop"
after "deploy:restart", "delayed_job:restart"

h3. Backgroundrb

These recipes are for backgroundrb job queue processing

h4. Configuration

h4. Tasks

manage.rb

hooks.rb


after "deploy:update_code"   , "backgroundrb:symlink_config" # copy backgroundrb config to release
after "deploy:restart"       , "backgroundrb:restart"     # restart backgroundrb daemon
after "backgroundrb:restart" , "backgroundrb:repair_permissions" # restart backgroundrb damon

h3. Juggernaut

These recipes are for managing the juggernaut push server

h4. Configuration

h4. Tasks

manage.rb

hooks.rb


after "deploy:update_code", "juggernaut:symlink_config" # copy juggernaut.yml to release
after "deploy:restart"    , "juggernaut:restart"     # restart juggernaut daemon

h3. ThinkingSphinx

These recipes are for managing the thinking_sphinx search index daemon

h4. Configuration

h4. Tasks

manage.rb

install.rb

hooks.rb


after "deploy:update_code", "thinking_sphinx:symlink_config" # sym thinking_sphinx.yml on update code
after "deploy:restart"    , "thinking_sphinx:restart"     # restart thinking_sphinx on app restart

h3. Memcache

These recipes are for managing the memcached caching mechanism

h4. Configuration

h4. Tasks

manage.rb

install.rb

hooks.rb


after "deploy:restart", "memcache:restart" # clear cache after updating code

h3. MongoDB

These recipes are for installing and managing the mongodb document-oriented database

h4. Configuration

h4. Tasks

install.rb

manage.rb

h3. Gitosis

These recipes are for installing Gitosis Git Repository Hosting

h4. Configuration

h4. Tasks

install.rb

h3. Whenever

These recipes are for managing whenever cron job scheduling

h4. Configuration

h4. Tasks

manage.rb

hooks.rb


after "deploy:symlink", "whenever:update_crontab"

h2. EXAMPLE

Here is a sample deploy.rb file using cap_recipes:


# =============================================================================
# GENERAL SETTINGS
# =============================================================================

set :application,  "app_name"
set :deploy_to,  "/var/apps/#{application}"
set :scm, :git
set :repository, "git@repos.site.com:/home/git/repos.git"

# =============================================================================
# CAP RECIPES
# =============================================================================

# Note this happens after the general settings have been defined
require 'rubygems'

# PASSENGER
require 'cap_recipes/tasks/passenger'
set :base_ruby_path, '/opt/ruby-enterprise' # defaults to "/usr"
set :apache_init_path, '/etc/init.d/apache2' # defaults to "/etc/init.d/apache2"

# BACKGROUNDRB
require 'cap_recipes/tasks/backgroundrb'
set :backgroundrb_log, "/var/log/backgroundrb.log" # defaults to "#{release_path}/log/backgroundrb.log"
set :backgroundrb_host, "worker.site.com" # defaults to localhost
set :backgroundrb_env, "staging" # defaults to production

# DELAYED_JOB
require 'cap_recipes/tasks/delayed_job'
set :delayed_script_path, 'script/djworker' # defaults to 'script/delayed_job'
set :delayed_job_env, 'staging' # defaults to production

# JUGGERNAUT
require 'cap_recipes/tasks/juggernaut'
set :juggernaut_config, "/some/path/juggernaut.yml" # defaults to "#{current_path}/config/juggernaut.yml"
set :juggernaut_pid, "/some/path/juggernaut.pid" # defaults to "#{current_path}/tmp/pids/juggernaut.pid"
set :juggernaut_log, "/var/log/juggernaut.log" # defaults to #{release_path}/log/juggernaut.log

# MEMCACHE
require 'cap_recipes/tasks/memcache'
set :memcache_init_path, "/etc/init.d/memcache" # defaults to "/etc/init.d/memcache"

You can find more examples of what your @deploy.rb@ file should look like in the @examples@ folder.

h2. UTILITIES

In addition to the recipes themselves, this gem provides a bunch of useful utility methods which make writing your own recipes or extending existing ones much easier by creating reusable commands for common subtasks in a recipe.

There are too many to mention all of them directly, but check out @lib/cap_recipes/tasks/utilities.rb@ to browse all available utility methods. A few are listed below:

h2. CONTRIBUTORS

The following people are the reason this library exists:

h2. LICENSE

(The MIT License)

Copyright (c) 2008 Nathan Esquenazi

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.