Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into disable_os_default
Browse files Browse the repository at this point in the history
  • Loading branch information
alepore committed Feb 10, 2016
2 parents 1efdaea + 8891054 commit f380a9b
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 29 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The disable recipe just stops redis and removes it from run levels.

The cookbook also contains a recipe to allow for the installation of the redis ruby gem.

Redis-sentinel will write configuration and state data back into its configuration file. This creates obvious problems when that config is managed by chef. There is an attribute set to true which controls if chef manages the redis-sentinel config. By default chef will write out this config file and manage it. If deploying sentenel it is recommened that you set the node[:redisio][:sentinel][:manage_config] to false allowing chef to write out the initial config and then allow redis-sentiniel to manage. If running sentinel it is only advices to have node[:redisio][:sentinel][:manage_config] = true when you are pushing new changes to the config file as it will create a flapping state between chef and sentinel when sentinel writes out state to the file.
Redis-sentinel will write configuration and state data back into its configuration file. This creates obvious problems when that config is managed by chef. This cookbook will create the config file once, and then leave a breadcrumb that will guard against the file from being updated again.

Recipes
-------
Expand Down Expand Up @@ -278,11 +278,12 @@ Available options and their defaults
'ulimit' => 0 - 0 is a special value causing the ulimit to be maxconnections +32. Set to nil or false to disable setting ulimits
'configdir' => '/etc/redis' - configuration directory
'name' => nil, Allows you to name the server with something other than port. Useful if you want to use unix sockets
'tcpbacklog' => '511',
'address' => nil, Can accept a single string or an array. When using an array, the FIRST value will be used by the init script for connecting to redis
'databases' => '16',
'backuptype' => 'rdb',
'datadir' => '/var/lib/redis',
'unixoscket' => nil - The location of the unix socket to use,
'unixsocket' => nil - The location of the unix socket to use,
'unixsocketperm' => nil - The permissions of the unix socket,
'timeout' => '0',
'keepalive' => '0',
Expand All @@ -293,29 +294,40 @@ Available options and their defaults
'shutdown_save' => false,
'save' => nil, # Defaults to ['900 1','300 10','60 10000'] inside of template. Needed due to lack of hash subtraction
'stopwritesonbgsaveerror' => 'yes',
'rdbcompression' => 'yes',
'rdbchecksum' => 'yes',
'dbfilename' => nil,
'slaveof' => nil,
'masterauth' => nil,
'slaveservestaledata' => 'yes',
'slavereadonly' => 'yes',
'replpingslaveperiod' => '10',
'repltimeout' => '60',
'repldisabletcpnodelay => 'no',
'slavepriority' => '100',
'requirepass' => nil,
'rename_commands' => nil, or a hash where each key is a redis command and the value is the command's new name.
'maxclients' => 10000,
'maxmemory' => nil,
'maxmemorypolicy' => nil,
'maxmemorysamples' => nil,
'appendfilename' => nil,
'appendfsync' => 'everysec',
'noappendfsynconrewrite' => 'no',
'aofrewritepercentage' => '100',
'aofrewriteminsize' => '64mb',
'luatimelimit' => '5000',
'slowloglogslowerthan' => '10000',
'slowlog-max-len' => '1024',
'slowlogmaxlen' => '1024',
'notifykeyspaceevents' => '',
'hashmaxziplistentries' => '512',
'hashmaxziplistvalue' => '64',
'listmaxziplistentries' => '512',
'listmaxziplistvalue' => '64',
'setmaxintsetentries' => '512',
'zsetmaxziplistentries' => '128',
'zsetmaxziplistvalue' => '64',
'hllsparsemaxbytes' => '3000',
'activerehasing' => 'yes',
'clientoutputbufferlimit' => [
%w(normal 0 0 0),
Expand All @@ -326,7 +338,7 @@ Available options and their defaults
'aofrewriteincrementalfsync' => 'yes',
'cluster-enabled' => 'no',
'cluster-config-file' => nil, # Defaults to redis instance name inside of template if cluster is enabled.
'cluster-node-timeout' => 5,
'cluster-node-timeout' => 5000,
'includes' => nil
```

Expand Down
19 changes: 16 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
default['redisio']['version'] = nil
else
# force version for tarball
default['redisio']['version'] = '2.8.17'
default['redisio']['version'] = '2.8.20'
end

# Custom installation directory
Expand All @@ -77,9 +77,11 @@
'homedir' => homedir,
'shell' => shell,
'systemuser' => true,
'uid' => nil,
'ulimit' => 0,
'configdir' => '/etc/redis',
'name' => nil,
'tcpbacklog' => '511',
'address' => nil,
'databases' => '16',
'backuptype' => 'rdb',
Expand All @@ -95,29 +97,40 @@
'shutdown_save' => false,
'save' => nil, # Defaults to ['900 1','300 10','60 10000'] inside of template. Needed due to lack of hash subtraction
'stopwritesonbgsaveerror' => 'yes',
'rdbcompression' => 'yes',
'rdbchecksum' => 'yes',
'dbfilename' => nil,
'slaveof' => nil,
'masterauth' => nil,
'slaveservestaledata' => 'yes',
'slavereadonly' => 'yes',
'replpingslaveperiod' => '10',
'repltimeout' => '60',
'repldisabletcpnodelay' => 'no',
'slavepriority' => '100',
'requirepass' => nil,
'rename_commands' => nil,
'maxclients' => 10000,
'maxmemory' => nil,
'maxmemorypolicy' => nil,
'maxmemorysamples' => nil,
'appendfilename' => nil,
'appendfsync' => 'everysec',
'noappendfsynconrewrite' => 'no',
'aofrewritepercentage' => '100',
'aofrewriteminsize' => '64mb',
'luatimelimit' => '5000',
'slowloglogslowerthan' => '10000',
'slowlog-max-len' => '1024',
'slowlogmaxlen' => '1024',
'notifykeyspaceevents' => '',
'hashmaxziplistentries' => '512',
'hashmaxziplistvalue' => '64',
'listmaxziplistentries' => '512',
'listmaxziplistvalue' => '64',
'setmaxintsetentries' => '512',
'zsetmaxziplistentries' => '128',
'zsetmaxziplistvalue' => '64',
'hllsparsemaxbytes' => '3000',
'activerehasing' => 'yes',
'clientoutputbufferlimit' => [
%w(normal 0 0 0),
Expand All @@ -128,7 +141,7 @@
'aofrewriteincrementalfsync' => 'yes',
'clusterenabled' => 'no',
'clusterconfigfile' => nil, # Defaults to redis instance name inside of template if cluster is enabled.
'clusternodetimeout' => 5,
'clusternodetimeout' => 5000,
'includes' => nil
}

Expand Down
2 changes: 1 addition & 1 deletion attributes/redis_sentinel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@

# Manage Sentinel Config File
## Will write out the base config one time then no longer manage the config allowing sentinel to take over
default['redisio']['sentinel']['manage_config'] = true
default['redisio']['sentinel']['manage_config'] = true #deprecated

default['redisio']['sentinels'] = nil
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
recipe "redisio::install", "This recipe is used to install redis"
recipe "redisio::configure", "This recipe is used to configure redis by creating the configuration files and init scripts"
recipe "redisio::sentinel", "This recipe is used to configure redis sentinels by creating the configuration files and init scripts"
recipe "redisio::sentinel_enable", "This recipe is used enable sentinel init scripts"
recipe "redisio::enable", "This recipe is used to start the redis instances and enable them in the default run levels"
recipe "redisio::disable", "This recipe is used to stop the redis instances and disable them in the default run levels"
recipe "redisio::redis_gem", "This recipe will install the redis ruby gem into the system ruby"
Expand Down
33 changes: 23 additions & 10 deletions providers/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,11 @@ def configure

descriptors = current['ulimit'] == 0 ? current['maxclients'] + 32 : current['maxclients']

#Manage Redisio Config?
if node['redisio']['sentinel']['manage_config'] == true
config_action = :create
else
config_action = :create_if_missing
end

recipe_eval do
server_name = current['name'] || current['port']
piddir = "#{base_piddir}/#{server_name}"
aof_file = "#{current['datadir']}/appendonly-#{server_name}.aof"
rdb_file = "#{current['datadir']}/dump-#{server_name}.rdb"
aof_file = "#{current['appendfilename']}" || "#{current['datadir']}/appendonly-#{server_name}.aof"
rdb_file = "#{current['dbfilename']}" || "#{current['datadir']}/dump-#{server_name}.rdb"

#Create the owner of the redis data directory
user current['user'] do
Expand All @@ -106,6 +99,7 @@ def configure
home current['homedir']
shell current['shell']
system current['systemuser']
uid current['uid'] unless current['uid'].nil?
not_if { node['etc']['passwd']["#{current['user']}"] }
end
#Create the redis configuration directory
Expand Down Expand Up @@ -191,13 +185,14 @@ def configure
owner current['user']
group current['group']
mode '0644'
action config_action
action :create
variables({
:version => version_hash,
:piddir => piddir,
:name => server_name,
:job_control => node['redisio']['job_control'],
:port => current['port'],
:tcpbacklog => current['tcpbacklog'],
:address => current['address'],
:databases => current['databases'],
:backuptype => current['backuptype'],
Expand All @@ -212,16 +207,24 @@ def configure
:syslogfacility => current['syslogfacility'],
:save => computed_save,
:stopwritesonbgsaveerror => current['stopwritesonbgsaveerror'],
:rdbcompression => current['rdbcompression'],
:rdbchecksum => current['rdbchecksum'],
:dbfilename => current['dbfilename'],
:slaveof => current['slaveof'],
:masterauth => current['masterauth'],
:slaveservestaledata => current['slaveservestaledata'],
:slavereadonly => current['slavereadonly'],
:replpingslaveperiod => current['replpingslaveperiod'],
:repltimeout => current['repltimeout'],
:repldisabletcpnodelay => current['repldisabletcpnodelay'],
:slavepriority => current['slavepriority'],
:requirepass => current['requirepass'],
:rename_commands => current['rename_commands'],
:maxclients => current['maxclients'],
:maxmemory => maxmemory,
:maxmemorypolicy => current['maxmemorypolicy'],
:maxmemorysamples => current['maxmemorysamples'],
:appendfilename => current['appendfilename'],
:appendfsync => current['appendfsync'],
:noappendfsynconrewrite => current['noappendfsynconrewrite'],
:aofrewritepercentage => current['aofrewritepercentage'] ,
Expand All @@ -232,9 +235,12 @@ def configure
:notifykeyspaceevents => current['notifykeyspaceevents'],
:hashmaxziplistentries => current['hashmaxziplistentries'],
:hashmaxziplistvalue => current['hashmaxziplistvalue'],
:listmaxziplistentries => current['listmaxziplistentries'],
:listmaxziplistvalue => current['listmaxziplistvalue'],
:setmaxintsetentries => current['setmaxintsetentries'],
:zsetmaxziplistentries => current['zsetmaxziplistentries'],
:zsetmaxziplistvalue => current['zsetmaxziplistvalue'],
:hllsparsemaxbytes => current['hllsparsemaxbytes'],
:activerehasing => current['activerehasing'],
:clientoutputbufferlimit => current['clientoutputbufferlimit'],
:hz => current['hz'],
Expand All @@ -244,7 +250,14 @@ def configure
:clusternodetimeout => current['clusternodetimeout'],
:includes => current['includes']
})
not_if do ::File.exists?("#{current['configdir']}/#{server_name}.conf.breadcrumb") end
end

file "#{current['configdir']}/#{server_name}.conf.breadcrumb" do
content "This file prevents the chef cookbook from overwritting the redis config more than once"
action :create_if_missing
end

#Setup init.d file

bin_path = node['redisio']['bin_path']
Expand Down
16 changes: 9 additions & 7 deletions providers/sentinel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ def configure
#Merge the configuration defaults with the provided array of configurations provided
current = current_defaults_hash.merge(current_instance_hash)

#Manage Sentinel Configs?
if node['redisio']['sentinel']['manage_config'] == true
config_action = :create
else
config_action = :create_if_missing
end

recipe_eval do
sentinel_name = current['name'] || current['port']
Expand All @@ -54,6 +48,8 @@ def configure
home current['homedir']
shell current['shell']
system current['systemuser']
uid current['uid'] unless current['uid'].nil?
not_if { node['etc']['passwd']["#{current['user']}"] }
end
#Create the redis configuration directory
directory current['configdir'] do
Expand Down Expand Up @@ -143,7 +139,7 @@ def configure
owner current['user']
group current['group']
mode '0644'
action config_action
action :create
variables({
:name => current['name'],
:piddir => piddir,
Expand All @@ -155,6 +151,12 @@ def configure
:syslogfacility => current['syslogfacility'],
:masters => masters_with_defaults
})
not_if do ::File.exists?("#{current['configdir']}/#{sentinel_name}.conf.breadcrumb") end
end

file "#{current['configdir']}/#{sentinel_name}.conf.breadcrumb" do
content "This file prevents the chef cookbook from overwritting the sentinel config more than once"
action :create_if_missing
end

#Setup init.d file
Expand Down
2 changes: 1 addition & 1 deletion recipes/sentinel_enable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
if node['redisio']['job_control'] != 'systemd'
resource.action << :enable
else
link "/etc/systemd/system/multi-user.target.wants/redis@#{sentinel_name}.service" do
link "/etc/systemd/system/multi-user.target.wants/redis-sentinel@#{sentinel_name}.service" do
to '/usr/lib/systemd/system/redis-sentinel@.service'
notifies :run, 'execute[reload-systemd]', :immediately
end
Expand Down
Loading

0 comments on commit f380a9b

Please sign in to comment.