Skip to content

Commit 2a88e3f

Browse files
committed
Remove restart_service on service_limits define
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 voxpupuli#190
1 parent 673cbc9 commit 2a88e3f

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

manifests/service_limits.pp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@
2626
#
2727
# * Mutually exclusive with ``$limits``
2828
#
29-
# @param restart_service
30-
# Restart the managed service after setting the limits
31-
#
3229
define systemd::service_limits (
3330
Enum['present', 'absent', 'file'] $ensure = 'present',
3431
Stdlib::Absolutepath $path = '/etc/systemd/system',
3532
Boolean $selinux_ignore_defaults = false,
3633
Optional[Systemd::ServiceLimits] $limits = undef,
3734
Optional[String] $source = undef,
38-
Boolean $restart_service = true
3935
) {
4036
include systemd
4137

@@ -68,14 +64,4 @@
6864
content => $_content,
6965
source => $source,
7066
}
71-
72-
if $restart_service {
73-
exec { "restart ${name} because limits":
74-
command => "systemctl restart ${name}",
75-
path => $facts['path'],
76-
refreshonly => true,
77-
}
78-
79-
Systemd::Dropin_file["${name}-90-limits.conf"] ~> Exec["restart ${name} because limits"]
80-
}
8167
}

spec/defines/service_limits_spec.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,20 @@
4949
with_content(%r{IOReadBandwidthMax=/bw/max 10K})
5050
}
5151

52-
it {
53-
expect(subject).to create_exec("restart #{title} because limits").with(
54-
command: "systemctl restart #{title}",
55-
refreshonly: true
56-
)
57-
}
52+
describe 'with service managed' do
53+
let(:pre_condition) do
54+
<<-PUPPET
55+
service { 'test':
56+
}
57+
PUPPET
58+
end
59+
60+
it { is_expected.to compile.with_all_deps }
61+
it do
62+
is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").
63+
that_notifies('Service[test]')
64+
end
65+
end
5866
end
5967

6068
describe 'ensured absent' do
@@ -64,14 +72,7 @@
6472

6573
it do
6674
expect(subject).to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").
67-
with_ensure('absent').
68-
that_notifies("Exec[restart #{title} because limits]")
69-
end
70-
71-
it do
72-
expect(subject).to create_exec("restart #{title} because limits").
73-
with_command("systemctl restart #{title}").
74-
with_refreshonly(true)
75+
with_ensure('absent')
7576
end
7677
end
7778
end

0 commit comments

Comments
 (0)