Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify services by default on drop in files #194

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ Data type: `Boolean`

Notify a service for the unit, if it exists

Default value: `false`
Default value: `true`

##### <a name="-systemd--dropin_file--daemon_reload"></a>`daemon_reload`

Expand Down Expand Up @@ -1273,7 +1273,6 @@ The following parameters are available in the `systemd::service_limits` defined
* [`selinux_ignore_defaults`](#-systemd--service_limits--selinux_ignore_defaults)
* [`limits`](#-systemd--service_limits--limits)
* [`source`](#-systemd--service_limits--source)
* [`restart_service`](#-systemd--service_limits--restart_service)

##### <a name="-systemd--service_limits--name"></a>`name`

Expand Down Expand Up @@ -1325,14 +1324,6 @@ A ``File`` resource compatible ``source``

Default value: `undef`

##### <a name="-systemd--service_limits--restart_service"></a>`restart_service`

Data type: `Boolean`

Restart the managed service after setting the limits

Default value: `true`

### <a name="systemd--timer"></a>`systemd::timer`

Create a timer and optionally a service unit to execute with the timer unit
Expand Down
2 changes: 1 addition & 1 deletion manifests/dropin_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
String $group = 'root',
String $mode = '0444',
Boolean $show_diff = true,
Boolean $notify_service = false,
Boolean $notify_service = true,
Boolean $daemon_reload = true,
) {
include systemd
Expand Down
15 changes: 1 addition & 14 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',
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,15 +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 => $facts['path'],
refreshonly => true,
}

Systemd::Dropin_file["${name}-90-limits.conf"] ~> Exec["restart ${name} because limits"]
notify_service => true,
}
}
30 changes: 16 additions & 14 deletions spec/defines/service_limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@
with_content(%r{IOReadBandwidthMax=/bw/max 10K})
}

it {
expect(subject).to create_exec("restart #{title} because limits").with(
command: "systemctl restart #{title}",
refreshonly: true
)
}
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_file("/etc/systemd/system/#{title}.d/90-limits.conf").
that_notifies('Service[test]')
end
end
end

describe 'ensured absent' do
Expand All @@ -66,14 +75,7 @@

it do
expect(subject).to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").
with_ensure('absent').
that_notifies("Exec[restart #{title} because limits]")
end

it do
expect(subject).to create_exec("restart #{title} because limits").
with_command("systemctl restart #{title}").
with_refreshonly(true)
with_ensure('absent')
end
end
end
Expand Down