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)


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
# File 'modules/memcached/manifests/init.pp', line 76

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 ! $enable_16 {
        fail('you can only enable tls with memcached1.6')
    }
    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 {
        apt::package_from_component { 'memcached_16':
            component => 'component/memcached16',
            packages  => ['memcached'],
            before    => Service['memcached'],
        }
        $override = true
    } else {
        package { 'memcached':
            ensure => $version,
            before => Service['memcached'],
        }
        $override = false
    }

    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',
        }
    }

}