Skip to content

Commit

Permalink
updated the redis cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
scoop206 committed Sep 14, 2012
1 parent de82bba commit beb175c
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 219 deletions.
12 changes: 12 additions & 0 deletions redis/README.md
@@ -0,0 +1,12 @@
Description
===========

Requirements
============

Attributes
==========

Usage
=====

29 changes: 5 additions & 24 deletions redis/attributes/default.rb
@@ -1,33 +1,14 @@
#
# Cookbook Name:: redis
# Attributes:: default
#
# Copyright 2010, Blue Box Group, LLC
#
# 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.
#

# Installation requirements.
default[:redis][:version] = "2.0.3"
default[:redis][:version] = "2.4.8"
default[:redis][:dir] = "/usr/local/redis"
default[:redis][:dirs] = [ "#{default[:redis][:dir]}/bin", "#{default[:redis][:dir]}/etc", "#{default[:redis][:dir]}/log", "/var/run/redis/" ]
default[:redis][:binaries] = %w(redis-benchmark redis-cli redis-server)
default[:redis][:dirs] = %w(bin etc log run)
default[:redis][:binaries] = %w(redis-benchmark redis-cli redis-server redis-check-aof redis-check-dump)

# Configuration requirements.
default[:redis][:daemonize] = "yes"
default[:redis][:pidfile] = "/var/run/redis/redis.pid"
default[:redis][:pidfile] = "#{node[:redis][:dir]}/run/redis.pid"
default[:redis][:port] = "6379"
default[:redis][:bind] = "127.0.0.1"
default[:redis][:bind] = "0.0.0.0"
default[:redis][:timeout] = "300"
default[:redis][:loglevel] = "notice"
default[:redis][:logfile] = "#{default[:redis][:dir]}/log/redis.log"
Expand Down
143 changes: 5 additions & 138 deletions redis/metadata.rb
@@ -1,140 +1,7 @@
maintainer "Blue Box Group, LLC"
maintainer_email "support@blueboxgrp.com"
license "Apache v2.0"
description "Installs and configures Redis."
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.1.0"
recipe "redis", "Installs Redis with a base configuration and init script."

maintainer_email "support@bluebox.net"
license "Apache 2.0"
description "Installs/Configures redis"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.1"
depends "build-essential"

%w{centos redhat debian ubuntu}.each do |os|
supports os
end

attribute "redis",
:display_name => "Redis Hash",
:description => "Hash of Redis attributes",
:type => "hash"

attribute 'redis/version',
:display_name => "Redis Version",
:description => "The version of Redis to install",
:default => "2.0.3"

attribute 'redis/dir',
:display_name => "Redis Directory",
:description => "The Redis installation directory",
:default => "/usr/local/redis"

attribute 'redis/dirs',
:display_name => "Redis Directories",
:description => "Additional directories that must be created for a successful installation",
:type => "array",
:default => [ "#{default[:redis][:dir]}/bin", "#{default[:redis][:dir]}/etc", "#{default[:redis][:dir]}/log", "/var/run/redis/" ]

attribute 'redis/binaries',
:display_name => "Redis Binaries",
:description => "Binaries created after compile that should be installed"
:type => "array",
:default => [ "redis-benchmark", "redis-cli", "redis-server" ]

attribute 'redis/daemonize',
:display_name => "Redis Daemonize",
:description => "Run Redis as a daemon",
:default => "yes"

attribute 'redis/pidfile',
:display_name => "Redis PID File",
:description => "Path to Redis PID file",
:default => "/var/run/redis/redis.pid"

attribute 'redis/port',
:display_name => "Redis Port",
:description => "Accept Redis connections on this port",
:default => "6379"

attribute 'redis/bind',
:display_name => "Redis Interface",
:description => "Interface Redis will bind to",
:default => "127.0.0.1"

attribute 'redis/timeout',
:display_name => "Redis Timeout",
:description => "Close the connection after a client is idle for N seconds",
:default => "300"

attribute 'redis/loglevel',
:display_name => "Redis Log Level",
:description => "Level of logging to be done by Redis",
:default => "notice"

attribute 'redis/logfile',
:display_name => "Redis Log File",
:description => "Path to Redis log file",
:default => "#{default[:redis][:dir]}/log/redis.log"

attribute 'redis/databases',
:display_name => "Redis Databases",
:description => "Number of Redis databases",
:default => "16"

attribute 'redis/appendonly',
:display_name => "Redis Append Only"
:description => "Append write operations to file on disk",
:default => "no"

attribute 'redis/appendfsync',
:display => "Redis Append Fsync",
:description => "Redis fsync mode",
:default => "everysec"

attribute 'redis/vm_enabled',
:display "Redis Enable VM",
:description => "Redis virtual memory",
:default => "no"

attribute 'redis/vm_swap_file',
:display => "Redis VM Swap File",
:description => "Path to Redis swap file",
:default => "/tmp/redis.swap"

attribute 'redis/vm_max_memory',
:display => "Redis VM Max Memory",
:description => "Configures the VM to use at max the specified amount of RAM",
:default => "0"

attribute 'redis/vm_page_size',
:display => "Redis VM Page Size",
:description => "Size of Redis VM Pages",
:default => "32"

attribute 'redis/vm_pages',
:display => "Redis VM Pages",
:description => "Number of total memory pages in Redis swap file",
:default => "134217728"

attribute 'redis/vm_max_threads',
:display => "Redis VM Max Threads",
:description => "Max number of VM I/O threads running at the same time",
:default => "4"

attribute 'redis/glueoutputbuf',
:display => "Redis Glue Output Buffer",
:description => "Glue small output buffers together in order to send small replies in a single TCP packet",
:default => "yes"

