Skip to content

Commit 4297485

Browse files
authored
Merge pull request voxpupuli#877 from jlutran/oomScoreAdj
Add support for oom_score_adj
2 parents 63fee2c + 1c26b93 commit 4297485

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

manifests/config.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
$auth_backends = $rabbitmq::auth_backends
8282
$cluster_partition_handling = $rabbitmq::cluster_partition_handling
8383
$file_limit = $rabbitmq::file_limit
84+
$oom_score_adj = $rabbitmq::oom_score_adj
8485
$collect_statistics_interval = $rabbitmq::collect_statistics_interval
8586
$ipv6 = $rabbitmq::ipv6
8687
$inetrc_config = $rabbitmq::inetrc_config
@@ -235,7 +236,10 @@
235236
if $facts['systemd'] { # systemd fact provided by systemd module
236237
systemd::service_limits { "${service_name}.service":
237238
selinux_ignore_defaults => ($facts['os']['family'] == 'RedHat'),
238-
limits => { 'LimitNOFILE' => $file_limit },
239+
limits => {
240+
'LimitNOFILE' => $file_limit,
241+
'OOMScoreAdjust' => $oom_score_adj,
242+
},
239243
# The service will be notified when config changes
240244
restart_service => false,
241245
}

manifests/init.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
# to 'False' and set 'erlang_cookie'.
141141
# @param file_limit
142142
# Set rabbitmq file ulimit. Defaults to 16384. Only available on systems with `$::osfamily == 'Debian'` or `$::osfamily == 'RedHat'`.
143+
# @param oom_score_adj
144+
# Set rabbitmq-server process OOM score. Defaults to 0.
143145
# @param heartbeat
144146
# Set the heartbeat timeout interval, default is unset which uses the builtin server defaults of 60 seconds. Setting this
145147
# @param inetrc_config
@@ -394,6 +396,7 @@
394396
Boolean $wipe_db_on_cookie_change = false,
395397
String $cluster_partition_handling = 'ignore',
396398
Variant[Integer[-1],Enum['unlimited'],Pattern[/^(infinity|\d+(:(infinity|\d+))?)$/]] $file_limit = 16384,
399+
Integer[-1000, 1000] $oom_score_adj = 0,
397400
Hash $environment_variables = { 'LC_ALL' => 'en_US.UTF-8' },
398401
Hash $config_variables = {},
399402
Hash $config_kernel_variables = {},

spec/classes/rabbitmq_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,40 @@
170170
end
171171
end
172172

173+
[-1000, 0, 1000].each do |value|
174+
context "with oom_score_adj => '#{value}'" do
175+
let(:params) { { oom_score_adj: value } }
176+
177+
if facts[:os]['family'] == 'Debian'
178+
it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/^echo #{value} > \/proc\/\$\$\/oom_score_adj$/) }
179+
else
180+
it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
181+
end
182+
183+
if facts[:systemd]
184+
selinux_ignore_defaults = facts[:os]['family'] == 'RedHat'
185+
186+
it do
187+
is_expected.to contain_systemd__service_limits("#{name}.service").
188+
with_limits('OOMScoreAdjust' => value).
189+
with_restart_service(false)
190+
end
191+
else
192+
it { is_expected.not_to contain_systemd__service_limits("#{name}.service") }
193+
end
194+
end
195+
end
196+
197+
[-2000, 2000, '500', 'foo'].each do |value|
198+
context "with oom_score_adj => '#{value}'" do
199+
let(:params) { { oom_score_adj: value } }
200+
201+
it 'does not compile' do
202+
expect { catalogue }.to raise_error(Puppet::PreformattedError, %r{Error while evaluating a Resource Statement})
203+
end
204+
end
205+
end
206+
173207
context 'on systems with systemd', if: facts[:systemd] do
174208
it do
175209
is_expected.to contain_systemd__service_limits("#{name}.service").

templates/default.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
# to handle many simultaneous connections. Refer to the system
99
# documentation for ulimit (in man bash) for more information.
1010
ulimit -n <%= @file_limit %>
11+
12+
# OOM score. It sets the score of the init script, but as this value is
13+
# inherited, it also applies to the rabbitmq-server.
14+
echo <%= @oom_score_adj %> > /proc/$$/oom_score_adj

0 commit comments

Comments
 (0)