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

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 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:
* [`unbound_version`](#-unbound--unbound_version)
* [`update_root_hints`](#-unbound--update_root_hints)
* [`interface_automatic_ports`](#-unbound--interface_automatic_ports)
* [`force_restart`](#-unbound--force_restart)
* [`manage_service`](#-unbound--manage_service)
* [`verbosity`](#-unbound--verbosity)
* [`statistics_interval`](#-unbound--statistics_interval)
Expand Down Expand Up @@ -290,6 +291,15 @@ specifies the default ports to listen on when interface_automatic is also set to

Default value: `undef`

##### <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 Expand Up @@ -2463,7 +2473,7 @@ Alias of

```puppet
Struct[{
action => Optional[Enum['deny', 'refuse', 'allow', 'allow_snoop', 'deny_non_local', 'refuse_non_local']],
action => Optional[Enum['deny', 'refuse', 'allow', 'allow_setrd', 'allow_snoop', 'allow_cookie', 'deny_non_local', 'refuse_non_local']],
tags => Optional[Array[String]],
rr_string => Optional[String],
view => Optional[String],
Expand Down Expand Up @@ -2533,7 +2543,7 @@ Struct[{

custom enum type for local-zone types

Alias of `Enum['deny', 'refuse', 'static', 'transparent', 'redirect', 'nodefault', 'typetransparent', 'inform', 'inform_deny', 'always_transparent', 'always_refuse', 'always_nxdomain']`
Alias of `Enum['deny', 'refuse', 'static', 'transparent', 'redirect', 'nodefault', 'typetransparent', 'inform', 'inform_deny', 'inform_redirect', 'always_transparent', 'block_a', 'always_refuse', 'always_nxdomain', 'always_null', 'noview', 'nodefault']`

### <a name="Unbound--Module"></a>`Unbound::Module`

Expand Down
11 changes: 9 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# @param interface_automatic_ports
# specifies the default ports to listen on when interface_automatic is also set to true, defaults to undef, specify as a string of space seperated ports e.g. "53 853 443"
#
# @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 @@ -190,6 +192,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 @@ -279,9 +282,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 @@ -24,16 +24,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 @@ -44,6 +47,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 @@ -945,6 +949,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 @@ -1194,6 +1200,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
Loading