Capistrano-zen is a collection of capistrano recipes to install and manage various services on production machine powered by Ubuntu. The current tested environment is Ubuntu 12.04LTS.
It provides installation and management recipes for the following service:
- nginx
- with config templates for rails app
- static website template
- nodejs
- postgresql
- mysql
- unicorn (integrated with a nginx/railsapp)
- rbenv
- redis
The upcoming recipes include:
- nginx
- global config template
- shorewall
- vsftp
- php-fpm
- mongodb
capistrano-zen is extracted from the deployment procedure at zenhacks.org for a Rails application so it is designed to work with the structure of a rails application. But most recipes are independent and future development will detach general recipes from a rails application.
capistrano-zen only provides recipes of tasks, it doesn't handle:
- the application dependencies
- the logic of deployment logic
- the server settings and configuration
You will need to declare those in your own capistrano config file such as Capfile or config/deploy.rb.
The gem includes some sample files to start with Capfile-rails-****.sample for various deployment-prove usage.
Add this line to your application's Gemfile:
gem 'capistrano-zen'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capistrano-zen
capistrano-zen uses python-software-properties to ease ppa source addition. You could install it with use python-software-properties to ease ppa source addition. You could install it from your local machine with
cap deploy:install
Or install it mannually with
sudo apt-get install python-software-properties
To load a set of recipes, require them in your Capfile with:
require 'capistrano-zen/nginx'
You could verify the load is successful with:
cap -T
Here is the recipes included in this gem:
- nginx
- with config templates for rails app
- static website template
- nodejs
- postgresql
- mysql
- unicorn (integrated with a nginx/railsapp)
- rbenv
Default role: web
Configuration variables: none
Tasks:
nginx:installinstalls the lastest release from the ppappa:nginx/stable.nginx:start/stop/reloadmaps tosudo service nginx start/stop/reloadon the remote machine.nginx:setup:unicorngenerates a nginx site configuration for a rails app runs withunicornthrough unix socket.nginx:setup:staticgenerates a nginx site configuration for static sites. requiredomain,deploy_toandapplication.
Default role: app
Configuration variables: none
Tasks:
nodejs:installinstallsnodeandnpmfrom theppa:chris-lea/node.js.
The ppa comes from official wiki.
Default role: app
Configuration variables: none
Tasks:
redis:installinstallsnodeandnpmfrom theppa:chris-lea/redis-server.redis:start/stop/reloadmaps tosudo service redis start/stop/reloadon the remote machine.
It uses the rbenv installer to create a ruby environment.
Default role: app
Configuration variables:
ruby_versionindicates the ruby version installed.rbenv_bootstrapindicates the ubuntu version to install the rbenv bootstrap.
Tasks:
rbenv:installinstallsrbenv, setups configuration in~/.bashrcand installsrubywithruby_versionrbenv:patchautoruns a ruby patch to enhance performance. more info
Currently, postgresql configuration is tightly attached to a rails application, it depends on the config/database.yml to setup remote server.
Default role: db
Configuration variables:
config_paththe path for thedatabase.ymlfile, the recipe reads from it to create database and generate remotedatabase.yml. If you are using this recipe out of Rails application, store your configuration in aconfig/database.yml.db_backup_paththe path to store database dumps.pg_keep_backupsthe backups versions you want to keep on one remote machine, it defaults to 10.
Tasks:
pg:installinstallspostgresqlandlibpg-devfromppa:pitti/postgresql.pg:resetdrops the databases and roles with the same names as in the application.pg:initgenerates roles and databases for the rails application.pg:setupgenerates remotedatabase.ymlbased on localdatabase.yml'sproductionsettings.config:db:symlinkcreates symbolic for thedatabase.ymlin the release.pg:dumpdumps and compresses the application database, store them in thedb_backup_path.pg:getdownload the remote dump to local/tmpdirectorypg:putupload the local dumps in/tmpto the remote serverpg:restore:remoteOn the remote machine, restores selected dumps from thedb_backup_path, it defaults to lastest dump.pg:restore:localOn the local machine, restores selected dumps from the/tmp, it defaults to lastest dump.pg:cleanupcleans up old backups while keeppg_keep_backupsnumbers of backups.
Most capistrano-zen/mysql has similar tasks as Postgresql.
This recipes setup unicorn configuration based on current rails application, and generate a init.d control scripts to manage the service.
Default role: app
Configuration variables:
unicorn_userthe user to run unicorn process, default to the same user as remote login user.unicorn_groupthe group to run unicorn process.unicorn_pidthe path for theunicorn.pidfile, default to thecurrent/tmp/pids/unicorn.pid.unicorn_configthe path to put the unicorn config file, default toshared/config/unicorn.rb.unicorn_logthe path to put the unicorn log file, default toshared/log/unicorn.log.unicorn_workersthe number of unicorn workers, default to 4.
Tasks:
unicorn:setupgenerateunicorn.rbconfig file and registerservicewithunicorn_init.unicorn:start/stop/restart/upgrade/force-stopmaps to remoteservice unicorn start/stop/restart/upgrade/force-stop. Details is in/tmpls/unicorn_init.rb
check:revisionautoruns before any deployment tasks. It compares the local and remote master branch head to make sure remote master branch are up-to-date.dev_lib:installinstall libraries on which some gems depend such asnokogiriorpaperclip.
The wiki page of capistrano has good resources to make you up to speed.
Railscasts also has a good coverage for this tool.
- make configuration rails-less
- add more recipes