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

Allow forcing service restart if control_enable true #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'] }
$service_params = $force_restart ? {
true => $service_require,
false => $service_require + { 'restart' => "${control_path} reload" },
}
Service[$service_name] {
restart => "${control_path} reload",
require => Class['unbound::remote'],
* => $service_params,
}
}
include unbound::remote
Expand Down
13 changes: 13 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 @@ -950,6 +954,8 @@
)
end

it { is_expected.to contain_service(service).with_restart("#{control_path} reload") }

case facts[:os]['family']
when 'FreeBSD'
it { is_expected.to contain_exec('unbound-control-setup').with_command('/usr/local/sbin/unbound-control-setup -d /usr/local/etc/unbound') }
Expand Down Expand Up @@ -1151,6 +1157,13 @@
)
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