Add Redis replica recipe and role
This commit is contained in:
parent
c32e8bc9e5
commit
88e96747e3
15
roles/redis_replica.rb
Normal file
15
roles/redis_replica.rb
Normal file
@ -0,0 +1,15 @@
|
||||
name "redis_replica"
|
||||
|
||||
run_list %w(
|
||||
kosmos_redis::replica
|
||||
kosmos_redis::firewall
|
||||
)
|
||||
|
||||
default_attributes({
|
||||
'redisio' => {
|
||||
'default_settings' => {
|
||||
'slaveservestaledata' => 'yes',
|
||||
'slavereadonly' => 'yes'
|
||||
}
|
||||
}
|
||||
})
|
@ -7,6 +7,7 @@ default_run_list = %w(
|
||||
production_run_list = %w(
|
||||
kosmos_redis::default
|
||||
kosmos_redis::firewall
|
||||
kosmos_redis::backup
|
||||
)
|
||||
|
||||
env_run_lists(
|
||||
@ -14,5 +15,3 @@ env_run_lists(
|
||||
'development' => default_run_list,
|
||||
'production' => production_run_list
|
||||
)
|
||||
|
||||
default_attributes({})
|
||||
|
11
site-cookbooks/kosmos_redis/recipes/backup.rb
Normal file
11
site-cookbooks/kosmos_redis/recipes/backup.rb
Normal file
@ -0,0 +1,11 @@
|
||||
#
|
||||
# Cookbook Name:: kosmos_redis
|
||||
# Recipe:: backup
|
||||
#
|
||||
|
||||
databases = node['redisio']['servers'].map do |server, _|
|
||||
"dump-#{server['port']}"
|
||||
end
|
||||
node.override["backup"]["redis"]["databases"] = databases
|
||||
|
||||
include_recipe "backup"
|
@ -3,16 +3,10 @@
|
||||
# Recipe:: default
|
||||
#
|
||||
|
||||
node.normal['redisio']['servers'] = [{
|
||||
'port' => '6379',
|
||||
'protected_mode' => 'no'
|
||||
}]
|
||||
|
||||
include_recipe 'redisio::default'
|
||||
include_recipe 'redisio::enable'
|
||||
|
||||
unless node.chef_environment == "development"
|
||||
include_recipe "kosmos_redis::firewall"
|
||||
|
||||
# Backup the databases to S3
|
||||
databases = node['redisio']['servers'].map do |server, _|
|
||||
"dump-#{server['port']}"
|
||||
end
|
||||
node.override["backup"]["redis"]["databases"] = databases
|
||||
include_recipe "backup"
|
||||
end
|
||||
|
19
site-cookbooks/kosmos_redis/recipes/replica.rb
Normal file
19
site-cookbooks/kosmos_redis/recipes/replica.rb
Normal file
@ -0,0 +1,19 @@
|
||||
#
|
||||
# Cookbook Name:: kosmos_redis
|
||||
# Recipe:: replica
|
||||
#
|
||||
|
||||
primary_host = search(:node, 'role:redis_server').first['knife_zero']['host'] rescue nil
|
||||
|
||||
if primary_host.nil?
|
||||
Chef::Log.warn("No node found with 'redis_server' role. Stopping here.")
|
||||
return
|
||||
end
|
||||
|
||||
node.normal['redisio']['servers'] = [{
|
||||
'port' => '6379',
|
||||
'replicaof' => { 'address' => primary_host, 'port' => '6379' }
|
||||
}]
|
||||
|
||||
include_recipe 'redisio::default'
|
||||
include_recipe 'redisio::enable'
|
Loading…
x
Reference in New Issue
Block a user