Skip to content

Commit

Permalink
Remove restart_service on service_limits define
Browse files Browse the repository at this point in the history
Since 97dd16f this parameter is a bad
idea. It doesn't do a daemon reload and it may restart at the wrong
time. In fact, I'd argue it's always been a bad idea.

The recommended alternative to this is to manage the service explicitly
and let Puppet handle it. There is an automatic notify that takes care
of it.

Fixes #190
  • Loading branch information
ekohl committed Apr 27, 2021
1 parent 81f3eb5 commit 31790ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
14 changes: 1 addition & 13 deletions manifests/service_limits.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@
#
# * Mutually exclusive with ``$limits``
#
# @param restart_service
# Restart the managed service after setting the limits
#
define systemd::service_limits (
Enum['present', 'absent', 'file'] $ensure = 'present',
Stdlib::Absolutepath $path = '/etc/systemd/system',
Optional[Boolean] $selinux_ignore_defaults = false,
Optional[Systemd::ServiceLimits] $limits = undef,
Optional[String] $source = undef,
Boolean $restart_service = true
) {
include systemd

Expand Down Expand Up @@ -67,14 +63,6 @@
selinux_ignore_defaults => $selinux_ignore_defaults,
content => $_content,
source => $source,
}

if $restart_service {
exec { "restart ${name} because limits":
command => "systemctl restart ${name}",
path => $::path,
refreshonly => true,
subscribe => File["${path}/${name}.d/90-limits.conf"],
}
notify_service => true,
}
}
23 changes: 13 additions & 10 deletions spec/defines/service_limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@
.with_content(%r{IODeviceWeight=/dev/weight2 20})
.with_content(%r{IOReadBandwidthMax=/bw/max 10K})
}
it {
is_expected.to create_exec("restart #{title} because limits").with(
command: "systemctl restart #{title}",
refreshonly: true,
)
}
end

describe 'ensured absent' do
Expand All @@ -60,12 +54,21 @@
it do
is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf")
.with_ensure('absent')
.that_notifies("Exec[restart #{title} because limits]")
end
end

describe 'with service managed' do
let(:pre_condition) do
<<-PUPPET
service { 'test':
}
PUPPET
end

it { is_expected.to compile.with_all_deps }
it do
is_expected.to create_exec("restart #{title} because limits")
.with_command("systemctl restart #{title}")
.with_refreshonly(true)
is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf")
.that_notifies('Service[test]')
end
end
end
Expand Down

0 comments on commit 31790ab

Please sign in to comment.