A gem with some capistrano recipes we use for our projects. This gem is not published to rubygems.
Add this line to your application's Gemfile:
gem 'capistrano-recipes', :git => 'https://github.com/auxilium/capistrano-recipes.git'
Require all or some recipes in your deploy.rb
# require all recipes
require 'capistrano-recipes/all'
# or include recipes one by one
# require 'capistrano-recipes/recipes/git'
# require 'capistrano-recipes/recipes/log'
# require 'capistrano-recipes/recipes/maintenance'
# require 'capistrano-recipes/recipes/nginx'
# require 'capistrano-recipes/recipes/postgresql'
# require 'capistrano-recipes/recipes/unicorn'
# require 'capistrano-recipes/recipes/uploads'
By default the recipes come with multistage
support. This means you need to structure your application to have the different stage enviroments configured in config/deploy
. See the example folder or the structure described below:
config/
deploy/
production.rb
staging.rb
deploy.rb
command | description |
---|---|
git:check_revision |
checks if the HEAD is the same as the origin |
before: deploy
, deploy:migrations
and deploy:cold
execute git:check_revision
command | description |
---|---|
log |
defaults to cap log:rails |
log:rails |
tails the rails log |
log:sidekiq |
tails the sidekiq log (if present) |
log:unicorn |
tails the unicorn log |
:maintenance_path
- default:"#{shared_path}/system/maintenance"
command | description |
---|---|
maintenance:on |
turns on the maintenance page |
maintenance:off |
turns off the maintenance page |
maintenance:update_maintenance_page |
copies the maintenance page from public/maintenance |
maintenance:check_maintenance_present |
checks if public/maintenance/index.html exists |
before: maintenance:on
execute maintenance:check_maintenance_present
after: deploy:update_code
execute maintenance:update_maintenance_page
:include_www_alias
- default:true
command | description |
---|---|
nginx:setup |
Creates a new site on the nginx instance |
nginx:start |
Starts the nginx service |
nginx:stop |
Stops the nginx service |
nginx:restart |
Restarts the nginx service |
after: deploy:setup
execute nginx:setup
:postgresql_create_user
- default: Asked by capistrano:postgresql_user
- default: Asked by capistrano:postgresql_password
- default: Asked by capistrano:postgresql_database
- default:"#{application}_#{stage}"
command | description |
---|---|
postgresql:setup |
Creates a database.yml file |
postgresql:create_database |
Creates the database and a user (unless it already exsists) |
postgresql:create_symlink |
Symlink the database.yml file |
postgresql:pull |
Pull the remote database and restore it on your local postgresql instance |
after: deploy:setup
execute postgresql:create_database
and postgresql:setup
after: deploy:finalize_update
execute postgresql:create_symlink
:unicorn_user
- default:user
meaning ssh user:unicorn_pid
- default:"#{shared_path}/pids/unicorn.pid"
:unicorn_sock
- default:"/tmp/unicorn.#{application}_#{stage}.sock"
:unicorn_config
- default:"#{shared_path}/config/unicorn.rb"
:unicorn_log
- default:"#{shared_path}/log/unicorn.log"
:unicorn_workers
- default:2
:unicorn_timeout
- default:30
command | description |
---|---|
unicorn:setup |
Creates a unicorn config and init script |
unicorn:start |
Starts the unicorns |
unicorn:stop |
Stops the unicorns |
unicorn:restart |
Restarts the unicorns |
unicorn:upgrade |
Upgrades the unicorns |
after: deploy:setup
execute unicorn:setup
after: 'deploy:startexecute
unicorn:start<br /> _after_: 'deploy:stop
execute unicorn:stop
after: 'deploy:restartexecute
unicorn:upgrade`
:upload_path
- default:"#{shared_path}/uploads"
command | description |
---|---|
uploads:setup |
Creates and upload folder in shared/uploads |
uploads:create_symlink |
Symlink public/uploads to shared upload folder |
after: deploy:setup
execute uploads:setup
after: deploy:create_symlink
execute uploads:create_symlink