forked from bloomberg/redis-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_config.rb
113 lines (106 loc) · 5.13 KB
/
redis_config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# Cookbook: redis
# License: Apache 2.0
#
# Copyright 2015-2016, Bloomberg Finance L.P.
#
require 'poise'
module RedisCookbook
module Resource
# A `redis_config` resource to manage the Redis configuration on a
# node.
# @provides redis_config
# @action create
# @action delete
# @since 2.0
class RedisConfig < Chef::Resource
include Poise(fused: true)
provides(:redis_config)
# @!attribute path
# @return [String]
attribute(:path, kind_of: String, default: '/etc/redis.conf')
# @!attribute owner
# @return [String]
attribute(:owner, kind_of: String, default: 'redis')
# @!attribute group
# @return [String]
attribute(:group, kind_of: String, default: 'redis')
# @!attribute mode
# @return [String]
attribute(:mode, kind_of: String, default: '0440')
# @!attribute instance_name
# @return [String]
attribute(:instance_name, kind_of: String, name_attribute: true)
# @!attribute log_dir
# @return [String]
attribute(:log_dir, kind_of: String, default: '/var/log/redis')
# @see: https://github.com/antirez/redis/blob/3.2/redis.conf
attribute(:port, kind_of: Integer, default: 6_379)
attribute(:bind, kind_of: String, default: '0.0.0.0')
attribute(:unixsocket, kind_of: [String, NilClass], default: nil)
attribute(:unixsocketperm, kind_of: [String, NilClass], default: nil)
attribute(:timeout, kind_of: Integer, default: 0)
attribute(:loglevel, kind_of: String, default: 'notice')
attribute(:syslog_enabled, kind_of: [String, NilClass], default: nil)
attribute(:syslog_ident, kind_of: [String, NilClass], default: nil)
attribute(:syslog_facility, kind_of: [String, NilClass], default: nil)
attribute(:logfile, kind_of: String, default: lazy { ::File.join(log_dir, "#{instance_name}.log") })
attribute(:databases, kind_of: Integer, default: 16)
attribute(:save, kind_of: [String, Array], default: ['900 1', '300 10', '60 10000'])
attribute(:stop_writes_on_bgsave_error, equal_to: %w{yes no}, default: 'yes')
attribute(:rdbcompression, equal_to: %w{yes no}, default: 'yes')
attribute(:rdbchecksum, equal_to: %w{yes no}, default: 'yes')
attribute(:dir, kind_of: String, default: lazy { "/var/lib/redis/#{instance_name}" })
attribute(:slaveof, kind_of: [String, Array, NilClass], default: nil)
attribute(:masterauth, kind_of: [String, NilClass], default: nil)
attribute(:slave_serve_stale_data, equal_to: %w{yes no}, default: 'yes')
attribute(:slave_read_only, equal_to: %w{yes no}, default: 'yes')
attribute(:repl_ping_slave_period, kind_of: [String, NilClass], default: nil)
attribute(:repl_timeout, kind_of: [String, NilClass], default: nil)
attribute(:slave_priority, kind_of: Integer, default: 100)
attribute(:requirepass, kind_of: [String, NilClass], default: nil)
attribute(:maxclients, kind_of: [String, NilClass], default: nil)
attribute(:maxmemory, kind_of: [String, NilClass], default: nil)
attribute(:maxmemory_policy, kind_of: [String, NilClass], default: nil)
attribute(:memory_samples, kind_of: [String, NilClass], default: nil)
attribute(:dbfilename, kind_of: String, default: 'dump.rdb')
attribute(:appendonly, equal_to: %w{yes no}, default: 'no')
attribute(:appendfilename, kind_of: String, default: 'appendonly.aof')
attribute(:appendfsync, kind_of: String, default: 'everysec')
attribute(:no_appendfsync_on_rewrite, equal_to: %w{yes no}, default: 'no')
attribute(:auto_aof_rewrite_percentage, kind_of: Integer, default: 100)
attribute(:auto_aof_rewrite_min_size, kind_of: String, default: '64mb')
attribute(:lua_time_limit, kind_of: Integer, default: 5_000)
attribute(:slowlog_log_slower_than, kind_of: Integer, default: 10_000)
attribute(:slowlog_max_len, kind_of: Integer, default: 128)
attribute(:hash_max_ziplist_entries, kind_of: Integer, default: 512)
attribute(:hash_max_ziplist_value, kind_of: Integer, default: 64)
attribute(:list_max_ziplist_entries, kind_of: Integer, default: 512)
attribute(:list_max_ziplist_value, kind_of: Integer, default: 64)
attribute(:set_max_intset_entries, kind_of: Integer, default: 512)
attribute(:zset_max_ziplist_entries, kind_of: Integer, default: 128)
attribute(:zet_max_ziplist_value, kind_of: Integer, default: 64)
attribute(:activerehashing, equal_to: %w{yes no}, default: 'yes')
attribute(:client_output_buffer_limit, kind_of: [String, Array], default: ['normal 0 0 0', 'slave 256mb 64mb 60', 'pubsub 32mb 8mb 60'])
action(:create) do
directory new_resource.log_dir do
owner new_resource.owner
group new_resource.group
recursive true
end
template new_resource.path do
source 'redis.conf.erb'
owner new_resource.owner
group new_resource.group
mode new_resource.mode
variables resource: new_resource
end
end
action(:delete) do
file new_resource.path do
action :delete
end
end
end
end
end