Help needed with memcached instances


#1

Env: Ubuntu 9.10 running chef 0.8.12

Problem: need to run multiple instances of memcached on one host, but seem to be doing something all wrong.

for the recipe below I have to create a template for each runit instance, also in the define the “#{params[:name]}” is not passed along.

joshua-millers-macbook-pro:site-cookbooks jmiller$ ls -l memcached/templates/default/sv-memcached-11212-*
-rw-r–r-- 1 jmiller staff 33 May 17 23:58 memcached/templates/default/sv-memcached-11212-log-run.erb
-rw-r–r-- 1 jmiller staff 133 May 17 23:55 memcached/templates/default/sv-memcached-11212-run.erb
joshua-millers-macbook-pro:site-cookbooks jmiller$

So I can hack around all this and get a fully working instance but to do that I had to do two defines with hard coded settings, and template for each instance … kind of defeats the point of using any variables.

Question is am I missing something major, is there a better way, or am I just hitting a limit of the runit_service

Thank you,

Joshua

Modified Recipe:
joshua-millers-macbook-pro:site-cookbooks jmiller$ more memcached/recipes/default.rb

package “memcached” do
action :upgrade
end

package “libmemcache-dev” do
action :upgrade
end

node[:memcached][:ports].each do |port|

memcached_instance “#{port}”

end

joshua-millers-macbook-pro:site-cookbooks jmiller$

Memcached_Instance_Def:

joshua-millers-macbook-pro:site-cookbooks jmiller$ more memcached/definitions/memcached_instance.rb

define :memcached_instance do
include_recipe “memcached”

runit_service “memcached-#{params[:name]}” do
options({
:memory => node[:memcached][:memory],
:port => “#{params[:name]}”,
:user => node[:memcached][:user]}.merge(params)
)
end
end

joshua-millers-macbook-pro:site-cookbooks jmiller$

Memcached Modifed Attributes:
joshua-millers-macbook-pro:site-cookbooks jmiller$ more memcached/attributes/default.rb
set_unless[:memcached][:memory] = 7680
set_unless[:memcached][:ports] = [ “11212”,“11213” ]
set_unless[:memcached][:user] = "nobody"
joshua-millers-macbook-pro:site-cookbooks jmiller$