Puppet Class: logstash::service

Defined in:
manifests/service.pp

Overview

This mangages the system service for Logstash.

It is usually used only by the top-level logstash class. It's unlikely that you will need to declare this class yourself.

Examples:

Include this class to ensure its resources are available.

include logstash::service

Author:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'manifests/service.pp', line 11

class logstash::service {
  $default_settings = {
    'path.data'   => '/var/lib/logstash',
    'path.config' => '/etc/logstash/conf.d',
    'path.logs'   => '/var/log/logstash',
  }

  $default_startup_options = {
    'JAVACMD'             => '/usr/bin/java',
    'LS_HOME'             => '/usr/share/logstash',
    'LS_SETTINGS_DIR'     => '/etc/logstash',
    'LS_OPTS'             => '"--path.settings ${LS_SETTINGS_DIR}"',
    'LS_JAVA_OPTS'        => '""',
    'LS_PIDFILE'          => '/var/run/logstash.pid',
    'LS_USER'             => $logstash::logstash_user,
    'LS_GROUP'            => $logstash::logstash_group,
    'LS_GC_LOG_FILE'      => '/var/log/logstash/gc.log',
    'LS_OPEN_FILES'       => '16384',
    'LS_NICE'             => '19',
    'SERVICE_NAME'        => '"logstash"',
    'SERVICE_DESCRIPTION' => '"logstash"',
  }

  $default_jvm_options = [
    '-Dfile.encoding=UTF-8',
    '-Djava.awt.headless=true',
    '-Xms256m',
    '-Xmx1g',
    '-XX:CMSInitiatingOccupancyFraction=75',
    '-XX:+DisableExplicitGC',
    '-XX:+HeapDumpOnOutOfMemoryError',
    '-XX:+UseCMSInitiatingOccupancyOnly',
    '-XX:+UseConcMarkSweepGC',
    '-XX:+UseParNewGC',
  ]

  $settings = merge($default_settings, $logstash::settings)
  $startup_options = merge($default_startup_options, $logstash::startup_options)
  $jvm_options = $logstash::jvm_options

  if $logstash::ensure == 'present' {
    case $logstash::status {
      'enabled': {
        $service_ensure = 'running'
        $service_enable = true
      }
      'disabled': {
        $service_ensure = 'stopped'
        $service_enable = false
      }
      'running': {
        $service_ensure = 'running'
        $service_enable = false
      }
      default: {
        fail("\"${logstash::status}\" is an unknown service status value")
      }
    }
  } else {
    $service_ensure = 'stopped'
    $service_enable = false
  }

  if $service_ensure == 'running' {
    # Then make sure the Logstash startup options are up to date.
    file {'/etc/logstash/startup.options':
      content => template('logstash/startup.options.erb'),
    }

    # ..and make sure the JVM options are up to date.
    file {'/etc/logstash/jvm.options':
      content => template('logstash/jvm.options.erb'),
    }

    # ..and the Logstash internal settings too.
    file {'/etc/logstash/logstash.yml':
      content => template('logstash/logstash.yml.erb'),
    }

    # Invoke 'system-install', which generates startup scripts based on the
    # contents of the 'startup.options' file.
    exec { 'logstash-system-install':
      command     => '/usr/share/logstash/bin/system-install',
      refreshonly => true,
      notify      => Service['logstash'],
    }
  }

  # Figure out which service provider (init system) we should be using.
  # In general, we'll try to guess based on the operating system.
  $os = downcase($::operatingsystem)
  $release = $::operatingsystemmajrelease
  # However, the operator may have explicitly defined the service provider.
  if($logstash::service_provider) {
    $service_provider = $logstash::service_provider
  }
  # In the absence of an explicit choice, we'll try to figure out a sensible
  # default.
  # Puppet 3 doesn't know that Debian 8 uses systemd, not SysV init, so we'll
  # help it out with our knowledge from the future.
  elsif($os == 'debian' and $release == '8') {
    $service_provider = 'systemd'
  }
  # Centos 6 uses Upstart by default, but Puppet can get confused about this too.
  elsif($os =~ /(redhat|centos)/ and $release == '6') {
    $service_provider = 'upstart'
  }
  elsif($os =~ /ubuntu/ and $release == '12.04') {
    $service_provider = 'upstart'
  }
  elsif($os =~ /opensuse/ and $release == '13') {
    $service_provider = 'systemd'
  }
  else {
    # In most cases, Puppet(4) can figure out the correct service
    # provider on its own, so we'll just say 'undef', and let it do
    # whatever it thinks is best.
    $service_provider = undef
  }

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

  # 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']
  }

  File {
    owner  => 'root',
    group  => 'root',
    mode   => '0664',
    notify => Exec['logstash-system-install'],
  }
}