Skip to content

Mindera/twemproxy-cookbook

Repository files navigation

Twemproxy Cookbook

Build Status

Chef coookbook to install and manage Twemproxy.

Requirements

None.

Platforms

  • Centos 6+
  • RedHat 6+

Usage

This cookbook can be used both by including its recipes and being attribute-driven or simply by calling the available providers within your own cookbook.

Attributes

default.rb

Attribute Type Description Options Default
['twemproxy']['mirror'] String Artifact mirror - https://github.com/twitter/twemproxy/archive
['twemproxy']['version'] String Artifact version - v0.4.1
['twemproxy']['file_name'] String Artifact name Defaults to nil since it fetches from the github archives. nil
['twemproxy']['artifact_type'] String Artifact type - tar.gz
<['twemproxy']['update_config']/tt> TrueClass/FalseClass Manage twemproxy configs after the initial run - you want to disable this is you update configs via sentinels - true
<['twemproxy']['config_dir']/tt> String Config directory - /etc/nutcracker
<['twemproxy']['log_dir']/tt> String Log directory - /var/log/nutcracker
<['twemproxy']['pid_dir']/tt> String PID directory - /var/run/nutcracker
<['twemproxy']['user']/tt> String User to run as - nutcracker
<['twemproxy']['group']/tt> String Group to run as - nutcracker
<['twemproxy']['config']/tt> String Config hash to be converted as the yaml nutcracker configuration file Required - the run will fail if you don't set this attribute - be warned! nil

Recipes

All of this cookbook recipes use the available providers under the hood as described below in the providers section.

default.rb

Installs, configures and enable/starts the twemproxy service.

install.rb

Install twemproxy by compiling it from a source artifact.

configure.rb

Configure twemproxy by doing all the system required tasks (create users, create directories, etc.) and build the yaml configuration file.

service.rb

Set twemproxy as a service and enable/start it.

Example

Add the twemproxy cookbook as a dependency:

depends 'twemproxy'

Set a twemproxy config as:

default['twemproxy']['config'] = {
  'default' => {
    'listen' => '0.0.0.0:6379',
    'hash' => 'fnv1a_64',
    'distribution' => 'ketama',
    'auto_eject_hosts' => false,
    'redis' => true,
    'preconnect' => true,
    'server_retry_timeout' => 2000,
    'server_failure_limit' => 1,
    'servers' => [
      '172.31.254.103:6380:1 redis_1',
    ]
  }
}

To install, configure, enable and start twemproxy:

Include the twemproxy::default recipe:

include_recipe 'twemproxy::default'

To install and configure but not create or start the service

Include the twemproxy::install and twemproxy::configure recipe:

include_recipe 'twemproxy::install'
include_recipe 'twemproxy::configure'

Providers

twemproxy_install

The twemproxy_install provider downloads and install twemproxy from a source artifact.

It does not configure or starts it.

Actions

It only has a default :run action available.

Attributes

The majority of the available attributes mimic the node attributes used by the recipes above.

Attribute Type Required
mirror String No
version String No
file_name String No
download_dir String No
artifact_type String No

Example

Install twemproxy with the default options:

twemproxy_install 'twemproxy'

Install twemproxy by providing the download options:

twemproxy_install 'twemproxy' do
    mirror 'https://github.com/twitter/twemproxy/archive''
    version 'v0.4.1'
    file_name ''
    download_dir '/var/tmp'
    artifact_type 'tar.gz'
end

twemproxy_configure

The twemproxy_twemproxy provider performs all the required system tasks and deploys the yaml configuration file.

It does not install or starts it.

Actions

It only has a default :run action available.

Attributes

The majority of the available attributes mimic the node attributes used by the recipes above.

Attribute Type Required
config Hash Yes
update_config TrueClass/FalseClass No
config_dir String No
log_dir String No
pid_dir String No
user String No
group String No

Example

Configure twemproxy with the default options and the provided config:

twemproxy_configuration 'twemproxy' do
    config config_hash
end

twemproxy_service

The twemproxy_service provider performs all the required system tasks to start and/or enable twemproxy as a service.

It deploys a sysV init script - feel free to add support for other init systems and PR your changes.

It does not install or configure it.

Actions

It has a default :run action available which is the equivalent to using the [:enable, :restart] actions.

Available actions:

Actions Description
:run Default action - enable and restarts the service
:enable Enable the service
:start Start the service
:restart Restart the service

Attributes

The majority of the available attributes mimic the node attributes used by the recipes above.

Attribute Type Required
config_dir String No
log_dir String No
pid_dir String No
user String No

Example

Enable and restart twemproxy service with the default options:

twemproxy_service 'twemproxy'

Enable and restart twemproxy service with custom options:

twemproxy_service 'twemproxy' do
    config_dir '/etc/nutcracker'
    log_dir '/var/log/nutcracker'
    pid_dir '/var/run/nutcracker'
    user 'nutcracker'
end

Development / Contributing

Dependencies

Installation

$ git clone git@github.com:Mindera/twemproxy-cookbook.git
$ cd twemproxy-cookbook
$ bundle install

Tests

To run unit tests (chefspec):

$ bundle exec rake unit

To run lint tests (rubocop, foodcritic):

$ bundle exec rake lint

To run integration tests (kitchen-ci, serverspec):

$ bundle exec rake integration