Skip to content

Commit

Permalink
Remove init script management.
Browse files Browse the repository at this point in the history
The module should no longer try to manage the init script for Logstash.
Firstly, Logstash 5 does a much better job of providing init config,
including systemd unit files. Secondly, very few distros actually use SysV
init anymore, so forcing them to use fallback support via a classical script
in /etc/init.d is a bad idea.
  • Loading branch information
ninaspitfire committed Nov 4, 2016
1 parent ad6b082 commit 61521ed
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 215 deletions.
5 changes: 0 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
$logstash_group = $logstash::params::logstash_group,
$configdir = $logstash::params::configdir,
$purge_configdir = $logstash::params::purge_configdir,
$service_provider = 'init',
$init_defaults = undef,
$init_defaults_file = undef,
$init_template = undef,
Expand Down Expand Up @@ -203,10 +202,6 @@
# purge conf dir
validate_bool($purge_configdir)

if ! ($service_provider in $logstash::params::service_providers) {
fail("\"${service_provider}\" is not a valid provider for \"${::operatingsystem}\"")
}

if ($package_url != undef and $version != false) {
fail('Unable to set the version number when using package_url option.')
}
Expand Down
1 change: 0 additions & 1 deletion manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# * Richard Pijnenburg <mailto:[email protected]>
#
class logstash::package {
require ::java

Exec {
path => [ '/bin', '/usr/bin', '/usr/local/bin' ],
Expand Down
34 changes: 1 addition & 33 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
$configdir = '/etc/logstash'
$package_dir = '/var/lib/logstash/swdl'
$installpath = '/opt/logstash'
$plugin = '/opt/logstash/bin/plugin'
$plugin = '/usr/share/logstash/bin/plugin'
}
'Darwin': {
$configdir = '/Library/Application Support/Logstash'
Expand Down Expand Up @@ -127,36 +127,4 @@
for \"${::operatingsystem}\"")
}
}

