-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix systemctl daemon-reload after file additions
* Add a `systemd::daemon_reload` defined type * Ensure that any file additions to the /etc/systemd/system space are followed by a call to `systemd::daemon_reload` * Allow users to disable the calls to `systemd::daemon_reload` * Allow users to globally disable the `systemctl daemon-reload` exec using a resource collector if necessary * Hook the daemon reload between the file creation and the service as is usually necessary, where possible * Add a 'best effort' optional exec as `systemd::lazy_daemon_reload` to try and clean up systems that were modified betweedn 2.9.0 and this release Fixes #234 Fixes #199
- Loading branch information
1 parent
56666b2
commit fbcbbc4
Showing
11 changed files
with
206 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# @summary Run systemctl daemon-reload | ||
# | ||
# @api public | ||
# | ||
# @param name | ||
# A globally unique name for the resource | ||
# | ||
# @param enable | ||
# Enable the reload exec | ||
# | ||
# * Added in case users want to disable the reload globally using a resource collector | ||
# | ||
# @param lazy_reload | ||
# Enable a global lazy reload. | ||
# | ||
# * This is meant for cleaning up systems that may have gotten out of sync so no particular | ||
# care is taken in trying to actually "fix" things, that would require a custom type that | ||
# manipulates the running catalog tree. | ||
# | ||
define systemd::daemon_reload ( | ||
Boolean $enable = true, | ||
Boolean $lazy_reload = false, | ||
) { | ||
if $enable { | ||
if $lazy_reload { | ||
exec { "${module_name}-${name}-global-systemctl-daemon-check": | ||
command => 'systemctl daemon-reload', | ||
onlyif => 'systemctl show "*" --property=NeedDaemonReload | grep -q "=yes"', | ||
path => $facts['path'], | ||
} | ||
|
||
# Give services a fighting chance of coming up properly | ||
Exec["${module_name}-${name}-global-systemctl-daemon-check"] -> Service <||> | ||
} | ||
|
||
exec { "${module_name}-${name}-systemctl-daemon-reload": | ||
command => 'systemctl daemon-reload', | ||
refreshonly => true, | ||
path => $facts['path'], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'systemd::daemon_reload' do | ||
context 'supported operating systems' do | ||
on_supported_os.each do |os, facts| | ||
context "on #{os}" do | ||
let(:facts) { facts } | ||
let(:title) { 'irregardless' } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
context 'with defaults' do | ||
it do | ||
expect(subject).to contain_exec("systemd-#{title}-systemctl-daemon-reload"). | ||
with_command('systemctl daemon-reload'). | ||
with_refreshonly(true) | ||
|
||
expect(subject).not_to contain_exec("systemd-#{title}-global-systemctl-daemon-check") | ||
end | ||
end | ||
|
||
context 'when disabled' do | ||
let(:params) do | ||
{ 'enable' => false } | ||
end | ||
|
||
it do | ||
expect(subject).not_to contain_exec("systemd-#{title}-systemctl-daemon-reload") | ||
end | ||
end | ||
|
||
context 'with lazy reloading' do | ||
let(:pre_condition) { 'service { "test": }' } | ||
let(:params) do | ||
{ 'lazy_reload' => true } | ||
end | ||
|
||
it do | ||
expect(subject).to contain_exec("systemd-#{title}-systemctl-daemon-reload"). | ||
with_command('systemctl daemon-reload'). | ||
with_refreshonly(true) | ||
|
||
expect(subject).to contain_exec("systemd-#{title}-global-systemctl-daemon-check"). | ||
with_command('systemctl daemon-reload'). | ||
with_onlyif('systemctl show "*" --property=NeedDaemonReload | grep -q "=yes"'). | ||
that_comes_before('Service[test]') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.