Skip to content

Commit a1251c2

Browse files
authored
Merge pull request #279 from tdevelioglu/decouple_service_from_init_system
Decouple service from init system
2 parents 1ba4616 + f85fcba commit a1251c2

File tree

5 files changed

+60
-57
lines changed

5 files changed

+60
-57
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: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,133 @@
11
# == Class: consul
2-
#
2+
#
33
# Installs, configures and manages consul
4-
#
4+
#
55
# === Parameters
6-
#
6+
#
77
# [*acls*]
88
# Hash of consul_acl resources to create.
9-
#
9+
#
1010
# [*arch*]
1111
# Architecture of consul binary to download.
12-
#
12+
#
1313
# [*archive_path*]
1414
# Path used when installing consul via the url.
15-
#
15+
#
1616
# [*bin_dir*]
1717
# Directory to create the symlink to the consul binary in.
18-
#
18+
#
1919
# [*checks*]
2020
# Hash of consul::check resources to create.
21-
#
21+
#
2222
# [*config_defaults*]
2323
# Configuration defaults hash. Gets merged with config_hash.
24-
#
24+
#
2525
# [*config_dir*]
2626
# Directory to place consul configuration files in.
27-
#
27+
#
2828
# [*config_hash*]
2929
# Use this to populate the JSON config file for consul.
30-
#
30+
#
3131
# [*config_mode*]
3232
# Use this to set the JSON config file mode for consul.
33-
#
33+
#
3434
# [*download_extension*]
3535
# The extension of the archive file containing the consul binary to download.
36-
#
36+
#
3737
# [*download_url*]
3838
# Fully qualified url to the location of the archive file containing the consul binary.
39-
#
39+
#
4040
# [*download_url_base*]
4141
# Base url to the location of the archive file containing the consul binary.
42-
#
42+
#
4343
# [*extra_groups*]
4444
# Extra groups to add the consul system user to.
45-
#
45+
#
4646
# [*extra_options*]
4747
# Extra arguments to be passed to the consul agent
48-
#
48+
#
4949
# [*group*]
5050
# Name of the group that should own the consul configuration files.
51-
#
51+
#
5252
# [*init_style*]
53-
# What style of init system your system uses.
54-
#
53+
# What style of init system your system uses. Set to 'unmanaged' to disable
54+
# managing init system files for the consul service entirely.
55+
#
5556
# [*install_method*]
5657
# Valid strings: `package` - install via system package
5758
# `url` - download and extract from a url. Defaults to `url`.
5859
# `none` - disable install.
59-
#
60+
#
6061
# [*join_wan*]
6162
# Whether to join the wan on service start.
62-
#
63+
#
6364
# [*manage_group*]
6465
# Whether to create/manage the group that should own the consul configuration files.
65-
#
66+
#
6667
# [*manage_service*]
6768
# Whether to manage the consul service.
68-
#
69+
#
6970
# [*manage_user*]
7071
# Whether to create/manage the user that should own consul's configuration files.
71-
#
72+
#
7273
# [*os*]
7374
# OS component in the name of the archive file containing the consul binary.
74-
#
75+
#
7576
# [*package_ensure*]
7677
# Only valid when the install_method == package. Defaults to `latest`.
77-
#
78+
#
7879
# [*package_name*]
7980
# Only valid when the install_method == package. Defaults to `consul`.
80-
#
81+
#
8182
# [*pretty_config*]
8283
# Generates a human readable JSON config file. Defaults to `false`.
83-
#
84+
#
8485
# [*pretty_config_indent*]
8586
# Toggle indentation for human readable JSON file. Defaults to `4`.
86-
#
87+
#
8788
# [*purge_config_dir*]
8889
# Purge config files no longer generated by Puppet
89-
#
90+
#
9091
# [*restart_on_change*]
9192
# Determines whether to restart consul agent on $config_hash changes.
9293
# This will not affect reloads when service, check or watch configs change.
9394
# Defaults to `true`.
94-
#
95+
#
9596
# [*service_enable*]
9697
# Whether to enable the consul service to start at boot.
97-
#
98+
#
9899
# [*service_ensure*]
99100
# Whether the consul service should be running or not.
100-
#
101+
#
101102
# [*services*]
102103
# Hash of consul::service resources to create.
103-
#
104+
#
104105
# [*ui_download_extension*]
105106
# The extension of the archive file containing the consul ui to download.
106-
#
107+
#
107108
# [*ui_download_url*]
108109
# Fully qualified url to the location of the archive file containing the consul ui.
109-
#
110+
#
110111
# [*ui_download_url_base*]
111112
# Base url to the location of the archive file containing the consul ui.
112-
#
113+
#
113114
# [*ui_package_ensure*]
114115
# Only valid when the install_method == package. Defaults to `latest`.
115-
#
116+
#
116117
# [*ui_package_name*]
117118
# Only valid when the install_method == package. Defaults to `consul_ui`.
118-
#
119+
#
119120
# [*user*]
120121
# Name of the user that should own the consul configuration files.
121-
#
122+
#
122123
# [*version*]
123124
# Specify version of consul binary to download.
124-
#
125+
#
125126
# [*watches*]
126127
# Hash of consul::watch resources to create.
127-
#
128+
#
128129
# === Examples
129-
#
130+
#
130131
# @example
131132
# class { '::consul':
132133
# config_hash => {
@@ -136,7 +137,7 @@
136137
# 'retry-join' => ['172.16.0.1'],
137138
# },
138139
# }
139-
#
140+
#
140141
class consul (
141142
$acls = $::consul::params::acls,
142143
$arch = $::consul::params::arch,

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)