Skip to content

Commit

Permalink
Merge pull request #47 from stonith/fix_memcached_instance
Browse files Browse the repository at this point in the history
Fix memcached instance
  • Loading branch information
stonith committed Aug 11, 2015
2 parents 58e9e8f + 22dd818 commit 9cf6f65
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 152 deletions.
72 changes: 72 additions & 0 deletions .kitchen.cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
driver_plugin: vagrant
driver_plugin: digitalocean
driver_config:
digitalocean_client_id: <%= ENV['DIGITAL_OCEAN_CLIENT_ID'] %>
digitalocean_api_key: <%= ENV['DIGITAL_OCEAN_API_KEY'] %>
aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
aws_ssh_key_id: <%= ENV['AWS_KEYPAIR_NAME'] %>
ssh_key: <%= ENV['AWS_PRIVATE_KEY_PATH'] %>
rackspace_username: <%= ENV['RACKSPACE_USERNAME'] %>
rackspace_api_key: <%= ENV['RACKSPACE_API_KEY'] %>
require_chef_omnibus: latest

platforms:
- name: centos-5.8
driver_plugin: digitalocean
driver_config:
image_id: 1601
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>

- name: centos-6.4
driver_plugin: digitalocean
driver_config:
image_id: 562354
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>

- name: amazon-2013.09
driver_plugin: ec2
driver_config:
image_id: ami-3be4bc52
username: ec2-user

# - name: fedora-19
# driver_plugin: digitalocean
# driver_config:
# image_id: 696598
# flavor_id: 63
# region_id: 1
# ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>

- name: ubuntu-1004
driver_plugin: digitalocean
driver_config:
image_id: 14097
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
run_list:
- recipe[apt]

- name: ubuntu-1204
driver_plugin: digitalocean
driver_config:
image_id: 1505447
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
run_list:
- recipe[apt]

suites:
- name: default
run_list:
- recipe[memcached::default]
- name: instance
run_list:
- recipe[fake::instance]
62 changes: 10 additions & 52 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,23 @@
---
driver_plugin: vagrant
driver_plugin: digitalocean
driver_config:
digitalocean_client_id: <%= ENV['DIGITAL_OCEAN_CLIENT_ID'] %>
digitalocean_api_key: <%= ENV['DIGITAL_OCEAN_API_KEY'] %>
aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
aws_ssh_key_id: <%= ENV['AWS_KEYPAIR_NAME'] %>
ssh_key: <%= ENV['AWS_PRIVATE_KEY_PATH'] %>
rackspace_username: <%= ENV['RACKSPACE_USERNAME'] %>
rackspace_api_key: <%= ENV['RACKSPACE_API_KEY'] %>
require_chef_omnibus: latest

platforms:
- name: centos-5.8
driver_plugin: digitalocean
driver_config:
image_id: 1601
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
provisioner:
name: chef_zero

- name: centos-6.4
driver_plugin: digitalocean
driver_config:
image_id: 562354
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
platforms:
- name: centos-5.10

- name: amazon-2013.09
driver_plugin: ec2
driver_config:
image_id: ami-3be4bc52
username: ec2-user
- name: centos-6.6

# - name: fedora-19
# driver_plugin: digitalocean
# driver_config:
# image_id: 696598
# flavor_id: 63
# region_id: 1
# ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
- name: ubuntu-10.04
run_list:
- recipe[apt]

- name: ubuntu-1004
driver_plugin: digitalocean
driver_config:
image_id: 14097
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
- name: ubuntu-12.04
run_list:
- recipe[apt]

- name: ubuntu-1204
driver_plugin: digitalocean
driver_config:
image_id: 1505447
flavor_id: 63
region_id: 1
ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %>
- name: ubuntu-14.04
run_list:
- recipe[apt]

Expand Down
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
site 'https://supermarket.chef.io'
source 'https://supermarket.chef.io'
metadata

group :integration do
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ The following are node attributes passed to the template for the runit service.
- `memcached['maxconn']` - maximum number of connections to accept (defaults to 1024)
- `memcached['max_object_size']` - maximum size of an object to cache (defaults to 1MB)
- `memcached['logfilename']` - logfile to which memcached output will be redirected in /var/log/$logfilename.

- `memcached['threads']` - Number of threads to use to process incoming requests. The default is 4.
- `memcached['experimental_options']` - Comma separated list of extended or experimental options. (array)
- `memcached['ulimit']` - boolean `true` will set the ulimit to the `maxconn` value

Usage
-----
Simply set the attributes and it will configure the `/etc/memcached.conf` file. If you want to use multiple memcached instances, you'll need to modify the recipe to disable the startup script and the template in the default recipe.

Use the definition, `memcached_instance`, to set up a runit service for the named memcached instance.
Use the definition, `memcached_instance`, to set up a runit service for the named memcached instance. (If the instance name is `memcached` the service name will be `memcached` otherwise it will be `memcached-#{service_name}`)

