Defined Type: elasticsearch::service::openrc

Defined in:
manifests/service/openrc.pp

Overview

Define: elasticsearch::service::init

This class exists to coordinate all service management related actions, functionality and logical units in a central place.

Note: “service” is the Puppet term and type for background processes in general and is used in a platform-independent way. E.g. “service” means “daemon” in relation to Unix-like systems.

Parameters

ensure

String. Controls if the managed resources shall be present or absent. If set to absent:

  • The managed software packages are being uninstalled.

  • Any traces of the packages will be purged as good as possible. This may include existing configuration files. The exact behavior is provider dependent. Q.v.:

  • System modifications (if any) will be reverted as good as possible (e.g. removal of created users, services, changed log settings, …).

  • This is thus destructive and should be used with care.

Defaults to present.

status

String to define the status of the service. Possible values:

  • enabled: Service is running and will be started at boot time.

  • disabled: Service is stopped and will not be started at boot time.

  • running: Service is running but will not be started at boot time. You can use this to start a service on the first Puppet run instead of the system startup.

  • unmanaged: Service will not be started at boot time and Puppet does not care whether the service is running or not. For example, this may be useful if a cluster management software is used to decide when to start the service plus assuring it is running on the desired node.

Defaults to enabled. The singular form (“service”) is used for the sake of convenience. Of course, the defined status affects all services if more than one is managed (see service.pp to check if this is the case).

init_defaults

Defaults file content in hash representation

init_defaults_file

Defaults file as puppet resource

init_template

Service file as a template

Authors

Parameters:

  • ensure (Any) (defaults to: $elasticsearch::ensure)
  • status (Any) (defaults to: $elasticsearch::status)
  • init_defaults_file (Any) (defaults to: undef)
  • init_defaults (Any) (defaults to: undef)
  • init_template (Any) (defaults to: undef)


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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'manifests/service/openrc.pp', line 57

define elasticsearch::service::openrc(
  $ensure             = $elasticsearch::ensure,
  $status             = $elasticsearch::status,
  $init_defaults_file = undef,
  $init_defaults      = undef,
  $init_template      = undef,
) {

  #### Service management

  # set params: in operation
  if $ensure == 'present' {

    case $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("\"${status}\" is an unknown service status value")
      }
    }

  # 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

  }

  $notify_service = $elasticsearch::restart_config_change ? {
    true  => Service["elasticsearch-instance-${name}"],
    false => undef,
  }


  if ( $status != 'unmanaged' and $ensure == 'present' ) {

    # defaults file content. Either from a hash or file
    if ($init_defaults_file != undef) {
      file { "${elasticsearch::params::defaults_location}/elasticsearch.${name}":
        ensure => $ensure,
        source => $init_defaults_file,
        owner  => 'root',
        group  => '0',
        mode   => '0644',
        before => Service["elasticsearch-instance-${name}"],
        notify => $notify_service,
      }

    } elsif ($init_defaults != undef and is_hash($init_defaults) ) {

      if(has_key($init_defaults, 'ES_USER')) {
        if($init_defaults['ES_USER'] != $elasticsearch::elasticsearch_user) {
          fail('Found ES_USER setting for init_defaults but is not same as elasticsearch_user setting. Please use elasticsearch_user setting.')
        }
      }

      $init_defaults_pre_hash = {
        'ES_USER' => $elasticsearch::elasticsearch_user,
        'ES_GROUP' => $elasticsearch::elasticsearch_group,
        'MAX_OPEN_FILES' => '65536',
      }
      $new_init_defaults = merge($init_defaults_pre_hash, $init_defaults)

      augeas { "defaults_${name}":
        incl    => "${elasticsearch::params::defaults_location}/elasticsearch.${name}",
        lens    => 'Shellvars.lns',
        changes => template("${module_name}/etc/sysconfig/defaults.erb"),
        before  => Service["elasticsearch-instance-${name}"],
        notify  => $notify_service,
      }

    }

    # init file from template
    if ($init_template != undef) {

      elasticsearch_service_file { "/etc/init.d/elasticsearch.${name}":
        ensure       => $ensure,
        content      => file($init_template),
        instance     => $name,
        notify       => $notify_service,
        package_name => $elasticsearch::package_name,
      } ->
      file { "/etc/init.d/elasticsearch.${name}":
        ensure => $ensure,
        owner  => 'root',
        group  => '0',
        mode   => '0755',
        before => Service["elasticsearch-instance-${name}"],
        notify => $notify_service,
      }

    }

  } elsif ($status != 'unmanaged') {

    file { "/etc/init.d/elasticsearch.${name}":
      ensure    => 'absent',
      subscribe => Service["elasticsearch-instance-${name}"],
    }

    file { "${elasticsearch::params::defaults_location}/elasticsearch.${name}":
      ensure    => 'absent',
      subscribe => Service["elasticsearch.${$name}"],
    }

  }


  if ( $status != 'unmanaged') {

    # action
    service { "elasticsearch-instance-${name}":
      ensure     => $service_ensure,
      enable     => $service_enable,
      name       => "elasticsearch.${name}",
      hasstatus  => $elasticsearch::params::service_hasstatus,
      hasrestart => $elasticsearch::params::service_hasrestart,
      pattern    => $elasticsearch::params::service_pattern,
    }

  }

}