Skip to content

Commit

Permalink
Allow forcing service restart if control_enable true
Browse files Browse the repository at this point in the history
Fixes #318
  • Loading branch information
b4ldr committed Aug 28, 2023
1 parent e431b7a commit 455c6db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The following parameters are available in the `unbound` class:
* [`hints_file`](#-unbound--hints_file)
* [`hints_file_content`](#-unbound--hints_file_content)
* [`unbound_version`](#-unbound--unbound_version)
* [`force_restart`](#-unbound--force_restart)
* [`manage_service`](#-unbound--manage_service)
* [`verbosity`](#-unbound--verbosity)
* [`statistics_interval`](#-unbound--statistics_interval)
Expand Down Expand Up @@ -274,6 +275,15 @@ the version of the installed unbound instance. defaults to the fact, but you can

Default value: `$facts['unbound_version']`

##### <a name="-unbound--force_restart"></a>`force_restart`

Data type: `Boolean`

if true and manage_service is also true the unbound service will be restarted instead
of reloaded.

Default value: `false`

##### <a name="-unbound--manage_service"></a>`manage_service`

Data type: `Boolean`
Expand Down
11 changes: 9 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# Contents of the root hints file, if it's not remotely fetched.
# @param unbound_version
# the version of the installed unbound instance. defaults to the fact, but you can overwrite it. this reduces the initial puppet runs from two to one
# @param force_restart if true and manage_service is also true the unbound service will be restarted instead
# of reloaded.
class unbound (
Boolean $manage_service = true,
Integer[0,5] $verbosity = 1,
Expand Down Expand Up @@ -185,6 +187,7 @@
Boolean $service_enable = true,
String[1] $validate_cmd = '/usr/sbin/unbound-checkconf %',
String[1] $restart_cmd = "/bin/systemctl restart ${service_name}",
Boolean $force_restart = false,
Array[String[1]] $custom_server_conf = [],
Boolean $skip_roothints_download = false,
Optional[Stdlib::Absolutepath] $python_script = undef,
Expand Down Expand Up @@ -273,9 +276,13 @@
require => $service_reuse,
}
if $manage_service {
$service_require = {'require' => Class['unbound::remote']}

Check failure on line 279 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or newline before a closing brace (check: manifest_whitespace_closing_brace_before)

Check failure on line 279 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be either a bracket, punctuation mark, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned (check: manifest_whitespace_closing_bracket_after)

Check failure on line 279 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or single newline after an opening brace (check: manifest_whitespace_opening_brace_after)
$service_params = $force_restart ? {
true => $service_require,
false => $service_require + {'restart' => "${control_path} reload"},

Check failure on line 282 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or newline before a closing brace (check: manifest_whitespace_closing_brace_before)

Check failure on line 282 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or single newline after an opening brace (check: manifest_whitespace_opening_brace_after)
}
Service[$service_name] {
restart => "${control_path} reload",
require => Class['unbound::remote'],
* => $service_params,
}
}
include unbound::remote
Expand Down
11 changes: 11 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@
let(:service) { 'unbound' }
let(:conf_dir) { '/etc/unbound' }
let(:purge_unbound_conf_d) { true }
let(:control_path) { '/usr/sbin/unbound-control' }
when 'OpenBSD'
pidfile = '/var/run/unbound.pid'
let(:service) { 'unbound' }
let(:conf_dir) { '/var/unbound/etc' }
let(:purge_unbound_conf_d) { false }
let(:control_path) { '/usr/sbin/unbound-control' }
when 'FreeBSD'
pidfile = '/usr/local/etc/unbound/unbound.pid'
let(:service) { 'unbound' }
let(:conf_dir) { '/usr/local/etc/unbound' }
let(:purge_unbound_conf_d) { false }
let(:control_path) { '/usr/local/sbin/unbound-control' }
when 'Darwin'
pidfile = '/var/run/unbound.pid'
let(:service) { 'org.macports.unbound' }
Expand All @@ -53,6 +56,7 @@
let(:service) { 'unbound' }
let(:conf_dir) { '/etc/unbound' }
let(:purge_unbound_conf_d) { false }
let(:control_path) { '/usr/sbin/unbound-control' }
end

context 'with default params' do
Expand Down Expand Up @@ -949,6 +953,7 @@
%r{^ control-enable: yes\n}
)
end
it { is_expected.to contain_service(service).with_restart("#{control_path} reload") }

case facts[:os]['family']
when 'FreeBSD'
Expand Down Expand Up @@ -1151,6 +1156,12 @@
)
end
end
context 'with force_restart' do
let(:params) {{ force_restart: true, control_enable: true }}

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service(service).with_restart(nil) }
end
end
end
# rubocop:enable RSpec/MultipleMemoizedHelpers
Expand Down

0 comments on commit 455c6db

Please sign in to comment.