Skip to content

Commit a46fb0c

Browse files
committed
Add file_limit support for RedHat platforms
1 parent f45bbcc commit a46fb0c

5 files changed

Lines changed: 186 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ This value has no default and must be set explicitly if using clustering.
224224

225225
####`file_limit`
226226

227-
Set rabbitmq file ulimit. Defaults to 16384. Only available on systems with `$::osfamily == 'Debian'`
227+
Set rabbitmq file ulimit. Defaults to 16384. Only available on systems with
228+
`$::osfamily == 'Debian'` or `$::osfamily == 'RedHat'`.
228229

229230
####`key_content`
230231

manifests/config.pp

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,48 @@
106106
}
107107
}
108108

109-
if $::osfamily == 'Debian' {
110-
file { '/etc/default/rabbitmq-server':
111-
ensure => file,
112-
content => template('rabbitmq/default.erb'),
113-
mode => '0644',
114-
owner => '0',
115-
group => '0',
116-
notify => Class['rabbitmq::service'],
109+
case $::osfamily {
110+
'Debian': {
111+
file { '/etc/default/rabbitmq-server':
112+
ensure => file,
113+
content => template('rabbitmq/default.erb'),
114+
mode => '0644',
115+
owner => '0',
116+
group => '0',
117+
notify => Class['rabbitmq::service'],
118+
}
119+
}
120+
'RedHat': {
121+
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
122+
file { '/etc/systemd/system/rabbitmq-server.service.d':
123+
ensure => directory,
124+
owner => '0',
125+
group => '0',
126+
mode => '0755',
127+
} ->
128+
file { '/etc/systemd/system/rabbitmq-server.service.d/limits.conf':
129+
content => template('rabbitmq/rabbitmq-server.service.d/limits.conf'),
130+
owner => '0',
131+
group => '0',
132+
mode => '0644',
133+
notify => Exec['rabbitmq-systemd-reload'],
134+
}
135+
exec { 'rabbitmq-systemd-reload':
136+
command => '/usr/bin/systemctl daemon-reload',
137+
notify => Class['Rabbitmq::Service'],
138+
refreshonly => true,
139+
}
140+
} else {
141+
file { '/etc/security/limits.d/rabbitmq-server.conf':
142+
content => template('rabbitmq/limits.conf'),
143+
owner => '0',
144+
group => '0',
145+
mode => '0644',
146+
notify => Class['Rabbitmq::Service'],
147+
}
148+
}
149+
}
150+
default: {
117151
}
118152
}
119153

spec/classes/rabbitmq_spec.rb

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,144 @@
248248
end
249249
end
250250

251+
context 'on RedHat 7.0 or more' do
252+
let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }}
253+
254+
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d').with(
255+
'ensure' => 'directory',
256+
'owner' => '0',
257+
'group' => '0',
258+
'mode' => '0755'
259+
) }
260+
261+
it { should contain_exec('rabbitmq-systemd-reload').with(
262+
'command' => '/usr/bin/systemctl daemon-reload',
263+
'notify' => 'Class[Rabbitmq::Service]',
264+
'refreshonly' => true
265+
) }
266+
context 'with file_limit => unlimited' do
267+
let(:params) {{ :file_limit => 'unlimited' }}
268+
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
269+
'owner' => '0',
270+
'group' => '0',
271+
'mode' => '0644',
272+
'notify' => 'Exec[rabbitmq-systemd-reload]',
273+
'content' => '[Service]
274+
LimitNOFILE=unlimited
275+
'
276+
) }
277+
end
278+
279+
context 'with file_limit => infinity' do
280+
let(:params) {{ :file_limit => 'infinity' }}
281+
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
282+
'owner' => '0',
283+
'group' => '0',
284+
'mode' => '0644',
285+
'notify' => 'Exec[rabbitmq-systemd-reload]',
286+
'content' => '[Service]
287+
LimitNOFILE=infinity
288+
'
289+
) }
290+
end
291+
292+
context 'with file_limit => -1' do
293+
let(:params) {{ :file_limit => -1 }}
294+
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
295+
'owner' => '0',
296+
'group' => '0',
297+
'mode' => '0644',
298+
'notify' => 'Exec[rabbitmq-systemd-reload]',
299+
'content' => '[Service]
300+
LimitNOFILE=-1
301+
'
302+
) }
303+
end
304+
305+
context 'with file_limit => \'1234\'' do
306+
let(:params) {{ :file_limit => '1234' }}
307+
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
308+
'owner' => '0',
309+
'group' => '0',
310+
'mode' => '0644',
311+
'notify' => 'Exec[rabbitmq-systemd-reload]',
312+
'content' => '[Service]
313+
LimitNOFILE=1234
314+
'
315+
) }
316+
end
317+
318+
context 'with file_limit => foo' do
319+
let(:params) {{ :file_limit => 'foo' }}
320+
it 'does not compile' do
321+
expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
322+
end
323+
end
324+
end
325+
326+
context 'on RedHat before 7.0' do
327+
let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '6' }}
328+
329+
context 'with file_limit => unlimited' do
330+
let(:params) {{ :file_limit => 'unlimited' }}
331+
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
332+
'owner' => '0',
333+
'group' => '0',
334+
'mode' => '0644',
335+
'notify' => 'Class[Rabbitmq::Service]',
336+
'content' => 'rabbitmq soft nofile unlimited
337+
rabbitmq hard nofile unlimited
338+
'
339+
) }
340+
end
341+
342+
context 'with file_limit => infinity' do
343+
let(:params) {{ :file_limit => 'infinity' }}
344+
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
345+
'owner' => '0',
346+
'group' => '0',
347+
'mode' => '0644',
348+
'notify' => 'Class[Rabbitmq::Service]',
349+
'content' => 'rabbitmq soft nofile infinity
350+
rabbitmq hard nofile infinity
351+
'
352+
) }
353+
end
354+
355+
context 'with file_limit => -1' do
356+
let(:params) {{ :file_limit => -1 }}
357+
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
358+
'owner' => '0',
359+
'group' => '0',
360+
'mode' => '0644',
361+
'notify' => 'Class[Rabbitmq::Service]',
362+
'content' => 'rabbitmq soft nofile -1
363+
rabbitmq hard nofile -1
364+
'
365+
) }
366+
end
367+
368+
context 'with file_limit => \'1234\'' do
369+
let(:params) {{ :file_limit => '1234' }}
370+
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
371+
'owner' => '0',
372+
'group' => '0',
373+
'mode' => '0644',
374+
'notify' => 'Class[Rabbitmq::Service]',
375+
'content' => 'rabbitmq soft nofile 1234
376+
rabbitmq hard nofile 1234
377+
'
378+
) }
379+
end
380+
381+
context 'with file_limit => foo' do
382+
let(:params) {{ :file_limit => 'foo' }}
383+
it 'does not compile' do
384+
expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
385+
end
386+
end
387+
end
388+
251389
['Debian', 'RedHat', 'SUSE', 'Archlinux'].each do |distro|
252390
context "on #{distro}" do
253391
let(:facts) {{

templates/limits.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rabbitmq soft nofile <%= @file_limit %>
2+
rabbitmq hard nofile <%= @file_limit %>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Service]
2+
LimitNOFILE=<%= @file_limit %>

0 commit comments

Comments
 (0)