Puppet Class: redis

Defined in:
manifests/init.pp

Overview

Class: redis

Install and configure redis.

Parameters

version

Version to install. Default: 2.4.13

redis_src_dir

Location to unpack source code before building and installing it. Default: /opt/redis-src

redis_bin_dir

Location to install redis binaries. Default: /opt/redis

redis_max_memory

Set the redis config value maxmemory (bytes). Default: 4gb

redis_max_clients

Set the redis config value maxclients. If no value provided, it is not included in the configuration for 2.6 and set to 0 (unlimited) for 2.4. Default: 0 (2.4) Default: nil (2.6)

redis_timeout

Set the redis config value timeout (seconds). Default: 300

redis_loglevel

Set the redis config value loglevel. Valid values are debug, verbose, notice, and warning. Default: notice

redis_databases

Set the redis config value databases. Default: 16

redis_slowlog_log_slower_than

Set the redis config value slowlog-log-slower-than (microseconds). Default: 10000

redis_showlog_max_len

Set the redis config value slowlog-max-len. Default: 1024

redis_password

Password used by AUTH command. Will be setted is its not nil. Default: nil

Examples

include redis

class { ‘redis’:

version          => '2.6.4',
redis_max_memory => '64gb',

}

Authors

Thomas Van Doren

Copyright 2012 Thomas Van Doren, unless otherwise noted.

Parameters:

  • version (Any) (defaults to: '2.4.13')
  • redis_src_dir (Any) (defaults to: '/opt/redis-src')
  • redis_bin_dir (Any) (defaults to: '/opt/redis')
  • redis_max_memory (Any) (defaults to: '4gb')
  • redis_max_clients (Any) (defaults to: false)
  • redis_timeout (Any) (defaults to: 300)
  • redis_loglevel (Any) (defaults to: 'notice')
  • redis_databases (Any) (defaults to: 16)
  • redis_slowlog_log_slower_than (Any) (defaults to: 10000)
  • redis_slowlog_max_len (Any) (defaults to: 1024)
  • redis_password (Any) (defaults to: false)


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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'manifests/init.pp', line 72

class redis (
  $version = '2.4.13',
  $redis_src_dir = '/opt/redis-src',
  $redis_bin_dir = '/opt/redis',
  $redis_max_memory = '4gb',
  $redis_max_clients = false,
  $redis_timeout = 300,         # 0 = disabled
  $redis_loglevel = 'notice',
  $redis_databases = 16,
  $redis_slowlog_log_slower_than = 10000, # microseconds
  $redis_slowlog_max_len = 1024,
  $redis_password = false,
  ) {
  case $version {
    /^2\.4\.\d+$/: {
      if ($redis_max_clients == false) {
        $real_redis_max_clients = 0
      }
      else {
        $real_redis_max_clients = $redis_max_clients
      }
    }
    /^2\.6\.\d+$/: {
      $real_redis_max_clients = $redis_max_clients
    }
    default: {
      fail("Invalid redis version, ${version}. It must match 2.4.\d+ or 2.6.\d+.")
    }
  }
  $redis_pkg_name = "redis-${version}.tar.gz"
  $redis_pkg = "${redis_src_dir}/${redis_pkg_name}"

  package { ['build-essential', 'wget']:
    ensure => present,
  }

  File {
    owner => root,
    group => root,
  }
  file { $redis_src_dir:
    ensure => directory,
  }
  file { '/etc/redis':
    ensure => directory,
  }
  file { 'redis-lib':
    ensure => directory,
    path   => '/var/lib/redis',
  }
  file { 'redis-lib-port':
    ensure => directory,
    path   => '/var/lib/redis/6379',
  }

  # If the version is 2.4.13, use the tarball that ships with the
  # module.
  if ($version == '2.4.13') {
    file { 'redis-pkg':
      ensure => present,
      path   => $redis_pkg,
      mode   => '0644',
      source => 'puppet:///modules/redis/redis-2.4.13.tar.gz',
    }
  }
  exec { 'get-redis-pkg':
    command => "/usr/bin/wget --output-document ${redis_pkg} http://redis.googlecode.com/files/${redis_pkg_name}",
    unless  => "/usr/bin/test -f ${redis_pkg}",
    require => File[$redis_src_dir],
  }
  file { 'redis-init':
    ensure  => present,
    path    => '/etc/init.d/redis_6379',
    mode    => '0755',
    content => template('redis/redis.init.erb')
  }
  file { '6379.conf':
    ensure  => present,
    path    => '/etc/redis/6379.conf',
    mode    => '0644',
    content => template('redis/6379.conf.erb'),
  }
  file { 'redis.conf':
    ensure => present,
    path   => '/etc/redis/redis.conf',
    mode   => '0644',
    source => 'puppet:///modules/redis/redis.conf',
  }
  file { 'redis-cli-link':
    ensure => link,
    path   => '/usr/local/bin/redis-cli',
    target => "${redis_bin_dir}/bin/redis-cli",
  }

  exec { 'unpack-redis':
    command => "tar --strip-components 1 -xzf ${redis_pkg}",
    cwd     => $redis_src_dir,
    path    => '/bin:/usr/bin',
    unless  => "test -f ${redis_src_dir}/Makefile",
    require => Exec['get-redis-pkg'],
  }
  exec { 'install-redis':
    command => "make && make install PREFIX=${redis_bin_dir}",
    cwd     => $redis_src_dir,
    path    => '/bin:/usr/bin',
    unless  => "test $(${redis_bin_dir}/bin/redis-server --version | cut -d ' ' -f 1) = 'Redis'",
    require => [ Exec['unpack-redis'], Package['build-essential'] ],
  }

  service { 'redis':
    ensure    => running,
    name      => 'redis_6379',
    enable    => true,
    require   => [ File['6379.conf'], File['redis.conf'], File['redis-init'], File['redis-lib-port'], Exec['install-redis'] ],
    subscribe => File['6379.conf'],
  }
}