forked from bloomberg/redis-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_installation_archive.rb
139 lines (120 loc) · 3.93 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
127
128
129
130
131
132
133
134
135
136
137
138
139
#
# Cookbook: redis
# License: Apache 2.0
#
# Copyright 2015-2016, Bloomberg Finance L.P.
#
require 'poise'
module RedisCookbook
module Provider
# @provides redis_installation
# @action create
# @action remove
# @since 2.0
class RedisInstallationArchive < Chef::Provider
include Poise(inversion: :redis_installation)
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',
archive_url: 'http://download.redis.io/releases/redis-%{version}.tar.gz',
archive_checksum: default_archive_checksum(resource))
end
def action_create
url = options[:archive_url] % { version: new_resource.version }
notifying_block do
include_recipe 'build-essential::default'
directory options[:prefix] do
recursive true
end
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
bash 'make-redis' do
action :nothing
cwd redis_base
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
poise_archive ::File.basename(url) do
action :nothing
path ::File.join(Chef::Config[:file_cache_path], name)
destination redis_base
notifies :run, 'bash[make-redis]', :immediately
end
remote_file ::File.basename(url) do
source url
checksum options[:archive_checksum]
path ::File.join(Chef::Config[:file_cache_path], name)
notifies :unpack, "poise_archive[#{name}]", :immediately
end
end
end
def action_remove
notifying_block do
link '/usr/local/bin/redis-server' do
to redis_program
action :delete
end
link '/usr/local/bin/redis-sentinel' do
to sentinel_program
action :delete
end
link '/usr/local/bin/redis-cli' do
to cli_program
action :delete
end
directory redis_base do
recursive true
action :delete
end
end
end
# @return [String]
# @api private
def redis_base
::File.join(options[:prefix], new_resource.version)
end
# @return [String]
# @api private
def redis_program
options.fetch(:program, ::File.join(redis_base, 'src', 'redis-server'))
end
# @return [String]
# @api private
def sentinel_program
options.fetch(:sentinel_program, ::File.join(redis_base, 'src', 'redis-sentinel'))
end
# @return [String]
# @api private
def cli_program
options.fetch(:cli_program, ::File.join(redis_base, 'src', 'redis-cli'))
end
# @param [Chef::Resource] resource
# @return [String]
def self.default_archive_checksum(resource)
case resource.version
when '3.2.0' then '989f1af3dc0ac1828fdac48cd6c608f5a32a235046dddf823226f760c0fd8762'
when '3.0.7' then 'b2a791c4ea3bb7268795c45c6321ea5abcc24457178373e6a6e3be6372737f23'
when '2.8.24' then '6c86ca5291ca7f4e37d9c90511eed67beb6649befe57e2e26307f74adb8630fe'
when '2.6.17' then '5a65b54bb6deef2a8a4fabd7bd6962654a5d35787e68f732f471bbf117f4768e'
end
end
end
end
end