Browse Source

Add Redis puppet module

Add upstream Redis puppet module which will be used
as base module for Ceilometer-Redis plugin:
https://github.com/fsalum/puppet-redis

Partially implements: blueprint ceilometer-central-agent-ha

Change-Id: Icbd879623790bf96e54b6dad7435594f107cb650
iberezovskiy 3 years ago
parent
commit
6a9a83d0d9
22 changed files with 4229 additions and 0 deletions
  1. 21
    0
      deployment_scripts/puppet/modules/redis/.travis.yml
  2. 99
    0
      deployment_scripts/puppet/modules/redis/CHANGELOG
  3. 24
    0
      deployment_scripts/puppet/modules/redis/Gemfile
  4. 201
    0
      deployment_scripts/puppet/modules/redis/LICENSE
  5. 13
    0
      deployment_scripts/puppet/modules/redis/Modulefile
  6. 108
    0
      deployment_scripts/puppet/modules/redis/README.md
  7. 11
    0
      deployment_scripts/puppet/modules/redis/Rakefile
  8. 43
    0
      deployment_scripts/puppet/modules/redis/Vagrantfile
  9. 71
    0
      deployment_scripts/puppet/modules/redis/lib/facter/redis_version.rb
  10. 211
    0
      deployment_scripts/puppet/modules/redis/manifests/init.pp
  11. 37
    0
      deployment_scripts/puppet/modules/redis/manifests/params.pp
  12. 152
    0
      deployment_scripts/puppet/modules/redis/manifests/sentinel.pp
  13. 42
    0
      deployment_scripts/puppet/modules/redis/manifests/sentinel_params.pp
  14. 51
    0
      deployment_scripts/puppet/modules/redis/metadata.json
  15. 17
    0
      deployment_scripts/puppet/modules/redis/spec/spec_helper.rb
  16. 9
    0
      deployment_scripts/puppet/modules/redis/templates/logrotate.erb
  17. 2790
    0
      deployment_scripts/puppet/modules/redis/templates/redis.conf.erb
  18. 14
    0
      deployment_scripts/puppet/modules/redis/templates/sentinel-init.conf.erb
  19. 178
    0
      deployment_scripts/puppet/modules/redis/templates/sentinel.conf.erb
  20. 2
    0
      deployment_scripts/puppet/modules/redis/tests/Puppetfile
  21. 97
    0
      deployment_scripts/puppet/modules/redis/tests/init.pp
  22. 38
    0
      deployment_scripts/puppet/modules/redis/tests/sentinel.pp

+ 21
- 0
deployment_scripts/puppet/modules/redis/.travis.yml View File

@@ -0,0 +1,21 @@
1
+---
2
+language: ruby
3
+bundler_args: --without development
4
+script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"
5
+matrix:
6
+  fast_finish: true
7
+  include:
8
+  - rvm: 1.8.7
9
+    env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
10
+  - rvm: 1.8.7
11
+    env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
12
+  - rvm: 1.8.7
13
+    env: PUPPET_GEM_VERSION="~> 3.0"
14
+  - rvm: 1.9.3
15
+    env: PUPPET_GEM_VERSION="~> 3.0"
16
+  - rvm: 2.0.0
17
+    env: PUPPET_GEM_VERSION="~> 3.0"
18
+  - rvm: 2.1.6
19
+    env: PUPPET_GEM_VERSION="~> 4.0"
20
+notifications:
21
+  email: false

+ 99
- 0
deployment_scripts/puppet/modules/redis/CHANGELOG View File

@@ -0,0 +1,99 @@
1
+## fsalum-redis changelog
2
+
3
+Release notes for the fsalum-redis module.
4
+
5
+------------------------------------------
6
+
7
+#### 1.0.3 - 2014-11-25
8
+
9
+* Version lookup not working (#41)
10
+* Remove from facter warning when redis is not installed #42 (@pmoranga)
11
+
12
+#### 1.0.2 - 2014-10-25
13
+
14
+* Fixed Travis integration and tests
15
+* Added metadata.json
16
+* Making it compatible to be 'puppet approved' :)
17
+
18
+#### 1.0.1 - 2014-09-16
19
+
20
+* Allowing redis package name as a param. #35 (@nprimmer)
21
+* add $redis_version_override #37 (@tmclaugh)
22
+
23
+#### 1.0.0 - 2014-06-08
24
+
25
+Many CHANGES to this version, complete rewrite of redis.conf template 
26
+to support Redis 2.2 to 2.8.
27
+
28
+Make sure to test the module and parameters before upgrading in production.
29
+
30
+Thanks to @zxjinn and @zeroecco for their hard work on this release.
31
+
32
+* some parameters were removed, added and/or default values changed
33
+* update redis.conf to the latest version available #32 (@zxjinn)
34
+* Logic for redis config file to support 2.2.x through 2.8.x #31 (@zeroecco)
35
+* Unixsocketoptions #33 (@nbeernink)
36
+* Changed operating system check to validate osfamily #29 (@george-b)
37
+
38
+#### 0.0.12 - 2014-03-21
39
+
40
+* Unset cleanup #27 (@trlinkin)
41
+* toggle ability to notify service to restart when config file changes #28 (@tmclaugh)
42
+
43
+#### 0.0.11 - 2014-02-19
44
+
45
+* system_sysctl parameter for redis class (@tehmaspc)
46
+
47
+#### 0.0.10 - 2014-02-19
48
+
49
+* Allow conf_bind to be unset (@stevelacey)
50
+* Changing default of glueoutputbuf to UNSET (@tehmaspc)
51
+
52
+#### 0.0.9 - 2014-01-09
53
+
54
+* Add quotes around all instances of UNSET (@charlesdunbar)
55
+
56
+#### 0.0.8 - 2013-12-20
57
+
58
+* Setting mode permission for conf_dir (@KlavsKlavsen)
59
+
60
+#### 0.0.7 - 2013-12-11
61
+
62
+* Add glueoutputbuf config option (@kryptx)
63
+* Add support for Amazon Linux AMI (@mattboston)
64
+
65
+#### 0.0.6 - 2013-08-01
66
+
67
+* Install package before poking config (@doismellburning)
68
+
69
+#### 0.0.5 - 2013-06-06
70
+
71
+* Fix Puppet 3.2.1 deprecation warnings (@ripienaar)
72
+* Fix duplicate entry for logrotate on Debian/RHEL using different paths (@arthurfurlan)
73
+* Add $conf_nosave parameter (@fsalum)
74
+* Minor changes to params variables (@fsalum)
75
+* Update CHANGELOG format
76
+
77
+------------------------------------------
78
+
79
+#### 0.0.4 - 2013-04-18
80
+
81
+* Creates conf_dir directory if it doesn't exist
82
+
83
+------------------------------------------
84
+
85
+#### 0.0.3 - 2013-02-25
86
+
87
+* Fixing redis.conf less options on Debian
88
+
89
+------------------------------------------
90
+
91
+#### 0.0.2 - 2013-02-25
92
+
93
+* Fixing redis.conf location for Debian
94
+
95
+------------------------------------------
96
+
97
+#### 0.0.1 - 2013-02-25
98
+
99
+* Initial Forge release

+ 24
- 0
deployment_scripts/puppet/modules/redis/Gemfile View File

@@ -0,0 +1,24 @@
1
+source ENV['GEM_SOURCE'] || "https://rubygems.org"
2
+
3
+group :development, :test do
4
+  gem 'rake',                   :require => false
5
+  gem 'rspec-puppet',           :require => false
6
+  gem 'puppetlabs_spec_helper', :require => false
7
+  gem 'puppet-lint',            :require => false
8
+  gem 'puppet_facts',           :require => false
9
+  gem 'metadata-json-lint',     :require => false
10
+end
11
+
12
+if facterversion = ENV['FACTER_GEM_VERSION']
13
+  gem 'facter', facterversion, :require => false
14
+else
15
+  gem 'facter', :require => false
16
+end
17
+
18
+if puppetversion = ENV['PUPPET_GEM_VERSION']
19
+  gem 'puppet', puppetversion, :require => false
20
+else
21
+  gem 'puppet', :require => false
22
+end
23
+
24
+# vim:ft=ruby

