Permalink
Browse files

adding memcached cookbook

  • Loading branch information...
1 parent 7e3471c commit e9afaf33d85fd0934da091783f911d57d3f2135d @mdxp committed Oct 18, 2011
View
@@ -0,0 +1,52 @@
+= DESCRIPTION:
+
+Installs memcached and provides a define to set up an instance of memcache via runit.
+
+= REQUIREMENTS:
+
+== Platform:
+
+Tested on Ubuntu 8.10-9.10. Uses the memcached init script by default. A runit service can be set up for instances using the included define.
+
+== Cookbooks:
+
+Opscode cookbooks, http://github.com/opscode/cookbooks/tree/master:
+
+* runit
+
+= ATTRIBUTES:
+
+The following are node attributes passed to the template for the runit service.
+
+* memcached[:memory] - maximum memory for memcached instances.
+* memcached[:user] - user to run memcached as.
+* memcached[:port] - port for memcached to listen on.
+* memcached[:listen] - IP address for memcached to listen on.
+
+= 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 define, memcached_instance, to set up a runit service for the named memcached instance.
+
+ memcached_instance "myproj"
+
+= LICENSE and AUTHOR:
+
+Author:: Joshua Timberman (<joshua@opscode.com>)
+Author:: Joshua Sierles (<joshua@37signals.com>)
+
+Copyright:: 2009, Opscode, Inc
+Copyright:: 2009, 37signals
+
+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.
@@ -0,0 +1,4 @@
+default[:memcached][:memory] = 64
+default[:memcached][:port] = 11211
+default[:memcached][:user] = "nobody"
+default[:memcached][:listen] = "0.0.0.0"
@@ -0,0 +1,32 @@
+#
+# Cookbook Name:: memcached
+# Definition:: memcached_instance
+#
+# Copyright 2009, Opscode, 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.
+#
+
+define :memcached_instance do
+ include_recipe "memcached"
+
+ runit_service "memcached-#{params[:name]}" do
+ template_name "memcached"
+ cookbook "memcached"
+ options({
+ :memory => node[:memcached][:memory],
+ :port => node[:memcached][:port],
+ :user => node[:memcached][:user]}.merge(params)
+ )
+ end
+end
View
@@ -0,0 +1,33 @@
+maintainer "Opscode, Inc."
+maintainer_email "cookbooks@opscode.com"
+license "Apache 2.0"
+description "Installs memcached and provides a define to set up an instance of memcache via runit"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version "0.10.4"
+depends "runit"
+
+recipe "memcached", "Installs and configures memcached"
+
+%w{ ubuntu debian }.each do |os|
+ supports os
+end
+
+attribute "memcached/memory",
+ :display_name => "Memcached Memory",
+ :description => "Memory allocated for memcached instance",
+ :default => "64"
+
+attribute "memcached/port",
+ :display_name => "Memcached Port",
+ :description => "Port to use for memcached instance",
+ :default => "11211"
+
+attribute "memcached/user",
+ :display_name => "Memcached User",
+ :description => "User to run memcached instance as",
+ :default => "nobody"
+
+attribute "memcached/listen",
+ :display_name => "Memcached IP Address",
+ :description => "IP address to use for memcached instance",
+ :default => "0.0.0.0"
@@ -0,0 +1,56 @@
+#
+# Cookbook Name:: memcached
+# Recipe:: default
+#
+# Copyright 2009, Opscode, 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.
+#
+
+package "memcached" do
+ action :upgrade
+end
+
+package "libmemcache-dev" do
+ action :upgrade
+end
+
+service "memcached" do
+ action :nothing
+ supports :status => true, :start => true, :stop => true, :restart => true
+end
+
+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],
+ :memory => node[:memcached][:memory]
+ )
+ notifies :restart, resources(:service => "memcached"), :immediately
+end
+
+case node[:lsb][:codename]
+when "karmic"
+ template "/etc/default/memcached" do
+ source "memcached.default.erb"
+ owner "root"
+ group "root"
+ mode "0644"
+ notifies :restart, resources(:service => "memcached"), :immediately
+ end
+end
@@ -0,0 +1,50 @@
+#
+# Configured by Chef. Logcal changes will be lost.
+#
+# memcached default config file
+# 2003 - Jay Bonci <jaybonci@debian.org>
+# This configuration file is read by the start-memcached script provided as
+# part of the Debian GNU/Linux distribution.
+
+# Run memcached as a daemon. This command is implied, and is not needed for the
+# daemon to run. See the README.Debian that comes with this package for more
+# information.
+-d
+
+# Log memcached's output to /var/log/memcached
+logfile /var/log/memcached.log
+
+# Be verbose
+-v
+
+# Be even more verbose (print client commands as well)
+# -vv
+
+# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
+# Note that the daemon will grow to this size, but does not start out holding this much
+# memory
+-m <%= @memory %>
+
+# Default connection port is 11211
+-p <%= @port %>
+
+# Run the daemon as root. The start-memcached will default to running as root if no
+# -u command is present in this config file
+-u <%= @user %>
+
+# Specify which IP address to listen on. The default is to 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.
+-l <%= @listen %>
+
+# Limit the number of simultaneous incoming connections. The daemon default is 1024
+# -c 1024
+
+# Lock down all paged memory. Consult with the README and homepage before you do this
+# -k
+
+# Return error when memory is exhausted (rather than removing items)
+# -M
+
+# Maximize core file limit
+# -r
@@ -0,0 +1,2 @@
+# Set this to yes to enable memcached.
+ENABLE_MEMCACHED=yes
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec svlogd -tt ./main
@@ -0,0 +1,3 @@
+#!/bin/sh
+exec 2>&1
+exec chpst -u <%= @options[:user] %> /usr/bin/memcached -v -m <%= @options[:memory] %> -p <%= @options[:port] %>

0 comments on commit e9afaf3

Please sign in to comment.