This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
redis_installation_archive.rb
126 lines (109 loc) · 3.52 KB
/
redis_installation_archive.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
125
126
#
# Cookbook: redis
# License: Apache 2.0
#
# Copyright 2015-2016, Bloomberg Finance L.P.
#
require 'poise'
module RedisCookbook
module Provider
# A `redis_installation` provider implementation which installs
# from an archive.
# @provides redis_installation
# @action create
# @action remove
# @since 2.0
class RedisInstallationArchive < RedisInstallation
provides(:archive)
# Set the default inversion options.
# @param [Chef::Node] _node
# @param [Chef::Resource] resource
# @return [Hash]
# @api private
def self.default_inversion_options(_node, resource)
super.merge(prefix: '/opt/redis',
version: resource.version,
archive_url: 'http://download.redis.io/releases/redis-%{version}.tar.gz',
archive_checksum: default_archive_checksum(resource))
end
# @return [String]
# @api private
def redis_program
options.fetch(:program, ::File.join(static_folder, 'src', 'redis-server'))
end
# @return [String]
# @api private
def sentinel_program
options.fetch(:sentinel_program, ::File.join(static_folder, 'src', 'redis-sentinel'))
end
# @return [String]
# @api private
def cli_program
options.fetch(:cli_program, ::File.join(static_folder, 'src', 'redis-cli'))
end
# @return [String]
# @api private
def static_folder
::File.join(options[:prefix], new_resource.version)
end
# @param [Chef::Resource] resource
# @return [String]
# @api private
def self.default_archive_checksum(resource)
case resource.version
when '3.2.3' then '674e9c38472e96491b7d4f7b42c38b71b5acbca945856e209cb428fbc6135f15'
when '3.0.7' then 'b2a791c4ea3bb7268795c45c6321ea5abcc24457178373e6a6e3be6372737f23'
when '2.8.24' then '6c86ca5291ca7f4e37d9c90511eed67beb6649befe57e2e26307f74adb8630fe'
when '2.6.17' then '5a65b54bb6deef2a8a4fabd7bd6962654a5d35787e68f732f471bbf117f4768e'
end
end
private
# @api private
def install_redis
include_recipe 'build-essential::default'
url = options[:archive_url] % {version: options[:version]}
poise_archive url do
notifies :run, 'bash[make-redis]', :immediately
destination static_folder
not_if { ::File.exist?(redis_program) }
end
bash 'make-redis' do
action :nothing
cwd static_folder
code 'make'
notifies :create, 'link[/usr/local/bin/redis-server]'
notifies :create, 'link[/usr/local/bin/redis-sentinel]'
notifies :create, 'link[/usr/local/bin/redis-cli]'
end
# Actually build the database from the extracted archive.
link '/usr/local/bin/redis-server' do
action :nothing
to redis_program
end
link '/usr/local/bin/redis-sentinel' do
action :nothing
to sentinel_program
end
link '/usr/local/bin/redis-cli' do
action :nothing
to cli_program
end
end
# @api private
def uninstall_redis
link '/usr/local/bin/redis-server' do
action :delete
to redis_program
end
link '/usr/local/bin/redis-sentinel' do
action :delete
to sentinel_program
end
link '/usr/local/bin/redis-cli' do
action :delete
to cli_program
end
end
end
end
end