attribute 'redis/hash_max_zipmap_entries',
:display => "Redis Hash Max ZipMap Entries",
:description => "Max number of elements to store in Redis hash",
:default => "64"

attribute 'redis/hash_max_zipmap_value',
:display => "Redis Hash Max ZipMap Value",
:description => "Max size of element(s) stored in Redis hash",
:default => "512"

attribute 'redis/activerehashing',
:display "Redis Active Rehashing",
:description => "Active rehashing against the main Redis hash table",
:default => "yes"
128 changes: 71 additions & 57 deletions redis/recipes/default.rb
@@ -1,108 +1,122 @@
#
# Cookbook Name:: redis
# Recipe:: default
#
# Copyright 2010, Blue Box Group, LLC
#
# 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.
#

# Make sure we can build Redis from source.
include_recipe "build-essential"
include_recipe "blocks_firewall"

# Create the redis group.
group "redis" do
action :create
end

# Create the redis user.
user "redis" do
comment "Redis Administrator"
system true
shell "/sbin/nologin"
end

# Create the root of our installation.
directory "#{node[:redis][:dir]}" do
owner "redis"
group "redis"
#group "redis" # See issue below.
mode "0755"
action :create
end

# Create the rest of the directories.
node[:redis][:dirs].each do |dir|
unless File.directory? dir
directory dir do
unless File.directory? node[:redis][:dir] + "/" + dir
directory node[:redis][:dir] + "/" + dir do
owner "redis"
group "redis"
#group "redis" # See issue below.
mode "0755"
recursive true
action :create
end
end
end

# Unfortunately we're hitting a bug in Chef that they've yet to resolve. This means we can't use the 'group' attribute to set proper ownership
# on the directories we created above. We'll have to use this until the resolve the issue.
# Bug report: http://tickets.opscode.com/browse/CHEF-1699
execute "chown-redis-dir" do
user "root"
command "chown redis:redis #{node[:redis][:dir]}"
end

node[:redis][:dirs].each do |dir|
execute "chown-redis-#{dir}" do
user "root"
command "chown redis:redis #{node[:redis][:dir]}/#{dir}"
end
end

# Grab the tarball for our specified version.
remote_file "/tmp/redis-#{node[:redis][:version]}.tar.gz" do
source "http://redis.googlecode.com/files/redis-#{node[:redis][:version]}.tar.gz"
backup false
action :create_if_missing
not_if "#{node[:redis][:dir]}/bin/redis-server --version | grep #{node[:redis][:version]}" # Don't download if we already have this version installed.
end

# Compile redis.
bash "compile-redis" do
cwd "/tmp"
code <<-EOH
tar zxf redis-#{node[:redis][:version]}.tar.gz
cd redis-#{node[:redis][:version]} && make
EOH
not_if "test -x #{node[:redis][:dir]}/bin/redis-server"
not_if "#{node[:redis][:dir]}/bin/redis-server --version | grep #{node[:redis][:version]}" # Don't compile if we already have this version installed.
end

# Move our binaries to the specified redis directory.
node[:redis][:binaries].each do |bin|
execute "installing-#{bin}" do
user "root"
command "cp -a /tmp/redis-#{node[:redis][:version]}/#{bin} #{node[:redis][:dir]}/bin/#{bin}"
creates "#{node[:redis][:dir]}/bin/#{bin}"
ruby_block "installing-binaries" do
block do
node[:redis][:binaries].each do |bin|
if File.exist?(node[:redis][:dir] + "/bin/" + bin) # If destination binary exists, then we need to compare our fresh compile w/ what's there.
unless File.read("/tmp/redis-#{node[:redis][:version]}/src/#{bin}") == File.read("#{node[:redis][:dir]}/bin/#{bin}") # Unless the files are the same...
system("cp -a /tmp/redis-#{node[:redis][:version]}/src/#{bin} #{node[:redis][:dir]}/bin/#{bin}") # Copy them over.
end
else
system("cp -a /tmp/redis-#{node[:redis][:version]}/src/#{bin} #{node[:redis][:dir]}/bin/#{bin}") # These were safe to move w/o comparing.
end
end
end
end
end

# Create profile.d script to add redis directory to $PATH.
template "/etc/profile.d/redis.sh" do
source "redis.sh"
mode "0755"
backup false
not_if "echo $PATH | grep '#{node[:redis][:dir]}/bin'"
end

# Create init script.
template "/etc/init.d/redis-server" do
source "redis-init"
owner "root"
group "root"
source "redis.sh.erb"
mode "0755"
backup false
end

# Define our new service.
service "redis-server" do
supports :start => true, :stop => true, :restart => true
action :nothing
# setup and start init per platform
case node[:platform]
when "centos","redhat","scientific"
template "/etc/init.d/redis-server" do
owner "root"
group "root"
source "redis-init.erb"
mode "0755"
backup false
end

service "redis-server" do
supports :start => true, :stop => true, :restart => true
action :enable
end
when "ubuntu"
template "/etc/init/redis-server.conf" do
owner "root"
group "root"
source "redis-upstart.conf.erb"
mode "0755"
backup false
end

link "/etc/init.d/redis-server" do
to "/lib/init/upstart-job"
end

service "redis-server" do
provider Chef::Provider::Service::Upstart
supports :status => true, :restart => true, :reload => true
action [ :enable, :start ]
end
end

# Create configuration file.
template "#{node[:redis][:dir]}/etc/redis.conf" do
source "redis.conf"
source "redis.conf.erb"
mode "0644"
backup false
notifies :restart, "service[redis-server]", :immediately
Expand Down

0 comments on commit beb175c

Please sign in to comment.