Skip to content

Commit 75c3cf6

Browse files
committedMar 26, 2024
Don't hardcode the service provider
Since years Puppet is able to figure it out on its own. We don't need to reimplement the logic.
1 parent dea63d6 commit 75c3cf6

File tree

3 files changed

+3
-41
lines changed

3 files changed

+3
-41
lines changed
 

‎REFERENCE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Default value: `true`
242242

243243
##### <a name="-logstash--service_provider"></a>`service_provider`
244244

245-
Data type: `String`
245+
Data type: `Optional[String[1]]`
246246

247247
Service provider (init system) to use. By Default, the module will try to
248248
choose the 'standard' provider for the current distribution.

‎manifests/init.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
$logstash_group = 'logstash',
155155
$config_dir = '/etc/logstash',
156156
Boolean $purge_config = true,
157-
$service_provider = undef,
157+
Optional[String[1]] $service_provider = undef,
158158
$settings = {},
159159
$startup_options = {},
160160
$jvm_options_defaults = {

‎manifests/service.pp

+1-39
Original file line numberDiff line numberDiff line change
@@ -113,50 +113,12 @@
113113
}
114114
}
115115

116-
# Figure out which service provider (init system) we should be using.
117-
# In general, we'll try to guess based on the operating system.
118-
$os = downcase($facts['os']['name'])
119-
$release = $facts['os']['release']['major']
120-
# However, the operator may have explicitly defined the service provider.
121-
if($logstash::service_provider) {
122-
$service_provider = $logstash::service_provider
123-
}
124-
# In the absence of an explicit choice, we'll try to figure out a sensible
125-
# default.
126-
# Puppet 3 doesn't know that Debian 8 uses systemd, not SysV init, so we'll
127-
# help it out with our knowledge from the future.
128-
elsif($os == 'debian' and $release == '8') {
129-
$service_provider = 'systemd'
130-
}
131-
# RedHat/CentOS/OEL 6 uses Upstart by default, but Puppet can get confused about this too.
132-
elsif($os =~ /(redhat|centos|oraclelinux)/ and $release == '6') {
133-
$service_provider = 'upstart'
134-
}
135-
elsif($os =~ /ubuntu/ and $release == '12.04') {
136-
$service_provider = 'upstart'
137-
}
138-
elsif($os =~ /opensuse/ and $release == '13') {
139-
$service_provider = 'systemd'
140-
}
141-
#Older Amazon Linux AMIs has its release based on the year
142-
#it came out (2010 and up); the provider needed to be set explicitly;
143-
#New Amazon Linux 2 AMIs has the release set to 2, Puppet can handle it
144-
elsif($os =~ /amazon/ and versioncmp($release, '2000') > 0) {
145-
$service_provider = 'upstart'
146-
}
147-
else {
148-
# In most cases, Puppet(4) can figure out the correct service
149-
# provider on its own, so we'll just say 'undef', and let it do
150-
# whatever it thinks is best.
151-
$service_provider = undef
152-
}
153-
154116
service { 'logstash':
155117
ensure => $service_ensure,
156118
enable => $service_enable,
157119
hasstatus => true,
158120
hasrestart => true,
159-
provider => $service_provider,
121+
provider => $logstash::service_provider,
160122
}
161123

162124
# If any files tagged as config files for the service are changed, notify

0 commit comments

Comments
 (0)