-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredis_installation_package.rb
124 lines (110 loc) · 3.17 KB
/
redis_installation_package.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
114
115
116
117
118
119
120
121
122
123
124
#
# Cookbook: blp-redis
# License: Apache 2.0
#
# Copyright 2015-2017, Bloomberg Finance L.P.
#
require 'poise'
module RedisCookbook
module Provider
# A `redis_installation` provider implementation which installs
# from the system package manager.
# @provides redis_installation
# @action create
# @action remove
# @since 2.0
class RedisInstallationPackage < RedisInstallation
provides(:package)
def self.provides_auto?(_node, _resource)
true
end
# @param [Chef::Node] node
# @param [Chef::Resource] _resource
# @api private
def self.default_inversion_options(node, _resource)
super.merge(package_name: default_package_name(node), version: default_package_version(node))
end
# @return [String]
# @api private
def redis_program
options.fetch(:program, '/usr/bin/redis-server')
end
# @return [String]
# @api private
def sentinel_program
options.fetch(:sentinel_program, '/usr/bin/redis-sentinel')
end
# @return [String]
# @api private
def cli_program
options.fetch(:cli_program, '/usr/bin/redis-cli')
end
# @param [Chef::Node] node
# @return [String]
def self.default_package_name(node)
case node['platform_family']
when 'rhel' then 'redis'
when 'debian' then 'redis-server'
when 'freebsd' then 'redis'
end
end
# @param [Chef::Node] node
# @return [String]
# @api private
def self.default_package_version(node)
case node['platform']
when 'redhat', 'centos'
case node['platform_version'].to_i
when 5 then '2.4.10-1.el5'
when 6 then '2.4.10-1.el6'
when 7 then '2.8.19-2.el7'
end
when 'ubuntu'
case node['platform_version'].to_i
when 12 then '2.2.12-1'
when 14 then '2:2.8.4-2'
when 16 then '2:3.0.6-1'
end
when 'freebsd'
case node['platform_version'].to_i
when 9 then '3.0.7'
when 10 then '3.0.7'
end
end
end
private
# @api private
def install_redis
system_package_name = options[:package_name]
system_package_version = options[:version]
init_file = file '/etc/init.d/redis-server' do
action :nothing
end
if node.platform_family?('debian')
dpkg_autostart 'redis-server' do
action :nothing
allow false
end
end
package system_package_name do
notifies :delete, init_file, :immediately
version system_package_version if system_package_version
if node.platform_family?('debian')
notifies :create, 'dpkg_autostart[redis-server]', :immediately
options '-o Dpkg::Options::=--path-exclude=/etc/redis*'
end
end
end
# @api private
def uninstall_redis
package options[:package_name] do
if node.platform_family?('debian')
action :purge
else
action :remove
end
end
end
end
end
end