Skip to content

Commit

Permalink
Decouple managing service and init system from eachother.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Taylan Develioglu committed Sep 19, 2016
1 parent b7b76e0 commit f85fcba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$purge = true,
) {

if $::consul::init_style {
if $::consul::init_style != 'unmanaged' {

case $::consul::init_style {
'upstart': {
Expand Down
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
# Name of the group that should own the consul configuration files.
#
# [*init_style*]
# What style of init system your system uses.
# What style of init system your system uses. Set to 'unmanaged' to disable
# managing init system files for the consul service entirely.
#
# [*install_method*]
# Valid strings: `package` - install via system package
Expand Down
5 changes: 1 addition & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
} elsif $::operatingsystem == 'Amazon' {
$init_style = 'init'
} else {
$init_style = undef
}
if $init_style == undef {
fail('Unsupported OS')
fail('Cannot determine init_style, unsupported OS')
}
}
13 changes: 9 additions & 4 deletions manifests/run_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
#
class consul::run_service {

$init_selector = $::consul::init_style ? {
$service_name = $::consul::init_style ? {
'launchd' => 'io.consul.daemon',
default => 'consul',
}

if $::consul::manage_service == true and $::consul::init_style {
$service_provider = $::consul::init_style ? {
'unmanaged' => undef,
default => $::consul::init_style,
}

if $::consul::manage_service == true {
service { 'consul':
ensure => $::consul::service_ensure,
name => $init_selector,
name => $service_name,
enable => $::consul::service_enable,
provider => $::consul::init_style,
provider => $service_provider,
}
}

Expand Down
6 changes: 3 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@
it { should contain_file('/lib/systemd/system/consul.service').with_content(/consul agent/) }
end

context "When asked not to manage the init_style" do
let(:params) {{ :init_style => false }}
it { should contain_class('consul').with_init_style(false) }
context "When asked not to manage the init system" do
let(:params) {{ :init_style => 'unmanaged' }}
it { should contain_class('consul').with_init_style('unmanaged') }
it { should_not contain_file("/etc/init.d/consul") }
it { should_not contain_file("/lib/systemd/system/consul.service") }
end
Expand Down

0 comments on commit f85fcba

Please sign in to comment.