# service parameters
case $::operatingsystem {
'RedHat', 'CentOS', 'Fedora', 'Scientific', 'Amazon', 'OracleLinux', 'SLES', 'OpenSuSE': {
$service_name = 'logstash'
$service_hasrestart = true
$service_hasstatus = true
$service_pattern = $service_name
$service_providers = [ 'init' ]
$defaults_location = '/etc/sysconfig'
}
'Debian', 'Ubuntu': {
$service_name = 'logstash'
$service_hasrestart = true
$service_hasstatus = true
$service_pattern = $service_name
$service_providers = [ 'init' ]
$defaults_location = '/etc/default'
}
'Darwin': {
$service_name = 'net.logstash'
$service_hasrestart = true
$service_hasstatus = true
$service_pattern = $service_name
$service_providers = [ 'launchd' ]
$defaults_location = false
}
default: {
fail("\"${module_name}\" provides no service parameters
for \"${::operatingsystem}\"")
}
}
}
6 changes: 3 additions & 3 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
{
require logstash::package
$exe = '/opt/logstash/bin/plugin'
$exe = '/usr/share/logstash/bin/plugin'

# Install plugin as logstash user and make
# sure we find su on centos and debian
Expand All @@ -42,14 +42,14 @@
case $source { # Where should we get the plugin from?
undef: {
# No explict source, so search Rubygems for the plugin, by name.
# ie. "/opt/logstash/bin/plugin install logstash-output-elasticsearch"
# ie. "/usr/share/logstash/bin/plugin install logstash-output-elasticsearch"
$plugin = $name
}

/^\//: {
# A gem file that is already available on the local filesystem.
# Install from the local path.
# ie. "/opt/logstash/bin/plugin install /tmp/logtash-filter-custom.gem"
# ie. "/usr/share/logstash/bin/plugin install /tmp/logtash-filter-custom.gem"
$plugin = $source
}

Expand Down
81 changes: 76 additions & 5 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,84 @@
class logstash::service {
require ::java

case $logstash::service_provider {
'init': {
logstash::service::init { $logstash::params::service_name: }
# set params: in operation
if $logstash::ensure == 'present' {
case $logstash::status {
# make sure service is currently running, start it on boot
'enabled': {
$service_ensure = 'running'
$service_enable = true
}
# make sure service is currently stopped, do not start it on boot
'disabled': {
$service_ensure = 'stopped'
$service_enable = false
}
# make sure service is currently running, do not start it on boot
'running': {
$service_ensure = 'running'
$service_enable = false
}
# do not start service on boot, do not care whether currently running
# or not
'unmanaged': {
$service_ensure = undef
$service_enable = false
}
# unknown status
# note: don't forget to update the parameter check in init.pp if you
# add a new or change an existing status.
default: {
fail("\"${logstash::status}\" is an unknown service status value")
}
}

default: {
fail("Unknown service provider ${logstash::service_provider}")
# set params: removal
} else {
# make sure the service is stopped and disabled (the removal itself will be
# done by package.pp)
$service_ensure = 'stopped'
$service_enable = false
}

if ( $logstash::status != 'unmanaged' ) {
# defaults file content. Either from a hash or file
if ($logstash::init_defaults_file != undef) {
$defaults_content = undef
$defaults_source = $logstash::init_defaults_file
} elsif ($logstash::init_defaults != undef and is_hash($logstash::init_defaults) ) {
$defaults_content = template("${module_name}/etc/sysconfig/defaults.erb")
$defaults_source = undef
} else {
$defaults_content = undef
$defaults_source = undef
}

# Check if we are going to manage the defaults file.
if ( $defaults_content != undef or $defaults_source != undef ) {
file { "${logstash::params::defaults_location}/${name}":
ensure => $logstash::ensure,
source => $defaults_source,
content => $defaults_content,
owner => 'root',
group => 'root',
mode => '0644',
tag => ['logstash_config'],
}
}
}

service { 'logstash':
ensure => $service_ensure,
enable => $service_enable,
hasstatus => true,
hasrestart => true,
}

# If any files tagged as config files for the service are changed, notify
# the service so it restarts.
if $::logstash::restart_on_change {
File<| tag == 'logstash_config' |> ~> Service['logstash']
Logstash::Plugin<| |> ~> Service['logstash']
}
}
155 changes: 0 additions & 155 deletions manifests/service/init.pp

This file was deleted.

6 changes: 1 addition & 5 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{
"name": "elasticsearch-logstash",
"version": "0.6.4",
"version": "5.0.0",
"source": "https://github.com/elastic/puppet-logstash",
"author": "elasticsearch",
"license": "Apache-2.0",
"summary": "Module for managing and configuring Logstash",
"description": "Module for managing and configuring Logstash",
"project_page": "https://github.com/elastic/puppet-logstash",
"dependencies": [
{
"name": "puppetlabs/java",
"version_requirement": ">= 1.6.0 <2.0.0"
},
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 3.2.0 <5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/class_logstash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

shared_examples 'a logstash installer' do
it "should install logstash version #{LS_VERSION}" do
expect(shell('/opt/logstash/bin/logstash --version').stdout).to eq("logstash #{LS_VERSION}\n")
expect(shell('/usr/share/logstash/bin/logstash --version').stdout).to eq("logstash #{LS_VERSION}\n")
end

describe package('logstash') do
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/class_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class { 'logstash':
end

def installed_plugins
shell('/opt/logstash/bin/plugin list').stdout
shell('/usr/share/logstash/bin/plugin list').stdout
end

def remove(plugin)
shell("/opt/logstash/bin/plugin uninstall #{plugin} || true")
shell("/usr/share/logstash/bin/plugin uninstall #{plugin} || true")
end

before(:all) do
Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/nodesets/debian-7-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ HOSTS:
hypervisor: docker
docker_cmd: '["/sbin/init"]'
docker_image_commands:
- 'apt-get install -yq lsb-release wget net-tools ruby rubygems ruby1.8-dev libaugeas-dev libaugeas-ruby ntpdate locales-all logrotate'
- 'REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc'
- apt-get update
- apt-get -y upgrade
- apt-get install -yq lsb-release wget net-tools ruby rubygems ruby1.8-dev libaugeas-dev libaugeas-ruby ntpdate locales-all logrotate
- REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc
docker_preserve_image: true
CONFIG:
type: foss
Expand Down
Loading

0 comments on commit 61521ed

Please sign in to comment.