Skip to content

Commit f85fcba

Browse files
author
Taylan Develioglu
committed
Decouple managing service and init system from eachother.
Previously the logic didn't make sense, where one could pass a bool to the parameter `init_style` that expects a string to toggle the management of service files in the init system and it was impossible to let the module manage the service but not the init system. This breaks the common case of where you want to let a package prep the init system but still let the module manage the service. This commit decouples the service resource from management of the init system so it offers the choice of using the module-supplied init files. It adds support for a magic value `unmanaged` on parameter `init_style` that disables management of the init system.
1 parent b7b76e0 commit f85fcba

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

manifests/config.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
$purge = true,
1616
) {
1717

18-
if $::consul::init_style {
18+
if $::consul::init_style != 'unmanaged' {
1919

2020
case $::consul::init_style {
2121
'upstart': {

manifests/init.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
# Name of the group that should own the consul configuration files.
5151
#
5252
# [*init_style*]
53-
# What style of init system your system uses.
53+
# What style of init system your system uses. Set to 'unmanaged' to disable
54+
# managing init system files for the consul service entirely.
5455
#
5556
# [*install_method*]
5657
# Valid strings: `package` - install via system package

manifests/params.pp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@
9393
} elsif $::operatingsystem == 'Amazon' {
9494
$init_style = 'init'
9595
} else {
96-
$init_style = undef
97-
}
98-
if $init_style == undef {
99-
fail('Unsupported OS')
96+
fail('Cannot determine init_style, unsupported OS')
10097
}
10198
}

manifests/run_service.pp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
#
66
class consul::run_service {
77

8-
$init_selector = $::consul::init_style ? {
8+
$service_name = $::consul::init_style ? {
99
'launchd' => 'io.consul.daemon',
1010
default => 'consul',
1111
}
1212

13-
if $::consul::manage_service == true and $::consul::init_style {
13+
$service_provider = $::consul::init_style ? {
14+
'unmanaged' => undef,
15+
default => $::consul::init_style,
16+
}
17+
18+
if $::consul::manage_service == true {
1419
service { 'consul':
1520
ensure => $::consul::service_ensure,
16-
name => $init_selector,
21+
name => $service_name,
1722
enable => $::consul::service_enable,
18-
provider => $::consul::init_style,
23+
provider => $service_provider,
1924
}
2025
}
2126

spec/classes/init_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@
694694
it { should contain_file('/lib/systemd/system/consul.service').with_content(/consul agent/) }
695695
end
696696

697-
context "When asked not to manage the init_style" do
698-
let(:params) {{ :init_style => false }}
699-
it { should contain_class('consul').with_init_style(false) }
697+
context "When asked not to manage the init system" do
698+
let(:params) {{ :init_style => 'unmanaged' }}
699+
it { should contain_class('consul').with_init_style('unmanaged') }
700700
it { should_not contain_file("/etc/init.d/consul") }
701701
it { should_not contain_file("/lib/systemd/system/consul.service") }
702702
end

0 commit comments

Comments
 (0)