This gem is for encapsulating Abletech's common deployment patterns using capistrano.
Add this line to your application's Gemfile:
gem 'easy-deployment', :git => "email@example.com:AbleTech/easy-deployment.git"
And then execute:
Or install it yourself as:
$ gem install easy-deployment
$ rails g easy:deployment
The templated configuration files leave several lines blank for you to fill in with TODO placeholders, so it's a good idea to run
rake notes:todo after installation to see if you've missed any.
Replace any missing configuration lines, and don't forget to remove the TODO text/comments
Apache (via Passenger)
Automatically setup an Apache V-Host, and reload apache2:
If you are running under Apache (with passenger or otherwise), and the sites-available directory is writable by your deploy user. easy-deployment can automatically write a v-host config to that directory and perform a soft reload (graceful) of apache2 to automatically configure your site.
Add to deploy.rb
Customise the vhost file within
If necessary, you can set the path to the apache2ctl binary via:
set :apachectl_bin, "/usr/sbin/apachectl"
This assumes your deploy user has access to run the apachectl command with sudo privileges. As a recommended security practice, your deploy user should not have general sudo access, instead configure limited sudo access for specific commands only, declaring the full binary path. Having passwordless sudo only for these limited commands can make this smoother, but is not a requirement - capistrano will prompt for sudo password if that is required.
# Example sudoers file entries to grant deploy user passwordless sudo privileges to only these commands deploy ALL=(ALL) NOPASSWD:/usr/sbin/apachectl graceful deploy ALL=(ALL) NOPASSWD:/usr/sbin/apachectl configtest
Read more about passenger configuration on our wiki at https://github.com/AbleTech/easy-deployment/wiki/Common-passenger-config
Nginx (for use with standalone ruby app server)
Add to deploy.rb
Customise the site configuration within
Alter the paths used if required:
set :nginx_bin, "/etc/init.d/nginx" # This is the default, change if necessary set :nginx_dir, "/etc/nginx" # This is the default, change if necessary
Like the apache integration, this requires sudo privileges to reload nginx:
This example shows setting a passwordless sudo for a single user
deploy for a limited set of commands controlling nginx
# Example sudoers file entries to grant deploy user passwordless sudo privileges to only these commands deploy ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload deploy ALL=(ALL) NOPASSWD:/etc/init.d/nginx configtest
Automatically configure logrotate for your application logfile: If you have logrotate installed and /etc/logrotate.d is writable by your deploy user, simply
within your deploy.rb to have a logrotate config automatically written
This includes a generator to create a backup configuration (generator may be disabled when running easy:deployment by passing
--disable-backup, or run by itself as
rails generate easy:backup)
This will generate:
config/backup.rb config/schedule.rb config/s3.yml
The created backup configuration will be scheduled on deploy to run nightly via the whenever integration below, and with a backup configuration at
The default setup is to backup the capistrano system folder, the configured database, to store the backup in S3, and notify of failures via email.
All these settings are configurable, to read more see the documentation for the backup gem https://github.com/meskyanichi/backup and setup your configuration to suit yourself.
If you use the whenever gem to manage application crontabs, automatically include the capistrano hooks to run whenever each deploy via:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
Copyright (c) 2012 Abletech http://www.abletech.co.nz/