From cc1b158f6695ac87f6602bf2a353a2bd15955228 Mon Sep 17 00:00:00 2001 From: fe80 Date: Wed, 21 Sep 2022 10:05:12 +0200 Subject: [PATCH] Unit_file: Add notify_service --- manifests/unit_file.pp | 12 ++++++++++-- spec/defines/unit_file_spec.rb | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/manifests/unit_file.pp b/manifests/unit_file.pp index e434f5b9..8c24a80a 100644 --- a/manifests/unit_file.pp +++ b/manifests/unit_file.pp @@ -64,6 +64,9 @@ # @param daemon_reload # call `systemd::daemon-reload` to ensure that the modified unit file is loaded # +# @param notify_service +# Notify service if systemd file is changed +# # @example manage unit file + service # systemd::unit_file { 'foo.service': # content => file("${module_name}/foo.service"), @@ -88,7 +91,8 @@ Optional[Boolean] $hasstatus = undef, Boolean $selinux_ignore_defaults = false, Hash[String[1], Any] $service_parameters = {}, - Boolean $daemon_reload = true + Boolean $daemon_reload = true, + Boolean $notify_service = true, ) { include systemd @@ -152,7 +156,11 @@ } Service[$name] -> File["${path}/${name}"] } else { - File["${path}/${name}"] ~> Service[$name] + if $notify_service { + File["${path}/${name}"] ~> Service[$name] + } else { + File["${path}/${name}"] -> Service[$name] + } if $daemon_reload { Systemd::Daemon_reload[$name] ~> Service[$name] diff --git a/spec/defines/unit_file_spec.rb b/spec/defines/unit_file_spec.rb index 956f9723..a0521aa2 100644 --- a/spec/defines/unit_file_spec.rb +++ b/spec/defines/unit_file_spec.rb @@ -267,6 +267,16 @@ expect(subject).not_to create_systemd__daemon_reload(title) } end + + context 'notify_service => false' do + let(:params) { { enable: true, notify_service: false } } + + it do + is_expected.not_to contain_service(title).with_subscribes_to( + "File[/etc/systemd/system/#{title}]" + ) + end + end end end end