Created
May 7, 2012 18:30
-
-
Save andrewgross/2629495 to your computer and use it in GitHub Desktop.
Redis Cookbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up our disk | |
include_recipe "data_volume::default" | |
data_volume "/var/lib/redis" do | |
action :create | |
size 16 | |
provider "data_volume" | |
not_if "grep '/var/lib/redis' /etc/fstab > /dev/null" | |
end | |
# Find our hostname, see if we are a slave | |
node_hostname = Chef::Config[:node_name].gsub(/_/, '-') | |
if node_hostname.include? 'slave' | |
masternode = search(:node, "role:*_redis_master") | |
slaveof = true | |
masterip = masternode[0][:ipaddress] | |
masterport = '6379' | |
end | |
# Add the PPA, addition is idempotent | |
execute "install redis ppa" do | |
command "apt-add-repository ppa:chris-lea/redis-server" | |
user "root" | |
end | |
execute "apt-get update" do | |
command "apt-get update" | |
user "root" | |
ignore_failure true | |
end | |
package "redis-server" do | |
action :install | |
end | |
execute "set redis permissions" do | |
command "chown -R redis:redis /var/lib/redis" | |
end | |
# The variables here should all be set by using the name of the config option | |
# with the "-" replaced with "_". If empty, they will use the redis defaults | |
template "/etc/redis/redis.conf" do | |
source "redis.conf.erb" | |
owner "root" | |
group "root" | |
variables( | |
:slaveof => slaveof, | |
:masterip => masterip, | |
:masterport => masterport | |
) | |
mode 0644 | |
notifies :restart, "service[redis-server]" | |
end | |
service "redis-server" do | |
supports :start => true, :stop => true, :restart => true | |
action [ :enable, :start ] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment