Skip to content

Commit

Permalink
Merge pull request #877 from jlutran/oomScoreAdj
Browse files Browse the repository at this point in the history
Add support for oom_score_adj
  • Loading branch information
bastelfreak committed Apr 15, 2021
2 parents 63fee2c + 1c26b93 commit 4297485
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
$auth_backends = $rabbitmq::auth_backends
$cluster_partition_handling = $rabbitmq::cluster_partition_handling
$file_limit = $rabbitmq::file_limit
$oom_score_adj = $rabbitmq::oom_score_adj
$collect_statistics_interval = $rabbitmq::collect_statistics_interval
$ipv6 = $rabbitmq::ipv6
$inetrc_config = $rabbitmq::inetrc_config
Expand Down Expand Up @@ -235,7 +236,10 @@
if $facts['systemd'] { # systemd fact provided by systemd module
systemd::service_limits { "${service_name}.service":
selinux_ignore_defaults => ($facts['os']['family'] == 'RedHat'),
limits => { 'LimitNOFILE' => $file_limit },
limits => {
'LimitNOFILE' => $file_limit,
'OOMScoreAdjust' => $oom_score_adj,
},
# The service will be notified when config changes
restart_service => false,
}
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
# to 'False' and set 'erlang_cookie'.
# @param file_limit
# Set rabbitmq file ulimit. Defaults to 16384. Only available on systems with `$::osfamily == 'Debian'` or `$::osfamily == 'RedHat'`.
# @param oom_score_adj
# Set rabbitmq-server process OOM score. Defaults to 0.
# @param heartbeat
# Set the heartbeat timeout interval, default is unset which uses the builtin server defaults of 60 seconds. Setting this
# @param inetrc_config
Expand Down Expand Up @@ -394,6 +396,7 @@
Boolean $wipe_db_on_cookie_change = false,
String $cluster_partition_handling = 'ignore',
Variant[Integer[-1],Enum['unlimited'],Pattern[/^(infinity|\d+(:(infinity|\d+))?)$/]] $file_limit = 16384,
Integer[-1000, 1000] $oom_score_adj = 0,
Hash $environment_variables = { 'LC_ALL' => 'en_US.UTF-8' },
Hash $config_variables = {},
Hash $config_kernel_variables = {},
Expand Down
34 changes: 34 additions & 0 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,40 @@
end
end

[-1000, 0, 1000].each do |value|
context "with oom_score_adj => '#{value}'" do
let(:params) { { oom_score_adj: value } }

if facts[:os]['family'] == 'Debian'
it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/^echo #{value} > \/proc\/\$\$\/oom_score_adj$/) }
else
it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
end

if facts[:systemd]
selinux_ignore_defaults = facts[:os]['family'] == 'RedHat'

it do
is_expected.to contain_systemd__service_limits("#{name}.service").
with_limits('OOMScoreAdjust' => value).
with_restart_service(false)
end
else
it { is_expected.not_to contain_systemd__service_limits("#{name}.service") }
end
end
end

[-2000, 2000, '500', 'foo'].each do |value|
context "with oom_score_adj => '#{value}'" do
let(:params) { { oom_score_adj: value } }

it 'does not compile' do
expect { catalogue }.to raise_error(Puppet::PreformattedError, %r{Error while evaluating a Resource Statement})
end
end
end

context 'on systems with systemd', if: facts[:systemd] do
it do
is_expected.to contain_systemd__service_limits("#{name}.service").
Expand Down
4 changes: 4 additions & 0 deletions templates/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
# to handle many simultaneous connections. Refer to the system
# documentation for ulimit (in man bash) for more information.
ulimit -n <%= @file_limit %>

# OOM score. It sets the score of the init script, but as this value is
# inherited, it also applies to the rabbitmq-server.
echo <%= @oom_score_adj %> > /proc/$$/oom_score_adj

0 comments on commit 4297485

Please sign in to comment.