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:
- Phusion Passenger (Setup and Deployment)
- Apache Server
- Memcache Process
- Juggernaut Daemon
- Backgroundrb Server
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):
# substitude memcache with: passenger, rails, apache, backgroundrb, 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'
USAGE
Apache
Configuration
- apache_init_path – the path to the init.d apache file [default: ‘/etc/init.d/apache2’]
Tasks
manage.rb
apache :stop :start :restartinstall.rb
apache :installPassenger
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_migrationsinstall.rb
passenger :installRails
Tasks
manage.rb
rails :symlink_db_config :repair_permissions :tail – tail production log :ping – ping the server to start it sweep :cache :loghooks.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 instanceBackgroundrb
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 :tailhooks.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 damonJuggernaut
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 :tailhooks.rb
after “deploy:update_code”, “juggernaut:symlink_config” # copy juggernaut.yml to release after “deploy:restart” , “juggernaut:restart” # restart juggernaut daemonMemcache
Configuration
- memcache_init_path – path to memcache config file [default: “/etc/init.d/memcache”]
Tasks
manage.rb
memcache :start :stop :restartinstall.rb
memcache :installhooks
after “deploy:restart”, “memcache:restart” # clear cache after updating codeEXAMPLE
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, "[email protected]:/home/git/repos.git"
# =============================================================================
# CAP RECIPES
# =============================================================================
# Note this happens after the general settings have been defined
require 'rubygems'
require 'cap_recipes'
# 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
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
# 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
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.