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 a new parameter to the public class `manage_init` that allows
fully shutting down management of the init system so the module can
cover all use cases.
  • Loading branch information
Taylan Develioglu committed Sep 19, 2016
1 parent b7b76e0 commit a87c3a9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 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::manage_init {

case $::consul::init_style {
'upstart': {
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
# [*manage_group*]
# Whether to create/manage the group that should own the consul configuration files.
#
# [*manage_init*]
# Whether to create and manage an init system file for the service. (e.g.
# systemd unit file, or sysv-rc initscript)
#
# [*manage_service*]
# Whether to manage the consul service.
#
Expand Down Expand Up @@ -157,6 +161,7 @@
$install_method = $::consul::params::install_method,
$join_wan = $::consul::params::join_wan,
$manage_group = $::consul::params::manage_group,
$manage_init = $::consul::params::manage_init,
$manage_service = $::consul::params::manage_service,
$manage_user = $::consul::params::manage_user,
$os = $::consul::params::os,
Expand Down Expand Up @@ -197,6 +202,7 @@
validate_hash($watches)
validate_hash($checks)
validate_hash($acls)
validate_bool($manage_init)

$config_hash_real = deep_merge($config_defaults, $config_hash)

Expand Down
6 changes: 2 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$group = 'consul'
$install_method = 'url'
$join_wan = false
$manage_init = true
$manage_group = true
$manage_service = true
$manage_user = true
Expand Down Expand Up @@ -93,9 +94,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')
}
}
2 changes: 1 addition & 1 deletion manifests/run_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
default => 'consul',
}

if $::consul::manage_service == true and $::consul::init_style {
if $::consul::manage_service == true {
service { 'consul':
ensure => $::consul::service_ensure,
name => $init_selector,
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) {{ :manage_init => false }}
it { should contain_class('consul').with_manage_init(false) }
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 a87c3a9

Please sign in to comment.