No commit activity in last 3 years
No release in over 3 years
Capistrano tasks for automatic and sensible memcached configuration. Enables zero downtime deployments of Rails applications. Configs can be copied to the application using generators and easily customized. Works *only* with Capistrano 3+. Heavily inspired (i.e. copied and reworked) by https://github.com/bruno-/capistrano-unicorn-nginx
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 1.2.0
 Project Readme

Capistrano::Memcached

Capistrano tasks for automatic memcached configuration.

Goals of this plugin:

  • automatic memcached configuration for Rails apps
  • no manual ssh to the server required

Specifics:

  • generates config file on the server (default in /etc/memcached.conf)
  • generates a memcached.yml config file in shared/config for easy consumption by a RoR app
  • capistrano tasks for management, example: memcached:restart
    see below for all available tasks

capistrano-memcached works only with Capistrano 3!

This project was heavily inspired (i.e. copied and reworked) by capistrano-nginx-unicorn and capistrano-recipes.

Installation

Add this to Gemfile:

group :development do
  gem 'capistrano', '~> 3.1'
  gem 'capistrano-memcached', '~> 1.0'
end

And then:

$ bundle install

Setup and usage

Add this line to Capfile

require 'capistrano/memcached'

Setup task

Make sure the deploy_to path exists and has the right privileges on the server (i.e. /var/www/myapp).
Or just install capistrano-safe-deploy-to plugin and don't think about it.

To setup the memcached server run:

$ bundle exec cap production setup

This will generate the memcached.conf and a memcached.yml file with the hostname + port where memcached is running. This can be used to configure Dalli, for example.

Configuration

As described in the Usage section, this plugin works with minimal setup. However, configuration is possible.

You'll find the options and their defaults below.

In order to override the default, put the option in the stage file, for example:

# in config/deploy/production.rb
set :memcached_listen_port, 11212

Defaults are listed near option name in the first line.

  • set :memcached_memory_limit # defaults to 128
    The memory limit of memcached in MB.

  • set :memcached_log_file, "/var/log/memcached.log"
    Location of memcached log file.

  • set :memcached_port, "11211"
    The port memcached listens on.

  • set :memcached_ip, "127.0.0.1" # default listen only on localhost (for security)
    The IP memcached listens on. If set to :all, memcached will listen on all IP addresses. This parameter is one of the only security measures that memcached has, so make sure it's listening on a firewalled interface.

  • set :memcached_roles, [:app]
    The roles on which memcached will be installed. memcached.yml will be available to all :app roles.

  • set :memcached_user, "memcache"
    The user account used by memcached.

Template customization

If you want to change default templates, you can generate them using rails generator:

$ bundle exec rails g capistrano:memcached:config

This will copy default templates to config/deploy/templates directory, so you can customize them as you like, and capistrano tasks will use this templates instead of default.

You can also provide path, where to generate templates:

$ bundle exec rails g capistrano:memcached:config config/templates

TODO

  • Configure memcached server and clients for distributed setup.
  • SASL authentication setup for memcached when running on multiple servers.

More Capistrano automation?

If you'd like to streamline your Capistrano deploys, you might want to check these zero-configuration, plug-n-play plugins:

Bug reports and pull requests

...are very welcome!

Thanks

@bruno- - for his capistrano-unicorn-nginx plugin on which this one is heavily based.