Puppet Class: memcached

Defined in:
modules/memcached/manifests/init.pp

Overview

Examples

class { '::memcached':
  size => 100,
  port => 11211,
  ip   => '127.0.0.1',
}

Parameters:

  • size (Integer) (defaults to: 2000)
  • port (Stdlib::Port) (defaults to: 11000)
  • ip (Stdlib::IP::Address) (defaults to: '0.0.0.0')
  • version (String) (defaults to: 'present')
  • min_slab_size (Integer) (defaults to: 48)
  • growth_factor (Float) (defaults to: 1.25)
  • extra_options (Hash[String, Any]) (defaults to: {})
  • enable_16 (Boolean) (defaults to: false)
  • enable_tls (Boolean) (defaults to: false)
  • enable_tls_localhost (Boolean) (defaults to: false)
  • enable_unix_socket (Boolean) (defaults to: false)
  • unix_socket_name (String) (defaults to: 'memcached.sock')
  • notls_port (Optional[Stdlib::Port]) (defaults to: undef)
  • ssl_cert (Optional[Stdlib::Unixpath]) (defaults to: undef)
  • ssl_key (Optional[Stdlib::Unixpath]) (defaults to: undef)


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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'modules/memcached/manifests/init.pp', line 87

class memcached(
    Integer                    $size                  = 2000,
    Stdlib::Port               $port                  = 11000,
    Stdlib::IP::Address        $ip                    = '0.0.0.0',
    String                     $version               = 'present',
    Integer                    $min_slab_size         = 48,
    Float                      $growth_factor         = 1.25,
    Hash[String, Any]          $extra_options         = {},
    Boolean                    $enable_16             = false,
    Boolean                    $enable_tls            = false,
    Boolean                    $enable_tls_localhost  = false,
    Boolean                    $enable_unix_socket    = false,
    String                     $unix_socket_name      = 'memcached.sock',
    Optional[Stdlib::Port]     $notls_port            = undef,
    Optional[Stdlib::Unixpath] $ssl_cert              = undef,
    Optional[Stdlib::Unixpath] $ssl_key               = undef,
) {
    if $enable_tls and (!$ssl_key or !$ssl_key) {
        fail('you must provide ssl_cert and ssl_key if you enable_tls')
    }
    if $enable_tls and $enable_unix_socket {
        fail('enabling TLS and using a unix socket are mutually exclusive')
    }
    $notls_listen = $notls_port ? {
        undef   => [],
        default => ["notls:${facts['networking']['ip']}:${notls_port}", "notls:localhost:${notls_port}"]
    }
    if $enable_unix_socket {
        systemd::tmpfile { 'memcached':
            content => 'd /run/memcached 0755 nobody nogroup - -'
        }
    } elsif ($ip == '0.0.0.0' and $enable_tls and !$enable_tls_localhost) {
        # if the ip is 0.0.0.0, indicating all ipv4 interfaces,
        # then we need to split theses addresses out to ensure we
        # have notls on localhost
        $listen = [$facts['networking']['ip'], 'notls:localhost'] + $notls_listen
    } else {
        $listen = [$ip] + $notls_listen
    }
    if $enable_16 {
        # The component for Buster also provides TLS support
        if debian::codename::eq('buster') {
            apt::package_from_component { 'memcached_16':
                component => 'component/memcached16',
                packages  => ['memcached'],
                before    => Service['memcached'],
            }
        }
    } else {
        if debian::codename::eq('bullseye') and $enable_tls {
            apt::package_from_component { 'memcached_tls':
                component => 'component/memcached-tls',
                packages  => ['memcached'],
                priority  => 1002,
                before    => Service['memcached'],
            }
        } else {
            package { 'memcached':
                ensure => $version,
                before => Service['memcached'],
            }
        }
    }

    if $enable_tls {
        $override = true
        if ! $enable_16 and debian::codename::eq('buster'){
            fail('You must set \$enable_16 when using \$enable_tls on Buster')
        }
    } else {
        $override = false
    }

    file { '/etc/memcached.conf':
        content => '# Refer to memcached.service unit for configuration.',
    }

    # Make sure memcached.service is not automatically started on package install and
    # before the override is in place.

    systemd::mask{ 'memcached.service':
        unless => "/usr/bin/dpkg -s memcached | /bin/grep -q '^Status: install ok installed$'",
    }

    systemd::unmask{ 'memcached.service': }

    # Ensure systemctl mask happens before the package is installed, and that
    # package installation triggers service unmask
    Systemd::Mask['memcached.service'] -> Package['memcached'] ~> Systemd::Unmask['memcached.service']

    systemd::service { 'memcached':
        ensure   => present,
        override => $override,
        content  => systemd_template('memcached'),
    }

    # Prefer a direct check if memcached is not running on localhost.
    if $enable_unix_socket {
        nrpe::monitor_service { 'memcached_socket':
            description  => 'memcached socket',
            nrpe_command => "/usr/lib/nagios/plugins/check_tcp -H /run/memcached/${$unix_socket_name} --timeout=2",
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Memcached',
        }
    # Prefer a direct check if memcached is not running on localhost.
    } elsif $ip == '127.0.0.1' {
        nrpe::monitor_service { 'memcached':
            description  => 'Memcached',
            nrpe_command => "/usr/lib/nagios/plugins/check_tcp -H ${ip} -p ${port}",
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Memcached',
        }
    } else {
        monitoring::service { 'memcached':
            description   => 'Memcached',
            check_command => "check_tcp!${port}",
            notes_url     => 'https://wikitech.wikimedia.org/wiki/Memcached',
        }
    }

}