Skip to content

Commit c3e537b

Browse files
committed
Allow forcing service restart if control_enable true
Also fix some minor rubocop issues Fixes #318
1 parent 59356eb commit c3e537b

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

REFERENCE.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The following parameters are available in the `unbound` class:
4747
* [`unbound_version`](#-unbound--unbound_version)
4848
* [`update_root_hints`](#-unbound--update_root_hints)
4949
* [`interface_automatic_ports`](#-unbound--interface_automatic_ports)
50+
* [`force_restart`](#-unbound--force_restart)
5051
* [`manage_service`](#-unbound--manage_service)
5152
* [`verbosity`](#-unbound--verbosity)
5253
* [`statistics_interval`](#-unbound--statistics_interval)
@@ -290,6 +291,15 @@ specifies the default ports to listen on when interface_automatic is also set to
290291

291292
Default value: `undef`
292293

294+
##### <a name="-unbound--force_restart"></a>`force_restart`
295+
296+
Data type: `Boolean`
297+
298+
if true and manage_service is also true the unbound service will be restarted instead
299+
of reloaded.
300+
301+
Default value: `false`
302+
293303
##### <a name="-unbound--manage_service"></a>`manage_service`
294304

295305
Data type: `Boolean`
@@ -2463,7 +2473,7 @@ Alias of
24632473

24642474
```puppet
24652475
Struct[{
2466-
action => Optional[Enum['deny', 'refuse', 'allow', 'allow_snoop', 'deny_non_local', 'refuse_non_local']],
2476+
action => Optional[Enum['deny', 'refuse', 'allow', 'allow_setrd', 'allow_snoop', 'allow_cookie', 'deny_non_local', 'refuse_non_local']],
24672477
tags => Optional[Array[String]],
24682478
rr_string => Optional[String],
24692479
view => Optional[String],
@@ -2533,7 +2543,7 @@ Struct[{
25332543

25342544
custom enum type for local-zone types
25352545

2536-
Alias of `Enum['deny', 'refuse', 'static', 'transparent', 'redirect', 'nodefault', 'typetransparent', 'inform', 'inform_deny', 'always_transparent', 'always_refuse', 'always_nxdomain']`
2546+
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']`
25372547

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

manifests/init.pp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# @param interface_automatic_ports
1313
# 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"
1414
#
15+
# @param force_restart if true and manage_service is also true the unbound service will be restarted instead
16+
# of reloaded.
1517
class unbound (
1618
Boolean $manage_service = true,
1719
Integer[0,5] $verbosity = 1,
@@ -190,6 +192,7 @@
190192
Boolean $service_enable = true,
191193
String[1] $validate_cmd = '/usr/sbin/unbound-checkconf %',
192194
String[1] $restart_cmd = "/bin/systemctl restart ${service_name}",
195+
Boolean $force_restart = false,
193196
Array[String[1]] $custom_server_conf = [],
194197
Boolean $skip_roothints_download = false,
195198
Optional[Stdlib::Absolutepath] $python_script = undef,
@@ -279,9 +282,13 @@
279282
require => $service_reuse,
280283
}
281284
if $manage_service {
285+
$service_require = { 'require' => Class['unbound::remote'] }
286+
$service_params = $force_restart ? {
287+
true => $service_require,
288+
false => $service_require + { 'restart' => "${control_path} reload" },
289+
}
282290
Service[$service_name] {
283-
restart => "${control_path} reload",
284-
require => Class['unbound::remote'],
291+
* => $service_params,
285292
}
286293
}
287294
include unbound::remote

spec/classes/init_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424
let(:service) { 'unbound' }
2525
let(:conf_dir) { '/etc/unbound' }
2626
let(:purge_unbound_conf_d) { true }
27+
let(:control_path) { '/usr/sbin/unbound-control' }
2728
when 'OpenBSD'
2829
pidfile = '/var/run/unbound.pid'
2930
let(:service) { 'unbound' }
3031
let(:conf_dir) { '/var/unbound/etc' }
3132
let(:purge_unbound_conf_d) { false }
33+
let(:control_path) { '/usr/sbin/unbound-control' }
3234
when 'FreeBSD'
3335
pidfile = '/usr/local/etc/unbound/unbound.pid'
3436
let(:service) { 'unbound' }
3537
let(:conf_dir) { '/usr/local/etc/unbound' }
3638
let(:purge_unbound_conf_d) { false }
39+
let(:control_path) { '/usr/local/sbin/unbound-control' }
3740
when 'Darwin'
3841
pidfile = '/var/run/unbound.pid'
3942
let(:service) { 'org.macports.unbound' }
@@ -44,6 +47,7 @@
4447
let(:service) { 'unbound' }
4548
let(:conf_dir) { '/etc/unbound' }
4649
let(:purge_unbound_conf_d) { false }
50+
let(:control_path) { '/usr/sbin/unbound-control' }
4751
end
4852

4953
context 'with default params' do
@@ -945,6 +949,8 @@
945949
)
946950
end
947951

952+
it { is_expected.to contain_service(service).with_restart("#{control_path} reload") }
953+
948954
case facts[:os]['family']
949955
when 'FreeBSD'
950956
it { is_expected.to contain_exec('unbound-control-setup').with_command('/usr/local/sbin/unbound-control-setup -d /usr/local/etc/unbound') }
@@ -1194,6 +1200,13 @@
11941200
)
11951201
end
11961202
end
1203+
1204+
context 'with force_restart' do
1205+
let(:params) { { force_restart: true, control_enable: true } }
1206+
1207+
it { is_expected.to compile.with_all_deps }
1208+
it { is_expected.to contain_service(service).with_restart(nil) }
1209+
end
11971210
end
11981211
end
11991212
# rubocop:enable RSpec/MultipleMemoizedHelpers

0 commit comments

Comments
 (0)