Skip to content

Commit 97dd16f

Browse files
authored
Drop Puppet 4 and 5 support + daemon-reload code (voxpupuli#171)
* Drop Puppet 4 and 5 support This picks version 6.1.0 as a new lower bound since that contains code to automatically run daemon-reload if needed. Versions 4 and 5 are EOL. * Drop daemon-reload code Since Puppet 6.1.0 it's no longer needed to run daemon-reload manually when restarting a service. That means it's possible to drop this code. * Implement a workaround for PUP-9473. Prior to this commit, the follow code did not suffer from PUP-9473: systemd::unit_file { 'myservice.service': ensure => absent, active => true, } That's because the module considers that an invalid state and fails to compile. The follow code did trigger the bug: systemd::unit_file { 'myservice.service': ensure => absent, } service { 'myservice': ensure => running, require => Systemd::Unit_file['myservice.service'], } That's precisely what happens when a module switches from a module-provided unit file to a package-provided unit file.
1 parent 8f68b0d commit 97dd16f

13 files changed

+23
-111
lines changed

README.md

+14-27
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ There are two ways to use this module.
1818

1919
### unit files
2020

21-
Let this module handle file creation and systemd reloading.
21+
Let this module handle file creation.
2222

2323
```puppet
2424
systemd::unit_file { 'foo.service':
@@ -29,23 +29,18 @@ systemd::unit_file { 'foo.service':
2929
}
3030
```
3131

32-
Or handle file creation yourself and trigger systemd.
32+
This is equivalent to:
3333

3434
```puppet
35-
include systemd::systemctl::daemon_reload
36-
3735
file { '/usr/lib/systemd/system/foo.service':
3836
ensure => file,
3937
owner => 'root',
4038
group => 'root',
4139
mode => '0644',
4240
source => "puppet:///modules/${module_name}/foo.service",
4341
}
44-
~> Class['systemd::systemctl::daemon_reload']
45-
46-
service {'foo':
47-
ensure => 'running',
48-
subscribe => File['/usr/lib/systemd/system/foo.service'],
42+
~> service {'foo':
43+
ensure => 'running',
4944
}
5045
```
5146

@@ -63,7 +58,7 @@ systemd::unit_file { 'foo.service':
6358

6459
Drop-in files are used to add or alter settings of a unit without modifying the
6560
unit itself. As for the unit files, the module can handle the file and
66-
directory creation and systemd reloading:
61+
directory creation:
6762

6863
```puppet
6964
systemd::dropin_file { 'foo.conf':
@@ -75,11 +70,9 @@ systemd::dropin_file { 'foo.conf':
7570
}
7671
```
7772

78-
Or handle file and directory creation yourself and trigger systemd:
73+
This is equivalent to:
7974

8075
```puppet
81-
include systemd::systemctl::daemon_reload
82-
8376
file { '/etc/systemd/system/foo.service.d':
8477
ensure => directory,
8578
owner => 'root',
@@ -93,29 +86,18 @@ file { '/etc/systemd/system/foo.service.d/foo.conf':
9386
mode => '0644',
9487
source => "puppet:///modules/${module_name}/foo.conf",
9588
}
96-
~> Class['systemd::systemctl::daemon_reload']
97-
98-
service {'foo':
99-
ensure => 'running',
100-
subscribe => File['/etc/systemd/system/foo.service.d/foo.conf'],
89+
~> service {'foo':
90+
ensure => 'running',
10191
}
10292
```
10393

104-
Sometimes it's desirable to reload the systemctl daemon before a service is refreshed (for example:
105-
when overriding `ExecStart` or adding environment variables to the drop-in file). In that case,
106-
use `daemon_reload => 'eager'` instead of the default `'lazy'`. Be aware that the daemon could be
107-
reloaded multiple times if you have multiple `systemd::dropin_file` resources and any one of them
108-
is using `'eager'`.
109-
11094
dropin-files can also be generated via hiera:
11195

11296
```yaml
113-
11497
systemd::dropin_files:
11598
my-foo.conf:
11699
unit: foo.service
117100
source: puppet:///modules/${module_name}/foo.conf
118-
119101
```
120102
121103
### tmpfiles
@@ -148,7 +130,6 @@ Create a systemd timer unit and a systemd service unit to execute from
148130
that timer
149131

150132
The following will create a timer unit and a service unit file.
151-
The execution of `systemctl daemon-reload` will occur.
152133
When `active` and `enable` are set to `true` the puppet service `runoften.timer` will be
153134
declared, started and enabled.
154135

@@ -240,6 +221,12 @@ systemd::service_limits { 'foo.service':
240221
}
241222
```
242223

224+
### Daemon reloads
225+
226+
Systemd caches unit files and their relations. This means it needs to reload, typically done via `systemctl daemon-reload`. Since Puppet 6.1.0 ([PUP-3483](https://tickets.puppetlabs.com/browse/PUP-3483)) takes care of this by calling `systemctl show $SERVICE -- --property=NeedDaemonReload` to determine if a reload is needed. Typically this works well and removes the need for `systemd::systemctl::daemon_reload` as provided prior to camptocamp/systemd 3.0.0. This avoids common circular dependencies.
227+
228+
It does contain a workaround for [PUP-9473](https://tickets.puppetlabs.com/browse/PUP-9473) but there's no guarantee that this works in every case.
229+
243230
### network
244231

245232
systemd-networkd is able to manage your network configuration. We provide a

REFERENCE.md

-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#### Public Classes
1010

1111
* [`systemd`](#systemd): This module allows triggering systemd commands once for all modules
12-
* [`systemd::systemctl::daemon_reload`](#systemdsystemctldaemon_reload): Reload the systemctl daemon
1312
* [`systemd::tmpfiles`](#systemdtmpfiles): Update the systemd temp files
1413

1514
#### Private Classes
@@ -238,10 +237,6 @@ Data type: `Boolean`
238237

239238

240239

241-
### `systemd::systemctl::daemon_reload`
242-
243-
Reload the systemctl daemon
244-
245240
### `systemd::tmpfiles`
246241

247242
Update the systemd temp files
@@ -371,14 +366,6 @@ Data type: `Boolean`
371366

372367
Default value: ``true``
373368

374-
##### `daemon_reload`
375-
376-
Data type: `Enum['lazy', 'eager']`
377-
378-
379-
380-
Default value: `'lazy'`
381-
382369
### `systemd::network`
383370

384371
-- Define: systemd::network

manifests/dropin_file.pp

-20
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@
4040
# @attr show_diff
4141
# Whether to show the diff when updating dropin file
4242
#
43-
# @attr daemon_reload
44-
# Set to `lazy` to defer execution of a systemctl daemon reload.
45-
# Minimizes the number of times the daemon is reloaded.
46-
# Set to `eager` to immediately reload after the dropin file is updated.
47-
# Useful if the daemon needs to be reloaded before a service is refreshed.
48-
# May cause multiple daemon reloads.
49-
#
5043
define systemd::dropin_file (
5144
Systemd::Unit $unit,
5245
Systemd::Dropin $filename = $name,
@@ -60,7 +53,6 @@
6053
String $group = 'root',
6154
String $mode = '0444',
6255
Boolean $show_diff = true,
63-
Enum['lazy', 'eager'] $daemon_reload = 'lazy',
6456
) {
6557
include systemd
6658

@@ -95,16 +87,4 @@
9587
selinux_ignore_defaults => $selinux_ignore_defaults,
9688
show_diff => $show_diff,
9789
}
98-
99-
if $daemon_reload == 'lazy' {
100-
File["${path}/${unit}.d/${filename}"] ~> Class['systemd::systemctl::daemon_reload']
101-
} else {
102-
File["${path}/${unit}.d/${filename}"] ~> Exec["${unit}-systemctl-daemon-reload"]
103-
104-
exec { "${unit}-systemctl-daemon-reload":
105-
command => 'systemctl daemon-reload',
106-
refreshonly => true,
107-
path => $facts['path'],
108-
}
109-
}
11090
}

manifests/init.pp

-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@
150150
Hash $dropin_files = {},
151151
Hash $udev_rules = {},
152152
) {
153-
contain systemd::systemctl::daemon_reload
154-
155153
create_resources('systemd::service_limits', $service_limits)
156154

157155
if $manage_resolved and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-resolved.service'] {

manifests/service_limits.pp

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
path => $::path,
7676
refreshonly => true,
7777
subscribe => File["${path}/${name}.d/90-limits.conf"],
78-
require => Class['systemd::systemctl::daemon_reload'],
7978
}
8079
}
8180
}

manifests/system.pp

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
section => 'Manager',
1313
setting => $option,
1414
value => $value,
15-
notify => Class['systemd::systemctl::daemon_reload'],
1615
}
1716
}
1817
}

manifests/systemctl/daemon_reload.pp

-10
This file was deleted.

manifests/unit_file.pp

+8-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
group => $group,
8686
mode => $mode,
8787
show_diff => $show_diff,
88-
notify => Class['systemd::systemctl::daemon_reload'],
8988
}
9089

9190
if $enable != undef or $active != undef {
@@ -103,8 +102,15 @@
103102
}
104103
Service[$name] -> File["${path}/${name}"]
105104
} else {
106-
Class['systemd::systemctl::daemon_reload'] -> Service[$name]
107105
File["${path}/${name}"] ~> Service[$name]
108106
}
107+
} elsif $ensure == 'absent' {
108+
# Work around https://tickets.puppetlabs.com/browse/PUP-9473
109+
exec { "${name}-systemctl-daemon-reload":
110+
command => 'systemctl daemon-reload',
111+
refreshonly => true,
112+
path => $facts['path'],
113+
subscribe => File["${path}/${name}"],
114+
}
109115
}
110116
}

metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"requirements": [
8282
{
8383
"name": "puppet",
84-
"version_requirement": ">= 4.10.10 < 7.0.0"
84+
"version_requirement": ">= 6.1.0 < 7.0.0"
8585
}
8686
],
8787
"pdk-version": "1.18.0",

spec/classes/init_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
it { is_expected.to compile.with_all_deps }
1010
it { is_expected.to create_class('systemd') }
11-
it { is_expected.to create_class('systemd::systemctl::daemon_reload') }
1211
it { is_expected.to contain_class('systemd::journald') }
1312
it { is_expected.to create_service('systemd-journald') }
1413
it { is_expected.to have_ini_setting_resource_count(0) }

spec/classes/systemctl/daemon_reload_spec.rb

-15
This file was deleted.

spec/defines/dropin_file_spec.rb

-16
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@
4444
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").with_selinux_ignore_defaults(true) }
4545
end
4646

47-
context 'with daemon_reload => lazy (default)' do
48-
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").that_notifies('Class[systemd::systemctl::daemon_reload]') }
49-
50-
it { is_expected.not_to create_exec("#{params[:unit]}-systemctl-daemon-reload") }
51-
end
52-
53-
context 'with daemon_reload => eager' do
54-
let(:params) do
55-
super().merge(daemon_reload: 'eager')
56-
end
57-
58-
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").that_notifies("Exec[#{params[:unit]}-systemctl-daemon-reload]") }
59-
60-
it { is_expected.to create_exec("#{params[:unit]}-systemctl-daemon-reload") }
61-
end
62-
6347
context 'with a bad unit type' do
6448
let(:title) { 'test.badtype' }
6549

spec/defines/unit_file_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
.with_ensure('file')
1616
.with_content(%r{#{params[:content]}})
1717
.with_mode('0444')
18-
.that_notifies('Class[systemd::systemctl::daemon_reload]')
1918
end
2019

2120
context 'with a bad unit type' do
@@ -45,7 +44,6 @@
4544
.with_enable(true)
4645
.with_provider('systemd')
4746
.that_subscribes_to("File[/etc/systemd/system/#{title}]")
48-
.that_requires('Class[systemd::systemctl::daemon_reload]')
4947
end
5048
end
5149

0 commit comments

Comments
 (0)