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
206
207
208
209
210
211
212
|
# File 'modules/memcached/manifests/init.pp', line 94
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 = {},
String $memcached_user = undef,
Boolean $enable_tls = false,
Boolean $enable_tls_localhost = false,
Boolean $enable_unix_socket = false,
String $unix_socket_name = 'memcached.sock',
WMFlib::Ensure $extstore_ensure = absent,
Optional[Stdlib::Port] $notls_port = undef,
Optional[Stdlib::Unixpath] $ssl_cert = undef,
Optional[Stdlib::Unixpath] $ssl_key = undef,
Optional[Stdlib::Unixpath] $localcacert = undef,
Optional[Stdlib::Unixpath] $extstore_path = '/srv/memcached',
) {
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 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
} 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':
refreshonly => true,
}
# 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'),
}
file { $extstore_path:
ensure => stdlib::ensure($extstore_ensure, 'directory'),
owner => $memcached_user,
group => $memcached_user,
mode => '0700',
require => Package['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',
}
}
}
|