Skip to content

Commit c0adfe5

Browse files
committed
Add support for oom_score_adj
1 parent 63fee2c commit c0adfe5

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-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+
Optional[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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,51 @@
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'] == 'RedHat'
178+
it do
179+
is_expected.to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf').
180+
with_owner('0').
181+
with_group('0').
182+
with_mode('0644').
183+
that_notifies('Class[Rabbitmq::Service]').
184+
with_content("OOMScoreAdjust=#{value}\n")
185+
end
186+
else
187+
it { is_expected.not_to contain_file('/etc/security/limits.d/rabbitmq-server.conf') }
188+
end
189+
190+
if facts[:os]['family'] == 'Debian'
191+
it { is_expected.to contain_file('/etc/default/rabbitmq-server').with_content(/^echo #{value} > \/proc\/\$\$\/oom_score_adj$/) }
192+
else
193+
it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
194+
end
195+
196+
if facts[:systemd]
197+
it do
198+
is_expected.to contain_systemd__service_limits("#{name}.service").
199+
with_limits('OOMScoreAdjust' => value).
200+
with_restart_service(false)
201+
end
202+
else
203+
it { is_expected.not_to contain_systemd__service_limits("#{name}.service") }
204+
end
205+
end
206+
end
207+
208+
[-2000, 2000, '500', 'foo'].each do |value|
209+
context "with oom_score_adj => '#{value}'" do
210+
let(:params) { { oom_score_adj: value } }
211+
212+
it 'does not compile' do
213+
expect { catalogue }.to raise_error(Puppet::PreformattedError, %r{Error while evaluating a Resource Statement})
214+
end
215+
end
216+
end
217+
173218
context 'on systems with systemd', if: facts[:systemd] do
174219
it do
175220
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)