+ 201
- 0
deployment_scripts/puppet/modules/redis/LICENSE View File

@@ -0,0 +1,201 @@
1
+                                 Apache License
2
+                           Version 2.0, January 2004
3
+                        http://www.apache.org/licenses/
4
+
5
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+   1. Definitions.
8
+
9
+      "License" shall mean the terms and conditions for use, reproduction,
10
+      and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+      "Licensor" shall mean the copyright owner or entity authorized by
13
+      the copyright owner that is granting the License.
14
+
15
+      "Legal Entity" shall mean the union of the acting entity and all
16
+      other entities that control, are controlled by, or are under common
17
+      control with that entity. For the purposes of this definition,
18
+      "control" means (i) the power, direct or indirect, to cause the
19
+      direction or management of such entity, whether by contract or
20
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+      outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+      "You" (or "Your") shall mean an individual or Legal Entity
24
+      exercising permissions granted by this License.
25
+
26
+      "Source" form shall mean the preferred form for making modifications,
27
+      including but not limited to software source code, documentation
28
+      source, and configuration files.
29
+
30
+      "Object" form shall mean any form resulting from mechanical
31
+      transformation or translation of a Source form, including but
32
+      not limited to compiled object code, generated documentation,
33
+      and conversions to other media types.
34
+
35
+      "Work" shall mean the work of authorship, whether in Source or
36
+      Object form, made available under the License, as indicated by a
37
+      copyright notice that is included in or attached to the work
38
+      (an example is provided in the Appendix below).
39
+
40
+      "Derivative Works" shall mean any work, whether in Source or Object
41
+      form, that is based on (or derived from) the Work and for which the
42
+      editorial revisions, annotations, elaborations, or other modifications
43
+      represent, as a whole, an original work of authorship. For the purposes
44
+      of this License, Derivative Works shall not include works that remain
45
+      separable from, or merely link (or bind by name) to the interfaces of,
46
+      the Work and Derivative Works thereof.
47
+
48
+      "Contribution" shall mean any work of authorship, including
49
+      the original version of the Work and any modifications or additions
50
+      to that Work or Derivative Works thereof, that is intentionally
51
+      submitted to Licensor for inclusion in the Work by the copyright owner
52
+      or by an individual or Legal Entity authorized to submit on behalf of
53
+      the copyright owner. For the purposes of this definition, "submitted"
54
+      means any form of electronic, verbal, or written communication sent
55
+      to the Licensor or its representatives, including but not limited to
56
+      communication on electronic mailing lists, source code control systems,
57
+      and issue tracking systems that are managed by, or on behalf of, the
58
+      Licensor for the purpose of discussing and improving the Work, but
59
+      excluding communication that is conspicuously marked or otherwise
60
+      designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+      "Contributor" shall mean Licensor and any individual or Legal Entity
63
+      on behalf of whom a Contribution has been received by Licensor and
64
+      subsequently incorporated within the Work.
65
+
66
+   2. Grant of Copyright License. Subject to the terms and conditions of
67
+      this License, each Contributor hereby grants to You a perpetual,
68
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+      copyright license to reproduce, prepare Derivative Works of,
70
+      publicly display, publicly perform, sublicense, and distribute the
71
+      Work and such Derivative Works in Source or Object form.
72
+
73
+   3. Grant of Patent License. Subject to the terms and conditions of
74
+      this License, each Contributor hereby grants to You a perpetual,
75
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+      (except as stated in this section) patent license to make, have made,
77
+      use, offer to sell, sell, import, and otherwise transfer the Work,
78
+      where such license applies only to those patent claims licensable
79
+      by such Contributor that are necessarily infringed by their
80
+      Contribution(s) alone or by combination of their Contribution(s)
81
+      with the Work to which such Contribution(s) was submitted. If You
82
+      institute patent litigation against any entity (including a
83
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+      or a Contribution incorporated within the Work constitutes direct
85
+      or contributory patent infringement, then any patent licenses
86
+      granted to You under this License for that Work shall terminate
87
+      as of the date such litigation is filed.
88
+
89
+   4. Redistribution. You may reproduce and distribute copies of the
90
+      Work or Derivative Works thereof in any medium, with or without
91
+      modifications, and in Source or Object form, provided that You
92
+      meet the following conditions:
93
+
94
+      (a) You must give any other recipients of the Work or
95
+          Derivative Works a copy of this License; and
96
+
97
+      (b) You must cause any modified files to carry prominent notices
98
+          stating that You changed the files; and
99
+
100
+      (c) You must retain, in the Source form of any Derivative Works
101
+          that You distribute, all copyright, patent, trademark, and
102
+          attribution notices from the Source form of the Work,
103
+          excluding those notices that do not pertain to any part of
104
+          the Derivative Works; and
105
+
106
+      (d) If the Work includes a "NOTICE" text file as part of its
107
+          distribution, then any Derivative Works that You distribute must
108
+          include a readable copy of the attribution notices contained
109
+          within such NOTICE file, excluding those notices that do not
110
+          pertain to any part of the Derivative Works, in at least one
111
+          of the following places: within a NOTICE text file distributed
112
+          as part of the Derivative Works; within the Source form or
113
+          documentation, if provided along with the Derivative Works; or,
114
+          within a display generated by the Derivative Works, if and
115
+          wherever such third-party notices normally appear. The contents
116
+          of the NOTICE file are for informational purposes only and
117
+          do not modify the License. You may add Your own attribution
118
+          notices within Derivative Works that You distribute, alongside
119
+          or as an addendum to the NOTICE text from the Work, provided
120
+          that such additional attribution notices cannot be construed
121
+          as modifying the License.
122
+
123
+      You may add Your own copyright statement to Your modifications and
124
+      may provide additional or different license terms and conditions
125
+      for use, reproduction, or distribution of Your modifications, or
126
+      for any such Derivative Works as a whole, provided Your use,
127
+      reproduction, and distribution of the Work otherwise complies with
128
+      the conditions stated in this License.
129
+
130
+   5. Submission of Contributions. Unless You explicitly state otherwise,
131
+      any Contribution intentionally submitted for inclusion in the Work
132
+      by You to the Licensor shall be under the terms and conditions of
133
+      this License, without any additional terms or conditions.
134
+      Notwithstanding the above, nothing herein shall supersede or modify
135
+      the terms of any separate license agreement you may have executed
136
+      with Licensor regarding such Contributions.
137
+
138
+   6. Trademarks. This License does not grant permission to use the trade
139
+      names, trademarks, service marks, or product names of the Licensor,
140
+      except as required for reasonable and customary use in describing the
141
+      origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+   7. Disclaimer of Warranty. Unless required by applicable law or
144
+      agreed to in writing, Licensor provides the Work (and each
145
+      Contributor provides its Contributions) on an "AS IS" BASIS,
146
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+      implied, including, without limitation, any warranties or conditions
148
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+      PARTICULAR PURPOSE. You are solely responsible for determining the
150
+      appropriateness of using or redistributing the Work and assume any
151
+      risks associated with Your exercise of permissions under this License.
152
+
153
+   8. Limitation of Liability. In no event and under no legal theory,
154
+      whether in tort (including negligence), contract, or otherwise,
155
+      unless required by applicable law (such as deliberate and grossly
156
+      negligent acts) or agreed to in writing, shall any Contributor be
157
+      liable to You for damages, including any direct, indirect, special,
158
+      incidental, or consequential damages of any character arising as a
159
+      result of this License or out of the use or inability to use the
160
+      Work (including but not limited to damages for loss of goodwill,
161
+      work stoppage, computer failure or malfunction, or any and all
162
+      other commercial damages or losses), even if such Contributor
163
+      has been advised of the possibility of such damages.
164
+
165
+   9. Accepting Warranty or Additional Liability. While redistributing
166
+      the Work or Derivative Works thereof, You may choose to offer,
167
+      and charge a fee for, acceptance of support, warranty, indemnity,
168
+      or other liability obligations and/or rights consistent with this
169
+      License. However, in accepting such obligations, You may act only
170
+      on Your own behalf and on Your sole responsibility, not on behalf
171
+      of any other Contributor, and only if You agree to indemnify,
172
+      defend, and hold each Contributor harmless for any liability
173
+      incurred by, or claims asserted against, such Contributor by reason
174
+      of your accepting any such warranty or additional liability.
175
+
176
+   END OF TERMS AND CONDITIONS
177
+
178
+   APPENDIX: How to apply the Apache License to your work.
179
+
180
+      To apply the Apache License to your work, attach the following
181
+      boilerplate notice, with the fields enclosed by brackets "{}"
182
+      replaced with your own identifying information. (Don't include
183
+      the brackets!)  The text should be enclosed in the appropriate
184
+      comment syntax for the file format. We also recommend that a
185
+      file or class name and description of purpose be included on the
186
+      same "printed page" as the copyright notice for easier
187
+      identification within third-party archives.
188
+
189
+   Copyright {2014} {Felipe Salum}
190
+
191
+   Licensed under the Apache License, Version 2.0 (the "License");
192
+   you may not use this file except in compliance with the License.
193
+   You may obtain a copy of the License at
194
+
195
+       http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+   Unless required by applicable law or agreed to in writing, software
198
+   distributed under the License is distributed on an "AS IS" BASIS,
199
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+   See the License for the specific language governing permissions and
201
+   limitations under the License.

+ 13
- 0
deployment_scripts/puppet/modules/redis/Modulefile View File

@@ -0,0 +1,13 @@
1
+name    'fsalum-redis'
2
+version '1.0.3'
3
+source 'git://github.com/fsalum/puppet-redis.git'
4
+author 'Felipe Salum'
5
+license 'Apache License, Version 2.0'
6
+summary 'Puppet module for Redis Server'
7
+description 'Module to install and configure a Redis server'
8
+project_page 'https://github.com/fsalum/puppet-redis'
9
+
10
+## Add dependencies, if any:
11
+
12
+# https://forge.puppetlabs.com/thias/sysctl
13
+dependency 'thias/sysctl', '>= 0.3.0'

+ 108
- 0
deployment_scripts/puppet/modules/redis/README.md View File

@@ -0,0 +1,108 @@
1
+#Redis Module for Puppet
2
+[![puppet-redis](https://img.shields.io/puppetforge/v/fsalum/redis.svg)](https://forge.puppetlabs.com/fsalum/redis) [![Build Status](https://travis-ci.org/fsalum/puppet-redis.svg?branch=master)](https://travis-ci.org/fsalum/puppet-redis)
3
+
4
+This module installs and manages a Redis server. All redis.conf options are
5
+accepted in the parameterized class.
6
+
7
+##Important
8
+
9
+If you are upgrading this module from 0.x to 1.0+, please test it carefully 
10
+outside production as it is not fully backwards compatible.
11
+
12
+Some class parameters were added, removed or had their default values changed.
13
+
14
+The redis.conf template has been completely rewritten to support Redis 2.2+ to 2.8+.
15
+
16
+##Operating System
17
+
18
+Tested on CentOS 6.5, Ubuntu Saucy/Trusty/Precise, Debian 7.4  
19
+redis.conf options compatible with Redis 2.2, 2.4, 2.6, 2.8  
20
+
21
+##Quick Start
22
+
23
+Use the default parameters:
24
+
25
+    class { 'redis': }
26
+
27
+To change the port and listening network interface:
28
+
29
+    class { 'redis':
30
+      conf_port => '6379',
31
+      conf_bind => '0.0.0.0',
32
+    }
33
+
34
+##Parameters
35
+
36
+Check the [init.pp](https://github.com/fsalum/puppet-redis/blob/master/manifests/init.pp) file for a complete list of parameters accepted.
37
+
38
+* custom sysctl
39
+
40
+To enable and set important Linux kernel sysctl parameters as described in the [Redis Admin Guide](http://redis.io/topics/admin) - use the following configuration option:
41
+
42
+    class { 'redis':
43
+      system_sysctl => true
44
+    }
45
+
46
+By default, this sysctl parameter will not be enabled. Furthermore, you will need the sysctl module defined in the [Modulefile](https://github.com/fsalum/puppet-redis/blob/master/Modulefile) file.
47
+
48
+* service restart
49
+
50
+If you need to execute a controlled restart of redis after changes due master/slave relationships to avoid that both are restarted at the same time use the parameter below.
51
+
52
+    class { 'redis':
53
+      service_restart => false
54
+    }
55
+
56
+By default service restart is true.
57
+
58
+#Sentinel
59
+
60
+This module supports Redis Sentinel that comes with Redis 2.8+ with all the configuration parameters.
61
+
62
+It manages upstart scripts (can be deactivated with parameter manage_upstart_scripts = false).
63
+
64
+##Operating System
65
+
66
+Tested on Ubuntu 14.04 with Redis 2.8
67
+
68
+##Quick Start
69
+
70
+Example:
71
+
72
+    class { redis::sentinel:
73
+      conf_port      => '26379',
74
+      sentinel_confs => {
75
+        'mymaster' => {
76
+          'monitor'                 => '127.0.0.1 6379 2',
77
+          'down-after-milliseconds' => '60000',
78
+          'failover-timeout'        => 180000,
79
+          'notification-script'     => '/etc/redis/scripts/thescript.py',
80
+          'parallel-syncs'          => '3',
81
+        },
82
+        'resque' => {
83
+          'monitor'                 => '127.0.0.1 6379 4',
84
+          'down-after-milliseconds' => '10000',
85
+          'failover-timeout'        => 180000,
86
+          'notification-script'     => '/etc/redis/scripts/thescript.py',
87
+          'parallel-syncs'          => '5',
88
+        }
89
+      }
90
+    }
91
+
92
+##Copyright and License
93
+
94
+Copyright (C) 2014 Felipe Salum
95
+
96
+Felipe Salum can be contacted at: fsalum@gmail.com
97
+
98
+Licensed under the Apache License, Version 2.0 (the "License");
99
+you may not use this file except in compliance with the License.
100
+You may obtain a copy of the License at
101
+
102
+    http://www.apache.org/licenses/LICENSE-2.0
103
+
104
+    Unless required by applicable law or agreed to in writing, software
105
+    distributed under the License is distributed on an "AS IS" BASIS,
106
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107
+    See the License for the specific language governing permissions and
108
+    limitations under the License.

+ 11
- 0
deployment_scripts/puppet/modules/redis/Rakefile View File

@@ -0,0 +1,11 @@
1
+require 'puppetlabs_spec_helper/rake_tasks'
2
+require 'puppet-lint/tasks/puppet-lint'
3
+
4
+PuppetLint.configuration.fail_on_warnings
5
+PuppetLint.configuration.send('relative')
6
+PuppetLint.configuration.send('disable_80chars')
7
+PuppetLint.configuration.send('disable_class_inherits_from_params_class')
8
+PuppetLint.configuration.send('disable_class_parameter_defaults')
9
+PuppetLint.configuration.send('disable_documentation')
10
+PuppetLint.configuration.send('disable_single_quote_string_with_variables')
11
+PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

+ 43
- 0
deployment_scripts/puppet/modules/redis/Vagrantfile View File

@@ -0,0 +1,43 @@
1
+# -*- mode: ruby -*-
2
+# vi: set ft=ruby :
3
+#
4
+
5
+if ENV['VAGRANT_HOME'].nil?
6
+    ENV['VAGRANT_HOME'] = './'
7
+end
8
+
9
+redis = {
10
+    :'centos5'  => { :memory => '120', :ip => '10.1.1.10', :box => 'puppetlabs/centos-5.11-64-puppet',  :domain => 'redis.local' },
11
+    :'centos65' => { :memory => '120', :ip => '10.1.1.11', :box => 'puppetlabs/centos-6.5-64-puppet',   :domain => 'redis.local' },
12
+    :'precise'  => { :memory => '120', :ip => '10.1.1.20', :box => 'puppetlabs/ubuntu-12.04-64-puppet', :domain => 'redis.local' },
13
+    :'saucy'    => { :memory => '120', :ip => '10.1.1.21', :box => 'puppetlabs/ubuntu-13.10-64-puppet', :domain => 'redis.local' },
14
+    :'trusty'   => { :memory => '240', :ip => '10.1.1.22', :box => 'puppetlabs/ubuntu-14.04-64-puppet', :domain => 'redis.local' },
15
+    :'squeeze'  => { :memory => '120', :ip => '10.1.1.30', :box => 'puppetlabs/debian-6.0.9-64-puppet', :domain => 'redis.local' },
16
+    :'wheezy'   => { :memory => '120', :ip => '10.1.1.31', :box => 'puppetlabs/debian-7.6-64-puppet',   :domain => 'redis.local' },
17
+}
18
+
19
+Vagrant::Config.run("2") do |config|
20
+  config.vbguest.auto_update = true
21
+  config.hostmanager.enabled = false
22
+
23
+    redis.each_pair do |name, opts|
24
+        config.vm.define name do |n|
25
+            config.vm.provider :virtualbox do |vb|
26
+                vb.customize ["modifyvm", :id, "--memory", opts[:memory] ]
27
+            end
28
+            n.vm.network "private_network", ip: opts[:ip]
29
+            n.vm.box = opts[:box]
30
+            n.vm.host_name = "#{name}" + "." + opts[:domain]
31
+            n.vm.synced_folder "#{ENV['VAGRANT_HOME']}","/etc/puppet/modules/redis"
32
+            n.vm.provision :shell, :inline => "gem install puppet facter --no-ri --no-rdoc" if name == "trusty"
33
+            n.vm.provision :shell, :inline => "puppet module install thias-sysctl --force"
34
+            n.vm.provision :puppet do |puppet|
35
+                puppet.manifests_path = "tests"
36
+                puppet.manifest_file  = "init.pp"
37
+                #puppet.manifest_file  = "sentinel.pp"
38
+                puppet.module_path = "./"
39
+            end
40
+        end
41
+    end
42
+
43
+end

+ 71
- 0
deployment_scripts/puppet/modules/redis/lib/facter/redis_version.rb View File

@@ -0,0 +1,71 @@
1
+require 'facter'
2
+
3
+Facter.add("redis_version", :timeout => 120) do
4
+    confine :osfamily => "Debian"
5
+
6
+    setcode do
7
+
8
+        dpkg = `which apt-cache 2> /dev/null`.chomp
9
+        if dpkg == ''
10
+            dpkg = '/usr/bin/apt-cache'
11
+        end
12
+
13
+        redis_version = Facter::Util::Resolution.exec('/usr/bin/redis-server --version')
14
+        if redis_version.nil?
15
+            redis_version = Facter::Util::Resolution.exec(dpkg+" show redis-server 2> /dev/null | /bin/grep -i 'version:' | /usr/bin/awk '{printf(\"%s\",$2)}' | sort -nr | head -1")
16
+        end
17
+
18
+        case redis_version
19
+            when /2\.8\.[0-9]/
20
+                #set version to 2.8
21
+                redis_version = '2.8.x'
22
+            when /2\.6\.[0-9]/
23
+                #set version to 2.6
24
+                redis_version = '2.6.x'
25
+            when /2\.4\.[0-9]/
26
+                #set version to 2.4
27
+                redis_version = '2.4.x'
28
+            when /2\.2\.[0-9]/
29
+                #set version to 2.2
30
+                redis_version = '2.2.x'
31
+            else
32
+                redis_version = 'nil'
33
+        end
34
+        redis_version
35
+    end
36
+end
37
+
38
+Facter.add("redis_version", :timeout => 120) do
39
+    confine :osfamily => "RedHat"
40
+
41
+    setcode do
42
+
43
+        yum = `which yum 2> /dev/null`.chomp
44
+        if yum == ''
45
+            yum = '/usr/bin/yum'
46
+        end
47
+
48
+        redis_version = Facter::Util::Resolution.exec('/usr/sbin/redis-server --version')
49
+        if redis_version.nil?
50
+            redis_version = Facter::Util::Resolution.exec(yum+" info redis 2> /dev/null | /bin/grep '^Version' | /bin/awk -F ':' '{printf(\"%s\",$2)}' | sort -nr | head -1")
51
+        end
52
+
53
+        case redis_version
54
+            when /2\.8\.[0-9]/
55
+                #set version to 2.8
56
+                redis_version = '2.8.x'
57
+            when /2\.6\.[0-9]/
58
+                #set version to 2.6
59
+                redis_version = '2.6.x'
60
+            when /2\.4\.[0-9]/
61
+                #set version to 2.4
62
+                redis_version = '2.4.x'
63
+            when /2\.2\.[0-9]/
64
+                #set version to 2.2
65
+                redis_version = '2.2.x'
66
+            else
67
+                redis_version = 'nil'
68
+        end
69
+        redis_version
70
+  end
71
+end

+ 211
- 0
deployment_scripts/puppet/modules/redis/manifests/init.pp View File

@@ -0,0 +1,211 @@
1
+# == Class: redis
2
+#
3
+# Install and configure a Redis server
4
+#
5
+# === Parameters
6
+#
7
+# All the redis.conf parameters can be passed to the class.
8
+# See below for a complete list of parameters accepted.
9
+#
10
+# Check the README.md file for any further information about parameters for this class.
11
+#
12
+# === Examples
13
+#
14
+#  class { redis:
15
+#    conf_port => '6380',
16
+#    conf_bind => '0.0.0.0',
17
+#  }
18
+#
19
+# === Authors
20
+#
21
+# Felipe Salum <fsalum@gmail.com>
22
+#
23
+# === Copyright
24
+#
25
+# Copyright 2013 Felipe Salum, unless otherwise noted.
26
+#
27
+class redis (
28
+  $conf_activerehashing                   = 'yes',
29
+  $conf_aof_rewrite_incremental_fsync     = 'yes', # 2.6+
30
+  $conf_append                            = {}, # hash of custom variables+values
31
+  $conf_appendfilename                    = undef, # default appendonly.aof
32
+  $conf_appendfsync                       = 'everysec',
33
+  $conf_appendonly                        = 'no',
34
+  $conf_auto_aof_rewrite_min_size         = '64mb',
35
+  $conf_auto_aof_rewrite_percentage       = '100',
36
+  $conf_bind                              = '0.0.0.0',
37
+  $conf_client_output_buffer_limit_normal = '0 0 0', # 2.6+
38
+  $conf_client_output_buffer_limit_pubsub = '32mb 8mb 60', # 2.6+
39
+  $conf_client_output_buffer_limit_slave  = '256mb 64mb 60', # 2.6+
40
+  $conf_daemonize                         = 'yes',
41
+  $conf_databases                         = '16',
42
+  $conf_dbfilename                        = 'dump.rdb',
43
+  $conf_dir                               = '/var/lib/redis/',
44
+  $conf_glueoutputbuf                     = undef,
45
+  $conf_hash_max_zipmap_entries           = '512',
46
+  $conf_hash_max_zipmap_value             = '64',
47
+  $conf_hll_sparse_max_bytes              = undef, # default 3000, 2.8.5?+
48
+  $conf_hz                                = '10', # 2.6+
49
+  $conf_include                           = [], # array of custom include files
50
+  $conf_list_max_ziplist_entries          = '512',
51
+  $conf_list_max_ziplist_value            = '64',
52
+  $conf_logfile                           = undef, #default ""
53
+  $conf_loglevel                          = 'notice',
54
+  $conf_lua_time_limit                    = '5000', # 2.6+
55
+  $conf_masterauth                        = undef,
56
+  $conf_maxclients                        = undef, # default 10000 in 2.6+
57
+  $conf_maxmemory                         = undef,
58
+  $conf_maxmemory_policy                  = undef,
59
+  $conf_maxmemory_samples                 = undef,
60
+  $conf_min_slaves_max_lag                = undef, # default 10, 2.8+
61
+  $conf_min_slaves_to_write               = undef, # 2.8+
62
+  $conf_no_appendfsync_on_rewrite         = 'no',
63
+  $conf_nosave                            = undef,
64
+  $conf_notify_keyspace_events            = undef, # 2.8+
65
+  $conf_pidfile                           = undef,
66
+  $conf_port                              = '6379',
67
+  $conf_rdbchecksum                       = 'yes', # 2.6+
68
+  $conf_rdbcompression                    = 'yes',
69
+  $conf_repl_backlog_size                 = '1mb', # 2,8+
70
+  $conf_repl_backlog_ttl                  = '3600', # 2.8+
71
+  $conf_repl_disable_tcp_nodelay          = 'no', # 2,6+
72
+  $conf_repl_ping_slave_period            = '10', # 2.4+
73
+  $conf_repl_timeout                      = '60', # 2.4+
74
+  $conf_requirepass                       = undef,
75
+  $conf_save                              = {'900' =>'1', '300' => '10', '60' => '10000'},
76
+  $conf_set_max_intset_entries            = '512',
77
+  $conf_slave_priority                    = undef, # 2.6+
78
+  $conf_slave_read_only                   = 'yes', # 2.6+
79
+  $conf_slave_serve_stale_data            = 'yes',
80
+  $conf_slaveof                           = undef,
81
+  $conf_slowlog_log_slower_than           = '10000',
82
+  $conf_slowlog_max_len                   = '128',
83
+  $conf_stop_writes_on_bgsave_error       = 'yes', # 2.6+
84
+  $conf_syslog_enabled                    = undef,
85
+  $conf_syslog_facility                   = undef,
86
+  $conf_syslog_ident                      = undef,
87
+  $conf_tcp_backlog                       = undef, # default is 511, 2.8.5+
88
+  $conf_tcp_keepalive                     = '0', # 2.6+
89
+  $conf_timeout                           = '0',
90
+  $conf_unixsocket                        = '/tmp/redis.sock', # 2.2+
91
+  $conf_unixsocketperm                    = '755', # 2.4+
92
+  $conf_vm_enabled                        = 'no', # deprecated in 2.4+
93
+  $conf_vm_max_memory                     = '0', # deprecated in 2.4+
94
+  $conf_vm_max_threads                    = '4', # deprecated in 2.4+
95
+  $conf_vm_page_size                      = '32', # deprecated in 2.4+
96
+  $conf_vm_pages                          = '134217728', # deprecated in 2.4+
97
+  $conf_vm_swap_file                      = '/tmp/redis.swap', # deprecated in 2.4+
98
+  $conf_zset_max_ziplist_entries          = '128', # 2.4+
99
+  $conf_zset_max_ziplist_value            = '64', # 2.4+
100
+  $package_ensure                         = 'present',
101
+  $package_name                           = undef,
102
+  $redis_version_override                 = undef,
103
+  $service_enable                         = true,
104
+  $service_ensure                         = 'running',
105
+  $service_restart                        = true,
106
+  $system_sysctl                          = false,
107
+) {
108
+
109
+  include redis::params
110
+
111
+  $conf_redis     = $redis::params::conf
112
+  $conf_logrotate = $redis::params::conf_logrotate
113
+  $service        = $redis::params::service
114
+
115
+  if $redis_version_override {
116
+    $redis_version_real = $redis_version_override
117
+  } else {
118
+    $redis_version_real = $package_ensure ? {
119
+      /2\.2\..*/ => '2.2.x',
120
+      /2\.4\..*/ => '2.4.x',
121
+      /2\.6\..*/ => '2.6.x',
122
+      /2\.8\..*/ => '2.8.x',
123
+      default => $::redis_version
124
+    }
125
+  }
126
+
127
+  if $package_name {
128
+    $package     = $package_name
129
+  }else{
130
+    $package      = $redis::params::package
131
+  }
132
+
133
+  if $conf_pidfile {
134
+    $conf_pidfile_real = $conf_pidfile
135
+  }else{
136
+    $conf_pidfile_real = $::redis::params::pidfile
137
+  }
138
+
139
+  if $conf_logfile {
140
+    $conf_logfile_real = $conf_logfile
141
+  }else{
142
+    $conf_logfile_real = $::redis::params::logfile
143
+  }
144
+
145
+  package { 'redis':
146
+    ensure => $package_ensure,
147
+    name   => $package,
148
+  }
149
+
150
+  service { 'redis':
151
+    ensure     => $service_ensure,
152
+    name       => $service,
153
+    enable     => $service_enable,
154
+    hasrestart => true,
155
+    hasstatus  => true,
156
+    require    => [ Package['redis'],
157
+                    Exec[$conf_dir],
158
+                    File[$conf_redis] ],
159
+  }
160
+
161
+  file { $conf_redis:
162
+    path    => $conf_redis,
163
+    content => template('redis/redis.conf.erb'),
164
+    owner   => root,
165
+    group   => root,
166
+    mode    => '0644',
167
+    require => Package['redis'],
168
+  }
169
+
170
+  file { $conf_logrotate:
171
+    path    => $conf_logrotate,
172
+    content => template('redis/logrotate.erb'),
173
+    owner   => root,
174
+    group   => root,
175
+    mode    => '0644',
176
+  }
177
+
178
+  exec { $conf_dir:
179
+    path    => '/bin:/usr/bin:/sbin:/usr/sbin',
180
+    command => "mkdir -p ${conf_dir}",
181
+    user    => root,
182
+    group   => root,
183
+    creates => $conf_dir,
184
+    before  => Service['redis'],
185
+    require => Package['redis'],
186
+  }
187
+
188
+  file { $conf_dir:
189
+    ensure  => directory,
190
+    owner   => redis,
191
+    group   => redis,
192
+    mode    => '0755',
193
+    before  => Service['redis'],
194
+    require => Exec[$conf_dir],
195
+  }
196
+
197
+  if ( $system_sysctl == true ) {
198
+    # add necessary kernel parameters
199
+    # see the redis admin guide here: http://redis.io/topics/admin
200
+    sysctl { 'vm.overcommit_memory':
201
+      value     => '1',
202
+    }
203
+  }
204
+
205
+  if $service_restart == true {
206
+    # https://github.com/fsalum/puppet-redis/pull/28
207
+    Exec[$conf_dir] ~> Service['redis']
208
+    File[$conf_redis] ~> Service['redis']
209
+  }
210
+
211
+}

+ 37
- 0
deployment_scripts/puppet/modules/redis/manifests/params.pp View File

@@ -0,0 +1,37 @@
1
+# Class: redis::params
2
+#
3
+# This class configures parameters for the puppet-redis module.
4
+#
5
+# Parameters:
6
+#
7
+# Actions:
8
+#
9
+# Requires:
10
+#
11
+# Sample Usage:
12
+#
13
+class redis::params {
14
+
15
+  case $::osfamily {
16
+    'redhat': {
17
+      $package        = 'redis'
18
+      $service        = 'redis'
19
+      $conf           = '/etc/redis.conf'
20
+      $conf_logrotate = '/etc/logrotate.d/redis'
21
+      $pidfile        = '/var/run/redis/redis.pid'
22
+      $logfile        = '/var/log/redis/redis.log'
23
+    }
24
+    'debian': {
25
+      $package        = 'redis-server'
26
+      $service        = 'redis-server'
27
+      $conf           = '/etc/redis/redis.conf'
28
+      $conf_logrotate = '/etc/logrotate.d/redis-server'
29
+      $pidfile        = '/var/run/redis/redis-server.pid'
30
+      $logfile        = '/var/log/redis/redis-server.log'
31
+    }
32
+    default: {
33
+      fail("Unsupported osfamily: ${::osfamily}, module ${module_name} only support osfamily RedHat and Debian")
34
+    }
35
+  }
36
+
37
+}

+ 152
- 0
deployment_scripts/puppet/modules/redis/manifests/sentinel.pp View File

@@ -0,0 +1,152 @@
1
+# == Class: redis::sentinel
2
+#
3
+# Install and configure a Redis Sentinel
4
+#
5
+# === Parameters
6
+#
7
+# All the sentinel.conf parameters can be passed to the class.
8
+# See below for a complete list of parameters accepted.
9
+#
10
+# Check the README.md file for any further information about parameters for this class.
11
+#
12
+# === Examples
13
+#
14
+#  class { redis::sentinel:
15
+#    conf_port      => '26379',
16
+#    sentinel_confs => {
17
+#      'mymaster' => {
18
+#        'monitor'                 => '127.0.0.1 6379 2',
19
+#        'down-after-milliseconds' => '60000',
20
+#        'notification-script'     => '/etc/redis/scripts/thescript.py',
21
+#        'parallel-syncs'          => '3',
22
+#      }
23
+#      'resque' => {
24
+#        'monitor'                 => 'resque 6379 4',
25
+#        'down-after-milliseconds' => '10000',
26
+#        'failover-timeout'        => 180000,
27
+#        'notification-script'     => '/etc/redis/scripts/thescript.py',
28
+#        'parallel-syncs'          => '5',
29
+#      }
30
+#    }
31
+#  }
32
+#
33
+# === Authors
34
+#
35
+# Victor Garcia <bravejolie@gmail.com>
36
+#
37
+# === Copyright
38
+#
39
+# Copyright 2013 Felipe Salum, unless otherwise noted.
40
+#
41
+class redis::sentinel (
42
+  $conf_port                = '26379',
43
+  $conf_daemonize           = 'yes',
44
+  $sentinel_confs           = [],
45
+  $service_enable           = true,
46
+  $service_ensure           = 'running',
47
+  $service_restart          = true,
48
+  $manage_upstart_scripts   = true,
49
+  $package_name             = undef,
50
+) {
51
+
52
+  include redis::sentinel_params
53
+
54
+  $conf_sentinel      = $redis::sentinel_params::conf
55
+  $conf_sentinel_orig = "${conf_sentinel}.puppet"
56
+  $conf_logrotate     = $redis::sentinel_params::conf_logrotate
57
+  $service            = $redis::sentinel_params::service
58
+  $upstart_script     = $redis::sentinel_params::upstart_script
59
+
60
+  if $package_name {
61
+    $package     = $package_name
62
+  }else{
63
+    $package      = $redis::sentinel_params::package
64
+  }
65
+
66
+  if $conf_pidfile {
67
+    $conf_pidfile_real = $conf_pidfile
68
+  }else{
69
+    $conf_pidfile_real = $::redis::sentinel_params::pidfile
70
+  }
71
+  if $conf_logfile {
72
+    $conf_logfile_real = $conf_logfile
73
+  }else{
74
+    $conf_logfile_real = $::redis::sentinel_params::logfile
75
+  }
76
+
77
+  package { 'redis':
78
+    ensure => $package_ensure,
79
+    name   => $package,
80
+  }
81
+
82
+  if $manage_upstart_scripts == true {
83
+    service { 'sentinel':
84
+      ensure     => $service_ensure,
85
+      name       => $service,
86
+      hasrestart => true,
87
+      hasstatus  => true,
88
+      require    => [ File[$conf_sentinel_orig],
89
+                      File[$upstart_script] ],
90
+      provider   => 'upstart'
91
+    }
92
+  } else {
93
+    service { 'sentinel':
94
+      ensure     => $service_ensure,
95
+      name       => $service,
96
+      enable     => $service_enable,
97
+      hasrestart => true,
98
+      hasstatus  => true,
99
+      require    => [ Package['redis'],
100
+                      File[$conf_sentinel_orig] ],
101
+    }
102
+  }
103
+
104
+  # Sentinel rewrites the config file so, to avoid overriding it
105
+  # with the original content everytime puppet runs, this manages the
106
+  # "notify" event on an original file that triggers a copy to the good one
107
+  # only if it changed.
108
+  file { $conf_sentinel_orig:
109
+    content => template('redis/sentinel.conf.erb'),
110
+    owner   => redis,
111
+    group   => redis,
112
+    mode    => '0644',
113
+    require => Package['redis'],
114
+    notify  => Exec["cp ${conf_sentinel_orig} ${conf_sentinel}"],
115
+  }
116
+
117
+  file { $conf_sentinel:
118
+    owner   => redis,
119
+    group   => redis,
120
+    require => Package['redis'],
121
+  }
122
+
123
+  exec { "cp ${conf_sentinel_orig} ${conf_sentinel}":
124
+    path        => '/bin:/usr/bin:/sbin:/usr/sbin',
125
+    refreshonly => true,
126
+    user        => redis,
127
+    group       => redis,
128
+    notify      => Service['sentinel'],
129
+    require     => File[$conf_sentinel],
130
+  }
131
+
132
+  file { $conf_logrotate:
133
+    path    => $conf_logrotate,
134
+    content => template('redis/logrotate.erb'),
135
+    owner   => root,
136
+    group   => root,
137
+    mode    => '0644',
138
+  }
139
+
140
+  if $service_restart == true {
141
+    # https://github.com/fsalum/puppet-redis/pull/28
142
+    File[$conf_sentinel_orig] ~> Service['sentinel']
143
+  }
144
+
145
+  if $manage_upstart_scripts == true {
146
+    file { $upstart_script:
147
+      ensure  => present,
148
+      content => template('redis/sentinel-init.conf.erb'),
149
+    }
150
+  }
151
+
152
+}

+ 42
- 0
deployment_scripts/puppet/modules/redis/manifests/sentinel_params.pp View File

@@ -0,0 +1,42 @@
1
+# Class: redis::sentinel_params
2
+#
3
+# This class configures sentinel parameters for the puppet-redis module.
4
+#
5
+# Parameters:
6
+#
7
+# Actions:
8
+#
9
+# Requires:
10
+#
11
+# Sample Usage:
12
+#
13
+class redis::sentinel_params {
14
+
15
+  case $::osfamily {
16
+    # TODO: add redhat support
17
+    #'redhat': {
18
+    #  $package        = 'redis'
19
+    #  $service        = 'redis-sentinel'
20
+    #  $conf           = '/etc/sentinel.conf'
21
+    #  $conf_dir       = undef
22
+    #  $conf_logrotate = '/etc/logrotate.d/sentinel'
23
+    #  $pidfile        = '/var/run/redis/sentinel.pid'
24
+    #  $logfile        = '/var/log/redis/sentinel.log'
25
+    #  $upstart_script = '/etc/init/redis-sentinel.conf'
26
+    #}
27
+    'debian': {
28
+      $package        = 'redis-server'
29
+      $service        = 'redis-sentinel'
30
+      $conf_dir       = '/etc/redis'
31
+      $conf           = '/etc/redis/sentinel.conf'
32
+      $conf_logrotate = '/etc/logrotate.d/redis-sentinel'
33
+      $pidfile        = '/var/run/redis/redis-sentinel.pid'
34
+      $logfile        = '/var/log/redis/redis-sentinel.log'
35
+      $upstart_script = '/etc/init/redis-sentinel.conf'
36
+    }
37
+    default: {
38
+      fail("Unsupported osfamily: ${::osfamily}, module ${module_name} only support osfamily RedHat and Debian")
39
+    }
40
+  }
41
+
42
+}

+ 51
- 0
deployment_scripts/puppet/modules/redis/metadata.json View File

@@ -0,0 +1,51 @@
1
+{
2
+  "name": "fsalum-redis",
3
+  "version": "1.0.3",
4
+  "author": "Felipe Salum",
5
+  "summary": "Puppet module for Redis Server",
6
+  "license": "Apache-2.0",
7
+  "source": "git://github.com/fsalum/puppet-redis.git",
8
+  "project_page": "https://github.com/fsalum/puppet-redis",
9
+  "issues_url": "https://github.com/fsalum/puppet-redis/issues",
10
+  "tags": ["redis", "memcached", "cache", "nosql"],
11
+  "operatingsystem_support": [
12
+      {
13
+          "operatingsystem": "Centos",
14
+          "operatingsystemrelease": [
15
+              "5",
16
+              "6"
17
+          ]
18
+      },
19
+      {
20
+          "operatingsystem": "Ubuntu",
21
+          "operatingsystemrelease": [
22
+              "12.04",
23
+              "13.10",
24
+              "14.04"
25
+          ]
26
+      },
27
+      {
28
+          "operatingsystem":"Debian",
29
+          "operatingsystemrelease": [
30
+              "6",
31
+              "7"
32
+          ]
33
+      }
34
+  ],
35
+  "requirements": [
36
+    {
37
+        "name": "pe",
38
+        "version_requirement": "3.x"
39
+    },
40
+    {
41
+        "name": "puppet",
42
+        "version_requirement": "3.x"
43
+    }
44
+  ],
45
+  "dependencies": [
46
+    {
47
+        "name": "thias/sysctl",
48
+        "version_requirement": ">= 0.3.0"
49
+    }
50
+  ]
51
+}

+ 17
- 0
deployment_scripts/puppet/modules/redis/spec/spec_helper.rb View File

@@ -0,0 +1,17 @@
1
+dir = File.expand_path(File.dirname(__FILE__))
2
+$LOAD_PATH.unshift File.join(dir, 'lib')
3
+
4
+require 'mocha'
5
+require 'puppet'
6
+require 'rspec'
7
+require 'spec/autorun'
8
+
9
+Spec::Runner.configure do |config|
10
+    config.mock_with :mocha
11
+end
12
+
13
+# We need this because the RAL uses 'should' as a method.  This
14
+# allows us the same behaviour but with a different method name.
15
+class Object
16
+    alias :must :should
17
+end

+ 9
- 0
deployment_scripts/puppet/modules/redis/templates/logrotate.erb View File

@@ -0,0 +1,9 @@
1
+<%= @conf_logfile_real %> {
2
+    weekly
3
+    rotate 10
4
+    copytruncate
5
+    delaycompress
6
+    compress
7
+    notifempty
8
+    missingok
9
+}

+ 2790
- 0
deployment_scripts/puppet/modules/redis/templates/redis.conf.erb
File diff suppressed because it is too large
View File


+ 14
- 0
deployment_scripts/puppet/modules/redis/templates/sentinel-init.conf.erb View File

@@ -0,0 +1,14 @@
1
+# redis-sentinel - Redis Datastore Server
2
+#
3
+# Redis is a key value in memory persistent datastore
4
+
5
+start on (local-filesystems and runlevel [2345])
6
+stop on runlevel [016]
7
+respawn
8
+expect fork
9
+limit nofile 20000 65000
10
+pre-start script
11
+mkdir -p /var/run/redis-sentinel
12
+chown redis:redis /var/run/redis-sentinel
13
+end script
14
+exec start-stop-daemon --start --chuid redis:redis --pidfile <%= @conf_pidfile_real %> --umask 007 --exec /usr/bin/redis-sentinel -- <%= @conf_sentinel %>

+ 178
- 0
deployment_scripts/puppet/modules/redis/templates/sentinel.conf.erb View File

@@ -0,0 +1,178 @@
1
+# By default Redis does not run as a daemon. Use 'yes' if you need it.
2
+# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
3
+<%- if @conf_daemonize -%>
4
+daemonize <%= @conf_daemonize %>
5
+<%- end -%>
6
+
7
+# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
8
+# default. You can specify a custom pid file location here.
9
+pidfile <%= @conf_pidfile_real %>
10
+
11
+# port <sentinel-port>
12
+# The port that this sentinel instance will run on
13
+<%- if @conf_port -%>
14
+port <%= @conf_port %>
15
+<%- end -%>
16
+
17
+# Specify the log file name. Also 'stdout' can be used to force
18
+# Redis to log on the standard output. Note that if you use standard
19
+# output for logging but daemonize, logs will be sent to /dev/null
20
+logfile <%= @conf_logfile_real %>
21
+
22
+<%- if @sentinel_confs -%>
23
+ <%- @sentinel_confs.keys.sort.each do |master| -%>
24
+# Sentinel configuration for <%= master %>
25
+sentinel monitor <%= master %> <%= @sentinel_confs[master]['monitor'] %>
26
+<%- @sentinel_confs[master].keys.sort.each do |key| -%>
27
+<%- if key != 'monitor' -%>
28
+sentinel <%= key %> <%= master %> <%= @sentinel_confs[master][key] %>
29
+<%- end -%>
30
+<%- end -%>
31
+<%- end -%>
32
+<%- end -%>
33
+
34
+# sentinel monitor <master-name> <ip> <redis-port> <quorum>
35
+#
36
+# Tells Sentinel to monitor this master, and to consider it in O_DOWN
37
+# (Objectively Down) state only if at least <quorum> sentinels agree.
38
+#
39
+# Note that whatever is the ODOWN quorum, a Sentinel will require to
40
+# be elected by the majority of the known Sentinels in order to
41
+# start a failover, so no failover can be performed in minority.
42
+#
43
+# Slaves are auto-discovered, so you don't need to specify slaves in
44
+# any way. Sentinel itself will rewrite this configuration file adding
45
+# the slaves using additional configuration options.
46
+# Also note that the configuration file is rewritten when a
47
+# slave is promoted to master.
48
+#
49
+# Note: master name should not include special characters or spaces.
50
+# The valid charset is A-z 0-9 and the three characters ".-_".
51
+#sentinel monitor mymaster 127.0.0.1 6379 2
52
+
53
+# sentinel auth-pass <master-name> <password>
54
+#
55
+# Set the password to use to authenticate with the master and slaves.
56
+# Useful if there is a password set in the Redis instances to monitor.
57
+#
58
+# Note that the master password is also used for slaves, so it is not
59
+# possible to set a different password in masters and slaves instances
60
+# if you want to be able to monitor these instances with Sentinel.
61
+#
62
+# However you can have Redis instances without the authentication enabled
63
+# mixed with Redis instances requiring the authentication (as long as the
64
+# password set is the same for all the instances requiring the password) as
65
+# the AUTH command will have no effect in Redis instances with authentication
66
+# switched off.
67
+#
68
+# Example:
69
+#
70
+# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
71
+
72
+# sentinel down-after-milliseconds <master-name> <milliseconds>
73
+#
74
+# Number of milliseconds the master (or any attached slave or sentinel) should
75
+# be unreachable (as in, not acceptable reply to PING, continuously, for the
76
+# specified period) in order to consider it in S_DOWN state (Subjectively
77
+# Down).
78
+#
79
+# Default is 30 seconds.
80
+#sentinel down-after-milliseconds mymaster 30000
81
+
82
+# sentinel parallel-syncs <master-name> <numslaves>
83
+#
84
+# How many slaves we can reconfigure to point to the new slave simultaneously
85
+# during the failover. Use a low number if you use the slaves to serve query
86
+# to avoid that all the slaves will be unreachable at about the same
87
+# time while performing the synchronization with the master.
88
+#sentinel parallel-syncs mymaster 1
89
+
90
+# sentinel failover-timeout <master-name> <milliseconds>
91
+#
92
+# Specifies the failover timeout in milliseconds. It is used in many ways:
93
+#
94
+# - The time needed to re-start a failover after a previous failover was
95
+#   already tried against the same master by a given Sentinel, is two
96
+#   times the failover timeout.
97
+#
98
+# - The time needed for a slave replicating to a wrong master according
99
+#   to a Sentinel current configuration, to be forced to replicate
100
+#   with the right master, is exactly the failover timeout (counting since
101
+#   the moment a Sentinel detected the misconfiguration).
102
+#
103
+# - The time needed to cancel a failover that is already in progress but
104
+#   did not produced any configuration change (SLAVEOF NO ONE yet not
105
+#   acknowledged by the promoted slave).
106
+#
107
+# - The maximum time a failover in progress waits for all the slaves to be
108
+#   reconfigured as slaves of the new master. However even after this time
109
+#   the slaves will be reconfigured by the Sentinels anyway, but not with
110
+#   the exact parallel-syncs progression as specified.
111
+#
112
+# Default is 3 minutes.
113
+#sentinel failover-timeout mymaster 180000
114
+
115
+# SCRIPTS EXECUTION
116
+#
117
+# sentinel notification-script and sentinel reconfig-script are used in order
118
+# to configure scripts that are called to notify the system administrator
119
+# or to reconfigure clients after a failover. The scripts are executed
120
+# with the following rules for error handling:
121
+#
122
+# If script exits with "1" the execution is retried later (up to a maximum
123
+# number of times currently set to 10).
124
+#
125
+# If script exits with "2" (or an higher value) the script execution is
126
+# not retried.
127
+#
128
+# If script terminates because it receives a signal the behavior is the same
129
+# as exit code 1.
130
+#
131
+# A script has a maximum running time of 60 seconds. After this limit is
132
+# reached the script is terminated with a SIGKILL and the execution retried.
133
+
134
+# NOTIFICATION SCRIPT
135
+#
136
+# sentinel notification-script <master-name> <script-path>
137
+# 
138
+# Call the specified notification script for any sentinel event that is
139
+# generated in the WARNING level (for instance -sdown, -odown, and so forth).
140
+# This script should notify the system administrator via email, SMS, or any
141
+# other messaging system, that there is something wrong with the monitored
142
+# Redis systems.
143
+#
144
+# The script is called with just two arguments: the first is the event type
145
+# and the second the event description.
146
+#
147
+# The script must exist and be executable in order for sentinel to start if
148
+# this option is provided.
149
+#
150
+# Example:
151
+#
152
+# sentinel notification-script mymaster /var/redis/notify.sh
153
+
154
+# CLIENTS RECONFIGURATION SCRIPT
155
+#
156
+# sentinel client-reconfig-script <master-name> <script-path>
157
+#
158
+# When the master changed because of a failover a script can be called in
159
+# order to perform application-specific tasks to notify the clients that the
160
+# configuration has changed and the master is at a different address.
161
+# 
162
+# The following arguments are passed to the script:
163
+#
164
+# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
165
+#
166
+# <state> is currently always "failover"
167
+# <role> is either "leader" or "observer"
168
+# 
169
+# The arguments from-ip, from-port, to-ip, to-port are used to communicate
170
+# the old address of the master and the new address of the elected slave
171
+# (now a master).
172
+#
173
+# This script should be resistant to multiple invocations.
174
+#
175
+# Example:
176
+#
177
+# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
178
+

+ 2
- 0
deployment_scripts/puppet/modules/redis/tests/Puppetfile View File

@@ -0,0 +1,2 @@
1
+mod "redis",
2
+      :git => "git://github.com/fsalum/puppet-redis.git"

+ 97
- 0
deployment_scripts/puppet/modules/redis/tests/init.pp View File

@@ -0,0 +1,97 @@
1
+node default {
2
+
3
+  case $::osfamily {
4
+    'RedHat': {
5
+      package { 'epel-release':
6
+        ensure   => present,
7
+        source   => 'http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm',
8
+        provider => rpm,
9
+        before   => Class['redis'],
10
+      }
11
+    }
12
+    'Debian': {
13
+      # redis is on repository
14
+    }
15
+    default: {
16
+      fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat and Debian")
17
+    }
18
+  }
19
+
20
+  class { 'redis':
21
+    conf_activerehashing                   => 'yes',
22
+    conf_aof_rewrite_incremental_fsync     => 'yes', # 2.6+
23
+    conf_appendfilename                    => 'appendonly.aof',
24
+    conf_appendfsync                       => 'everysec',
25
+    conf_appendonly                        => 'no',
26
+    conf_auto_aof_rewrite_min_size         => '64mb',
27
+    conf_auto_aof_rewrite_percentage       => '100',
28
+    conf_bind                              => '0.0.0.0',
29
+    conf_client_output_buffer_limit_normal => '0 0 0', # 2.6+
30
+    conf_client_output_buffer_limit_pubsub => '32mb 8mb 60', # 2.6+
31
+    conf_client_output_buffer_limit_slave  => '256mb 64mb 60', # 2.6+
32
+    conf_daemonize                         => 'yes',
33
+    conf_databases                         => '16',
34
+    conf_dbfilename                        => 'dump.rdb',
35
+    conf_dir                               => '/var/lib/redis/',
36
+    conf_glueoutputbuf                     => undef,
37
+    conf_hash_max_zipmap_entries           => '512',
38
+    conf_hash_max_zipmap_value             => '64',
39
+    conf_hll_sparse_max_bytes              => undef, # default 3000 in 2.8+
40
+    conf_hz                                => '10', # 2.6+
41
+    conf_include                           => undef,
42
+    conf_list_max_ziplist_entries          => '512',
43
+    conf_list_max_ziplist_value            => '64',
44
+    conf_logfile                           => '',
45
+    conf_loglevel                          => 'notice',
46
+    conf_lua_time_limit                    => '5000', # 2.6+
47
+    conf_masterauth                        => undef,
48
+    conf_maxclients                        => '128', # default 10000 in 2.6+
49
+    conf_maxmemory                         => undef,
50
+    conf_maxmemory_policy                  => undef,
51
+    conf_maxmemory_samples                 => undef,
52
+    conf_min_slaves_max_lag                => '10', # default 10, 2.8+
53
+    conf_min_slaves_to_write               => undef, # 2.8+
54
+    conf_no_appendfsync_on_rewrite         => 'no',
55
+    conf_nosave                            => undef,
56
+    conf_notify_keyspace_events            => undef, # 2.8+
57
+    conf_pidfile                           => undef,
58
+    conf_port                              => '6379',
59
+    conf_rdbchecksum                       => 'yes', # 2.6+
60
+    conf_rdbcompression                    => 'yes',
61
+    conf_repl_backlog_size                 => '1mb', # 2,8+
62
+    conf_repl_backlog_ttl                  => '3600', # 2.8+
63
+    conf_repl_disable_tcp_nodelay          => 'no', # 2,6+
64
+    conf_repl_ping_slave_period            => '10', # 2.4+
65
+    conf_repl_timeout                      => '60', # 2.4+
66
+    conf_requirepass                       => undef,
67
+    conf_save                              => {"900" =>"1", "300" => "10", "60" => "10000"},
68
+    conf_set_max_intset_entries            => '512',
69
+    conf_slave_priority                    => undef, # 2.6+
70
+    conf_slave_read_only                   => 'yes', # 2.6+
71
+    conf_slave_serve_stale_data            => 'yes',
72
+    conf_slaveof                           => undef,
73
+    conf_slowlog_log_slower_than           => '10000',
74
+    conf_slowlog_max_len                   => '128',
75
+    conf_stop_writes_on_bgsave_error       => 'yes', # 2.6+
76
+    conf_syslog_enabled                    => undef,
77
+    conf_syslog_facility                   => undef,
78
+    conf_syslog_ident                      => undef,
79
+    conf_tcp_backlog                       => undef, # 2.8.5+
80
+    conf_tcp_keepalive                     => '0', # 2.6+
81
+    conf_timeout                           => '0',
82
+    conf_vm_enabled                        => 'no', # deprecated in 2.4+
83
+    conf_vm_max_memory                     => '0', # deprecated in 2.4+
84
+    conf_vm_max_threads                    => '4', # deprecated in 2.4+
85
+    conf_vm_page_size                      => '32', # deprecated in 2.4+
86
+    conf_vm_pages                          => '134217728', # deprecated in 2.4+
87
+    conf_vm_swap_file                      => '/tmp/redis.swap', # deprecated in 2.4+
88
+    conf_zset_max_ziplist_entries          => '128', # 2.4+
89
+    conf_zset_max_ziplist_value            => '64', # 2.4+
90
+    package_ensure                         => 'present',
91
+    service_enable                         => true,
92
+    service_ensure                         => 'running',
93
+    service_restart                        => true,
94
+    system_sysctl                          => true,
95
+  }
96
+
97
+}

+ 38
- 0
deployment_scripts/puppet/modules/redis/tests/sentinel.pp View File

@@ -0,0 +1,38 @@
1
+node default {
2
+
3
+  case $::osfamily {
4
+    #'RedHat': {
5
+    #  package { 'epel-release':
6
+    #    ensure   => present,
7
+    #    source   => 'http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm',
8
+    #    provider => rpm,
9
+    #    before   => Class['redis'],
10
+    #  }
11
+    #}
12
+    'Debian': {
13
+      # redis is on repository
14
+    }
15
+    default: {
16
+      fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat and Debian")
17
+    }
18
+  }
19
+
20
+  class { 'redis::sentinel':
21
+    conf_port      => '26379',
22
+    sentinel_confs => {
23
+      'mymaster' => {
24
+        'monitor'                 => '127.0.0.1 6379 2',
25
+        'down-after-milliseconds' => '60000',
26
+        'failover-timeout'        => 180000,
27
+        'parallel-syncs'          => '3',
28
+      },
29
+      'resque' => {
30
+        'monitor'                 => '127.0.0.1 6379 4',
31
+        'down-after-milliseconds' => '10000',
32
+        'failover-timeout'        => 180000,
33
+        'parallel-syncs'          => '5',
34
+      }
35
+    }
36
+  }
37
+
38
+}

Loading…
Cancel
Save