Skip to content

Commit

Permalink
Merge pull request #337 from fcharlier/limits_redhat
Browse files Browse the repository at this point in the history
Add file_limit support for RedHat platforms
  • Loading branch information
DavidS committed Apr 17, 2015
2 parents 1a7859c + a46fb0c commit 2c3fd7e
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ This value has no default and must be set explicitly if using clustering.

####`file_limit`

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

####`key_content`

Expand Down
50 changes: 42 additions & 8 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,48 @@
}
}

if $::osfamily == 'Debian' {
file { '/etc/default/rabbitmq-server':
ensure => file,
content => template('rabbitmq/default.erb'),
mode => '0644',
owner => '0',
group => '0',
notify => Class['rabbitmq::service'],
case $::osfamily {
'Debian': {
file { '/etc/default/rabbitmq-server':
ensure => file,
content => template('rabbitmq/default.erb'),
mode => '0644',
owner => '0',
group => '0',
notify => Class['rabbitmq::service'],
}
}
'RedHat': {
if versioncmp($::operatingsystemmajrelease, '7') >= 0 {
file { '/etc/systemd/system/rabbitmq-server.service.d':
ensure => directory,
owner => '0',
group => '0',
mode => '0755',
} ->
file { '/etc/systemd/system/rabbitmq-server.service.d/limits.conf':
content => template('rabbitmq/rabbitmq-server.service.d/limits.conf'),
owner => '0',
group => '0',
mode => '0644',
notify => Exec['rabbitmq-systemd-reload'],
}
exec { 'rabbitmq-systemd-reload':
command => '/usr/bin/systemctl daemon-reload',
notify => Class['Rabbitmq::Service'],
refreshonly => true,
}
} else {
file { '/etc/security/limits.d/rabbitmq-server.conf':
content => template('rabbitmq/limits.conf'),
owner => '0',
group => '0',
mode => '0644',
notify => Class['Rabbitmq::Service'],
}
}
}
default: {
}
}

Expand Down
138 changes: 138 additions & 0 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,144 @@
end
end

context 'on RedHat 7.0 or more' do
let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '7' }}

it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d').with(
'ensure' => 'directory',
'owner' => '0',
'group' => '0',
'mode' => '0755'
) }

it { should contain_exec('rabbitmq-systemd-reload').with(
'command' => '/usr/bin/systemctl daemon-reload',
'notify' => 'Class[Rabbitmq::Service]',
'refreshonly' => true
) }
context 'with file_limit => unlimited' do
let(:params) {{ :file_limit => 'unlimited' }}
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Exec[rabbitmq-systemd-reload]',
'content' => '[Service]
LimitNOFILE=unlimited
'
) }
end

context 'with file_limit => infinity' do
let(:params) {{ :file_limit => 'infinity' }}
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Exec[rabbitmq-systemd-reload]',
'content' => '[Service]
LimitNOFILE=infinity
'
) }
end

context 'with file_limit => -1' do
let(:params) {{ :file_limit => -1 }}
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Exec[rabbitmq-systemd-reload]',
'content' => '[Service]
LimitNOFILE=-1
'
) }
end

context 'with file_limit => \'1234\'' do
let(:params) {{ :file_limit => '1234' }}
it { should contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Exec[rabbitmq-systemd-reload]',
'content' => '[Service]
LimitNOFILE=1234
'
) }
end

context 'with file_limit => foo' do
let(:params) {{ :file_limit => 'foo' }}
it 'does not compile' do
expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
end
end
end

context 'on RedHat before 7.0' do
let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '6' }}

context 'with file_limit => unlimited' do
let(:params) {{ :file_limit => 'unlimited' }}
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Class[Rabbitmq::Service]',
'content' => 'rabbitmq soft nofile unlimited
rabbitmq hard nofile unlimited
'
) }
end

context 'with file_limit => infinity' do
let(:params) {{ :file_limit => 'infinity' }}
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Class[Rabbitmq::Service]',
'content' => 'rabbitmq soft nofile infinity
rabbitmq hard nofile infinity
'
) }
end

context 'with file_limit => -1' do
let(:params) {{ :file_limit => -1 }}
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Class[Rabbitmq::Service]',
'content' => 'rabbitmq soft nofile -1
rabbitmq hard nofile -1
'
) }
end

context 'with file_limit => \'1234\'' do
let(:params) {{ :file_limit => '1234' }}
it { should contain_file('/etc/security/limits.d/rabbitmq-server.conf').with(
'owner' => '0',
'group' => '0',
'mode' => '0644',
'notify' => 'Class[Rabbitmq::Service]',
'content' => 'rabbitmq soft nofile 1234
rabbitmq hard nofile 1234
'
) }
end

context 'with file_limit => foo' do
let(:params) {{ :file_limit => 'foo' }}
it 'does not compile' do
expect { catalogue }.to raise_error(Puppet::Error, /\$file_limit must be an integer, 'unlimited', or 'infinity'/)
end
end
end

['Debian', 'RedHat', 'SUSE', 'Archlinux'].each do |distro|
context "on #{distro}" do
let(:facts) {{
Expand Down
2 changes: 2 additions & 0 deletions templates/limits.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rabbitmq soft nofile <%= @file_limit %>
rabbitmq hard nofile <%= @file_limit %>
2 changes: 2 additions & 0 deletions templates/rabbitmq-server.service.d/limits.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
LimitNOFILE=<%= @file_limit %>

0 comments on commit 2c3fd7e

Please sign in to comment.