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

fix: refresh service only based on drop-in file changes #406

Merged
merged 2 commits into from
Jun 2, 2024
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
4 changes: 2 additions & 2 deletions manifests/dropin_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@
File[$full_filename] ~> Service <| title == $unit or name == $unit |>

if $daemon_reload {
Systemd::Daemon_reload[$unit] ~> Service <| title == $unit or name == $unit |>
Systemd::Daemon_reload[$unit] -> Service <| title == $unit or name == $unit |>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't a notify anymore, should this be around line 77 instead? I think the ordering is still correct. Same for the other case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this @ekohl. The conditions stay the same. The ordering of the Daemon_reload in relation to the Service still only needs to happen when both $notify_service and $daemon_reload are true.

}

if $unit =~ /\.service$/ {
$short_service_name = regsubst($unit, /\.service$/, '')
File[$full_filename] ~> Service <| title == $short_service_name or name == $short_service_name |>

if $daemon_reload {
Systemd::Daemon_reload[$unit] ~> Service <| title == $short_service_name or name == $short_service_name |>
Systemd::Daemon_reload[$unit] -> Service <| title == $short_service_name or name == $short_service_name |>
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion spec/defines/dropin_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,32 @@

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service('myservice').that_subscribes_to("File[#{filename}]") }
it { is_expected.to contain_systemd__daemon_reload(params[:unit]).that_notifies('Service[myservice]') }
it { is_expected.not_to contain_systemd__daemon_reload(params[:unit]).that_notifies('Service[myservice]') }
it { is_expected.to contain_systemd__daemon_reload(params[:unit]).that_comes_before('Service[myservice]') }
end
end

context 'doesn\'t notify services' do
let(:params) do
super().merge(notify_service: false)
end
let(:filename) { "/etc/systemd/system/#{params[:unit]}.d/#{title}" }
let(:pre_condition) do
<<-PUPPET
service { ['test', 'test.service']:
}
PUPPET
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service('test') }
it { is_expected.not_to contain_service('test').that_subscribes_to("File[#{filename}]") }
it { is_expected.not_to contain_service('test').that_subscribes_to("Systemd::Daemon_reload[#{params[:unit]}]") }
it { is_expected.to contain_service('test.service') }
it { is_expected.not_to contain_service('test.service').that_subscribes_to("File[#{filename}]") }
it { is_expected.not_to contain_service('test.service').that_subscribes_to("Systemd::Daemon_reload[#{params[:unit]}]") }
end

context 'with selinux_ignore_defaults set to true' do
let(:params) do
super().merge(selinux_ignore_defaults: true)
Expand Down