diff --git a/REFERENCE.md b/REFERENCE.md index d5d9ee9..1a4d504 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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) @@ -274,6 +275,15 @@ the version of the installed unbound instance. defaults to the fact, but you can Default value: `$facts['unbound_version']` +##### `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` + ##### `manage_service` Data type: `Boolean` diff --git a/manifests/init.pp b/manifests/init.pp index edce29e..3060b6a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, @@ -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, @@ -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 diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index d6eea4d..467c022 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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' } @@ -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 @@ -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') } @@ -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