Skip to content

Commit

Permalink
Merge pull request #378 from schustersv/broker_service_fix
Browse files Browse the repository at this point in the history
fix: honor service_restart in kafka::broker::service
  • Loading branch information
TheMeier authored Dec 13, 2024
2 parents bf54af5 + e1ba820 commit eea3864
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion manifests/broker/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Boolean $manage_service = $kafka::broker::manage_service,
Enum['running', 'stopped'] $service_ensure = $kafka::broker::service_ensure,
String[1] $service_name = $kafka::broker::service_name,
Boolean $service_restart = $kafka::broker::service_restart,
String[1] $user_name = $kafka::broker::user_name,
String[1] $group_name = $kafka::broker::group_name,
Stdlib::Absolutepath $config_dir = $kafka::broker::config_dir,
Expand Down Expand Up @@ -38,12 +39,19 @@

include systemd

if ($service_restart) {
$config_notify = Service[$service_name]
} else {
$config_notify = undef
}

file { "/etc/systemd/system/${service_name}.service":
ensure => file,
mode => '0644',
content => template('kafka/unit.erb'),
notify => $config_notify,
}
~> service { $service_name:
service { $service_name:
ensure => $service_ensure,
enable => true,
hasstatus => true,
Expand Down
8 changes: 8 additions & 0 deletions spec/classes/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
end

context 'defaults' do
it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_notify('Service[kafka]') }
it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=} }
it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=} }
it { is_expected.to contain_service('kafka') }
Expand All @@ -86,6 +87,13 @@
it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^After=dummy\.target$} }
it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^Wants=dummy\.target$} }
end

context 'service_restart false' do
let(:params) { super().merge(service_restart: false) }

it { is_expected.to contain_file('/etc/systemd/system/kafka.service') }
it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_notify('Service[kafka]') }
end
end

it_validates_parameter 'mirror_url'
Expand Down

0 comments on commit eea3864

Please sign in to comment.