h1. cap-recipes A collection of useful capistrano recipes. Best suited for ruby projects which deploy using Phusion Passenger. Feel free to contribute to this and make it better! Currently included: * Apache Server * Phusion Passenger (Setup and Deployment) * Memcache Process (Setup and Deployment) * Juggernaut Daemon * Backgroundrb Server * DelayedJob Worker h2. 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
  require 'cap_recipes'

  # OR
  # use a single slice of the deployment process
  # (use hooks which tie all the recipes into the deployment process,
  # tasks for managing and tasks for installing):
  # substitute memcache with: passenger, rails, apache, backgroundrb, delayed_job, juggernaut
  require 'cap_recipes/tasks/memcache'

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

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

h2. USAGE h3. Apache These recipes manage the apache web server h4. Configuration * apache_init_path - the path to the init.d apache file [default: '/etc/init.d/apache2'] h4. Tasks h5. manage.rb apache :stop :start :restart h5. install.rb apache :install h3. Passenger These recipes manage the passenger module for apache h4. 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" h4. Tasks h5. manage.rb deploy :start :stop :restart :with_migrations h5. install.rb passenger :install h3. Rails These recipes support rails-specific functionality h4. Tasks h5. manage.rb rails :symlink_db_config :repair_permissions :tail - tail production log :ping - ping the server to start it sweep :cache :log h5. 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 * delayed_script_path - the path to the delayed job script [default: 'script/delayed_job'] * delayed_job_env - the rails environment [default: 'production'] h4. Tasks h5. manage.rb delayed_job :stop :start :restart h5. 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 * 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'] h4. Tasks h5. manage.rb backgroundrb :stop :start :restart :symlink_config :tail h5. 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 * 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"] h4. Tasks h5. manage.rb juggernaut :start :stop :restart :symlink_config :tail h5. hooks.rb after "deploy:update_code", "juggernaut:symlink_config" # copy juggernaut.yml to release after "deploy:restart" , "juggernaut:restart" # restart juggernaut daemon h3. Memcache These recipes are for managing the memcached caching mechanism h4. 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'] h4. Tasks h5. manage.rb memcache :start :stop :restart h5. install.rb memcache :install h5. hooks after "deploy:restart", "memcache:restart" # clear cache after updating code 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"

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.