Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Battle-tested capistrano recipes for ruby, rubygems, apache, passenger, unicorn, redis, riak, mysql, god, autossh, statsd, among other popular tools

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION.yml
Octocat-spinner-32 cap-recipes.gemspec
README.textile

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.
Feel free to contribute to this collection and make it even better!

The overall vision for this project being to collect a number of classic, generic recipes which can
be used by the community.

Currently included:

  • Apache Server
  • Rubygems Package Management
  • Phusion Passenger (Setup and Deployment)
  • Memcache Process (Setup and Deployment)
  • Juggernaut Daemon
  • Backgroundrb Server
  • DelayedJob Worker
  • Whenever Cron Scheduling
  • Aptitude Package Management

INSTALLATION

sudo gem install nesquena-cap-recipes -s http://gems.github.com/

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'
  # or rails, apache, rubygems, delayed_job, juggernaut, backgroundrb, aptitude, whenever

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

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

USAGE

Apache

These recipes manage the apache web server

Configuration

  • apache_init_path – the path to the init.d apache file [default: ‘/etc/init.d/apache2’]

Tasks

manage.rb
apache :stop :start :restart
install.rb
apache :install

Rubygems

Configuration

  • rubygem_paths – a path or array of paths to your gem binaries [default ‘/usr/bin/gem’ ]

Tasks

manage.rb
rubygems :full_update :upgrade :update :cleanup :install :uninstall

Passenger

These recipes manage the passenger module for apache

Configuration

  • base_ruby_path – the base path to the ruby installation [default: ‘/usr’]
  • local_ping_path – the localhost path to ping to start passenger [default: “http://localhost”]

The following files and folders are expected to exist:

  • “#{base_ruby_path}/lib/ruby”
  • “#{base_ruby_path}/bin/ruby”
  • “#{base_ruby_path}/bin/gem”

Tasks

manage.rb
deploy :start :stop :restart :with_migrations
install.rb
passenger :install

Aptitude

Tasks

manage.rb
aptitude :install :remove :updates

Rails

These recipes support rails-specific functionality

Tasks

manage.rb
rails :symlink_db_config :repair_permissions :tail – tail production log :ping – ping the server to start it sweep :cache :log
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

DelayedJob

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

Configuration

  • delayed_script_path – the path to the delayed job script [default: ‘script/delayed_job’]
  • delayed_job_env – the rails environment [default: ‘production’]

Tasks

manage.rb
delayed_job :stop :start :restart
hooks.rb
after “deploy:start”, “delayed_job:start” after “deploy:stop”, “delayed_job:stop” after “deploy:restart”, “delayed_job:restart”

Backgroundrb

These recipes are for backgroundrb job queue processing

Configuration

  • backgroundrb_log – the path to the backgroundrb log file
  • backgroundrb_host – the background host machine ip [default: ‘localhost’]
  • backgroundrb_env – the rails environment [default: ‘production’]

Tasks

manage.rb
backgroundrb :stop :start :restart :symlink_config :tail
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

Juggernaut

These recipes are for managing the juggernaut push server

Configuration

  • juggernaut_config – path to juggernaut config file [default: “#{current_path}/config/juggernaut.yml”]
  • juggernaut_pid – path to juggernaut pid file [default: “#{current_path}/tmp/pids/juggernaut.pid”]
  • juggernaut_log – path to juggernaut log file [default: “#{current_path}/log/juggernaut.log”]

Tasks

manage.rb
juggernaut :start :stop :restart :symlink_config :tail
hooks.rb
after “deploy:update_code”, “juggernaut:symlink_config” # copy juggernaut.yml to release after “deploy:restart” , “juggernaut:restart” # restart juggernaut daemon

Memcache

These recipes are for managing the memcached caching mechanism

Configuration

  • memcache_init_path – path to memcache config file [default: “/etc/init.d/memcache”]
  • memcache_size – the total size of memory to use [default: 64]
  • memcache_port – the port to start memcache [default: ‘11211’]
  • memcache_host – the host for memcache [default: ‘127.0.0.1’]
  • memcache_user – the user to run memcache [default: ‘nobody’]

Tasks

manage.rb
memcache :start :stop :restart
install.rb
memcache :install
hooks
after “deploy:restart”, “memcache:restart” # clear cache after updating code

Whenever

These recipes are for managing whenever cron job scheduling

Configuration

  • None necessary yet

Tasks

manage.rb
whenever :update_crontab
hooks
after “deploy:symlink”, “whenever:update_crontab”

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"

LICENSE:

(The MIT License)

Copyright © 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.

Something went wrong with that request. Please try again.