```ruby
```
memcached_instance 'myproj'
```

Expand Down
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
# limitations under the License.
#

default['memcached']['version'] = nil
default['memcached']['memory'] = 64
default['memcached']['port'] = 11_211
default['memcached']['udp_port'] = 11_211
default['memcached']['listen'] = '0.0.0.0'
default['memcached']['maxconn'] = 1024
default['memcached']['max_object_size'] = '1m'
default['memcached']['logfilepath'] = '/var/log/'
default['memcached']['logfilename'] = 'memcached.log'

case node['platform_family']
Expand Down
25 changes: 16 additions & 9 deletions definitions/memcached_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@
#

define :memcached_instance do
include_recipe 'runit::default'
include_recipe 'memcached::default'
include_recipe 'runit'
include_recipe 'memcached::package'

instance_name = params[:name] == 'memcached' || params[:name] == nil ? 'memcached' : "memcached-#{params[:name]}"

opts = params

runit_service "memcached-#{params[:name]}" do
runit_service instance_name do
run_template_name 'memcached'
default_logger true
cookbook 'memcached'
options({
:memory => node['memcached']['memory'],
:port => node['memcached']['port'],
:listen => node['memcached']['listen'],
:maxconn => node['memcached']['maxconn'],
:user => node['memcached']['user']
:memory => node['memcached']['memory'],
:port => node['memcached']['port'],
:udp_port => node['memcached']['udp_port'],
:listen => node['memcached']['listen'],
:maxconn => node['memcached']['maxconn'],
:user => node['memcached']['user'],
:threads => node['memcached']['threads'],
:max_object_size => node['memcached']['max_object_size'],
:experimental_options => Array(node['memcached']['experimental_options']),
:ulimit => node['memcached']['ulimit']
}.merge(opts))
end
end
end
77 changes: 77 additions & 0 deletions recipes/configure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Cookbook Name:: memcached
# Recipe:: default
#
# Copyright 2009-2013, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

directory node['memcached']['logfilepath']

service 'memcached' do
action :enable
supports :status => true, :start => true, :stop => true, :restart => true, :enable => true
end

case node['platform_family']
when 'rhel', 'fedora', 'suse'
family = node['platform_family'] == 'suse' ? 'suse' : 'redhat'
template '/etc/sysconfig/memcached' do
source "memcached.sysconfig.#{family}.erb"
owner 'root'
group 'root'
mode '0644'
variables(
:listen => node['memcached']['listen'],
:user => node['memcached']['user'],
:group => node['memcached']['group'],
:port => node['memcached']['port'],
:udp_port => node['memcached']['udp_port'],
:maxconn => node['memcached']['maxconn'],
:memory => node['memcached']['memory'],
:logfilepath => node['memcached']['logfilepath'],
:logfilename => node['memcached']['logfilename'],
:threads => node['memcached']['threads'],
:max_object_size => node['memcached']['max_object_size']
)
notifies :restart, 'service[memcached]'
end
when 'smartos'
# SMF directly configures memcached with no opportunity to alter settings
# If you need custom parameters, use the memcached_instance provider
service 'memcached' do
action :enable
end
else
template '/etc/memcached.conf' do
source 'memcached.conf.erb'
owner 'root'
group 'root'
mode '0644'
variables(
:listen => node['memcached']['listen'],
:user => node['memcached']['user'],
:port => node['memcached']['port'],
:udp_port => node['memcached']['udp_port'],
:maxconn => node['memcached']['maxconn'],
:memory => node['memcached']['memory'],
:logfilepath => node['memcached']['logfilepath'],
:logfilename => node['memcached']['logfilename'],
:threads => node['memcached']['threads'],
:max_object_size => node['memcached']['max_object_size'],
:experimental_options => Array(node['memcached']['experimental_options'])
)
notifies :restart, 'service[memcached]'
end
end
74 changes: 2 additions & 72 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,5 @@
# limitations under the License.
#

# include epel on redhat/centos 5 and below in order to get the memcached packages
include_recipe 'yum-epel' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5

package 'memcached'

package 'libmemcache-dev' do
case node['platform_family']
when 'rhel', 'fedora'
package_name 'libmemcached-devel'
when 'smartos'
package_name 'libmemcached'
when 'suse'
if node['platform_version'].to_f < 12
package_name 'libmemcache-devel'
else
package_name 'libmemcached-devel'
end
else
package_name 'libmemcache-dev'
end
end

service 'memcached' do
action :enable
supports :status => true, :start => true, :stop => true, :restart => true, :enable => true
end

case node['platform_family']
when 'rhel', 'fedora', 'suse'
family = node['platform_family'] == 'suse' ? 'suse' : 'redhat'
template '/etc/sysconfig/memcached' do
source "memcached.sysconfig.#{family}.erb"
owner 'root'
group 'root'
mode '0644'
variables(
:listen => node['memcached']['listen'],
:user => node['memcached']['user'],
:group => node['memcached']['group'],
:port => node['memcached']['port'],
:udp_port => node['memcached']['udp_port'],
:maxconn => node['memcached']['maxconn'],
:memory => node['memcached']['memory'],
:max_object_size => node['memcached']['max_object_size'],
:logfilename => node['memcached']['logfilename']
)
notifies :restart, 'service[memcached]'
end
when 'smartos'
# SMF directly configures memcached with no opportunity to alter settings
# If you need custom parameters, use the memcached_instance provider
service 'memcached' do
action :enable
end
else
template '/etc/memcached.conf' do
source 'memcached.conf.erb'
owner 'root'
group 'root'
mode '0644'
variables(
:listen => node['memcached']['listen'],
:user => node['memcached']['user'],
:port => node['memcached']['port'],
:udp_port => node['memcached']['udp_port'],
:maxconn => node['memcached']['maxconn'],
:memory => node['memcached']['memory'],
:max_object_size => node['memcached']['max_object_size']
)
notifies :restart, 'service[memcached]'
end
end
include_recipe 'memcached::package'
include_recipe 'memcached::configure'
Loading

0 comments on commit 9cf6f65

Please sign in to comment.