1 # == Define: elasticsearch::service::init
3 # This class exists to coordinate all service management related actions,
4 # functionality and logical units in a central place.
6 # <b>Note:</b> "service" is the Puppet term and type for background processes
7 # in general and is used in a platform-independent way. E.g. "service" means
8 # "daemon" in relation to Unix-like systems.
14 # String. Controls if the managed resources shall be <tt>present</tt> or
15 # <tt>absent</tt>. If set to <tt>absent</tt>:
16 # * The managed software packages are being uninstalled.
17 # * Any traces of the packages will be purged as good as possible. This may
18 # include existing configuration files. The exact behavior is provider
20 # * Puppet type reference: {package, "purgeable"}[http://j.mp/xbxmNP]
21 # * {Puppet's package provider source code}[http://j.mp/wtVCaL]
22 # * System modifications (if any) will be reverted as good as possible
23 # (e.g. removal of created users, services, changed log settings, ...).
24 # * This is thus destructive and should be used with care.
25 # Defaults to <tt>present</tt>.
28 # String to define the status of the service. Possible values:
29 # * <tt>enabled</tt>: Service is running and will be started at boot time.
30 # * <tt>disabled</tt>: Service is stopped and will not be started at boot
32 # * <tt>running</tt>: Service is running but will not be started at boot time.
33 # You can use this to start a service on the first Puppet run instead of
35 # * <tt>unmanaged</tt>: Service will not be started at boot time and Puppet
36 # does not care whether the service is running or not. For example, this may
37 # be useful if a cluster management software is used to decide when to start
38 # the service plus assuring it is running on the desired node.
39 # Defaults to <tt>enabled</tt>. The singular form ("service") is used for the
40 # sake of convenience. Of course, the defined status affects all services if
41 # more than one is managed (see <tt>service.pp</tt> to check if this is the
45 # Defaults file content in hash representation
47 # [*init_defaults_file*]
48 # Defaults file as puppet resource
51 # Service file as a template
55 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
57 define elasticsearch::service::init(
58 $ensure = $elasticsearch::ensure,
59 $status = $elasticsearch::status,
60 $init_defaults_file = undef,
61 $init_defaults = undef,
62 $init_template = undef,
65 #### Service management
67 # set params: in operation
68 if $ensure == 'present' {
71 # make sure service is currently running, start it on boot
73 $service_ensure = 'running'
74 $service_enable = true
76 # make sure service is currently stopped, do not start it on boot
78 $service_ensure = 'stopped'
79 $service_enable = false
81 # make sure service is currently running, do not start it on boot
83 $service_ensure = 'running'
84 $service_enable = false
86 # do not start service on boot, do not care whether currently running
89 $service_ensure = undef
90 $service_enable = false
93 # note: don't forget to update the parameter check in init.pp if you
94 # add a new or change an existing status.
96 fail("\"${status}\" is an unknown service status value")
100 # set params: removal
103 # make sure the service is stopped and disabled (the removal itself will be
104 # done by package.pp)
105 $service_ensure = 'stopped'
106 $service_enable = false
110 $notify_service = $elasticsearch::restart_on_change ? {
111 true => Service["elasticsearch-instance-${name}"],
116 if ( $status != 'unmanaged' and $ensure == 'present' ) {
118 # defaults file content. Either from a hash or file
119 if ($init_defaults_file != undef) {
120 file { "${elasticsearch::params::defaults_location}/elasticsearch-${name}":
122 source => $init_defaults_file,
126 before => Service["elasticsearch-instance-${name}"],
127 notify => $notify_service,
130 } elsif ($init_defaults != undef and is_hash($init_defaults) ) {
132 if(has_key($init_defaults, 'ES_USER')) {
133 if($init_defaults['ES_USER'] != $elasticsearch::elasticsearch_user) {
134 fail('Found ES_USER setting for init_defaults but is not same as elasticsearch_user setting. Please use elasticsearch_user setting.')
138 $init_defaults_pre_hash = { 'ES_USER' => $elasticsearch::elasticsearch_user, 'ES_GROUP' => $elasticsearch::elasticsearch_group, 'MAX_OPEN_FILES' => '65535' }
139 $new_init_defaults = merge($init_defaults_pre_hash, $init_defaults)
141 augeas { "defaults_${name}":
142 incl => "${elasticsearch::params::defaults_location}/elasticsearch-${name}",
143 lens => 'Shellvars.lns',
144 changes => template("${module_name}/etc/sysconfig/defaults.erb"),
145 before => Service["elasticsearch-instance-${name}"],
146 notify => $notify_service,
151 # init file from template
152 if ($init_template != undef) {
154 file { "/etc/init.d/elasticsearch-${name}":
156 content => template($init_template),
160 before => Service["elasticsearch-instance-${name}"],
161 notify => $notify_service,
166 } elsif ($status != 'unmanaged') {
168 file { "/etc/init.d/elasticsearch-${name}":
170 subscribe => Service["elasticsearch-instance-${name}"],
173 file { "${elasticsearch::params::defaults_location}/elasticsearch-${name}":
175 subscribe => Service["elasticsearch-${$name}"],
181 if ( $status != 'unmanaged') {
184 service { "elasticsearch-instance-${name}":
185 ensure => $service_ensure,
186 enable => $service_enable,
187 name => "elasticsearch-${name}",
188 hasstatus => $elasticsearch::params::service_hasstatus,
189 hasrestart => $elasticsearch::params::service_hasrestart,
190 pattern => $elasticsearch::params::service_pattern,