diff --git a/manifests/service.pp b/manifests/service.pp index 45a7465..6e46270 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,85 +1,53 @@ # 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. # -# @param ensure -# Controls if the managed resources shall be `present` or `absent`. -# If set to `absent`, the managed software packages will be uninstalled, and -# any traces of the packages will be purged as well as possible, possibly -# including existing configuration files. -# System modifications (if any) will be reverted as well as possible (e.g. -# removal of created users, services, changed log settings, and so on). -# This is a destructive parameter and should be used with care. -# -# @param init_defaults -# Defaults file content in hash representation -# -# @param init_defaults_file -# Defaults file as puppet resource -# -# @param init_template -# Service file as a template -# -# @param service_flags -# Flags to pass to the service. -# -# @param status -# Defines the status of the service. If set to `enabled`, the service is -# started and will be enabled at boot time. If set to `disabled`, the -# service is stopped and will not be started at boot time. If set to `running`, -# the service is started but will not be enabled at boot time. You may use -# this to start a service on the first Puppet run instead of the system startup. -# If set to `unmanaged`, the 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. -# # @author Richard Pijnenburg # @author Tyler Langlois # @author Gavin Williams # class elasticsearch::service { #### Service management if $elasticsearch::ensure == 'present' { case $elasticsearch::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 } default: { } } } else { # make sure the service is stopped and disabled (the removal itself will be # done by package.pp) $_service_ensure = 'stopped' $_service_enable = false } service { $elasticsearch::service_name: ensure => $_service_ensure, enable => $_service_enable, } } diff --git a/manifests/service/init.pp b/manifests/service/init.pp deleted file mode 100644 index 1a03280..0000000 --- a/manifests/service/init.pp +++ /dev/null @@ -1,162 +0,0 @@ -# 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. -# -# @param ensure -# Controls if the managed resources shall be `present` or -# `absent`. If set to `absent`, the managed software packages will being -# uninstalled and any traces of the packages will be purged as well as -# possible. This may include existing configuration files (the exact -# behavior is provider). This is thus destructive and should be used with -# care. -# -# @param init_defaults -# Defaults file content in hash representation -# -# @param init_defaults_file -# Defaults file as puppet resource -# -# @param init_template -# Service file as a template -# -# @param status -# Defines the status of the service. If set to `enabled`, the service is -# started and will be enabled at boot time. If set to `disabled`, the -# service is stopped and will not be started at boot time. If set to `running`, -# the service is started but will not be enabled at boot time. You may use -# this to start a service on the first Puppet run instead of the system startup. -# If set to `unmanaged`, the 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. -# -# @author Richard Pijnenburg -# @author Tyler Langlois -# @author Gavin Williams -# -class elasticsearch::service::init ( - Enum['absent', 'present'] $ensure = $elasticsearch::ensure, - Hash $init_defaults = {}, - Optional[String] $init_defaults_file = undef, - Optional[String] $init_template = undef, - Elasticsearch::Status $status = $elasticsearch::status, -) { - - #### Service management - - 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 - } - default: { } - } - } 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(has_key($init_defaults, 'ES_USER') and $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.') - } - - $new_init_defaults = merge( - { - 'ES_USER' => $elasticsearch::elasticsearch_user, - 'ES_GROUP' => $elasticsearch::elasticsearch_group, - 'MAX_OPEN_FILES' => '65536', - }, - $init_defaults - ) - - $notify_service = $elasticsearch::restart_config_change ? { - true => Service["elasticsearch-instance-${name}"], - false => undef, - } - - if ($ensure == 'present') { - - # Defaults file, either from file source or from hash to augeas commands - if ($init_defaults_file != undef) { - file { "${elasticsearch::defaults_location}/elasticsearch-${name}": - ensure => $ensure, - source => $init_defaults_file, - owner => 'root', - group => '0', - mode => '0644', - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } else { - augeas { "defaults_${name}": - incl => "${elasticsearch::defaults_location}/elasticsearch-${name}", - lens => 'Shellvars.lns', - changes => template("${module_name}/etc/sysconfig/defaults.erb"), - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } - - } else { # absent - - file { "${elasticsearch::defaults_location}/elasticsearch-${name}": - ensure => 'absent', - subscribe => Service["elasticsearch-${$name}"], - } - - } - - # Note that service files are persisted even in the case of absent instances. - # This is to ensure that manifest can remain idempotent and have the service - # file available in order to permit Puppet to introspect system state. - # init file from template - if ($init_template != undef) { - elasticsearch_service_file { "/etc/init.d/elasticsearch-${name}": - ensure => 'present', - content => file($init_template), - instance => $name, - notify => $notify_service, - package_name => $elasticsearch::package_name, - } - -> file { "/etc/init.d/elasticsearch-${name}": - ensure => 'file', - owner => 'root', - group => '0', - mode => '0755', - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } - - service { "elasticsearch-instance-${name}": - ensure => $service_ensure, - enable => $service_enable, - name => "elasticsearch-${name}", - } -} diff --git a/manifests/service/openbsd.pp b/manifests/service/openbsd.pp deleted file mode 100644 index 120953e..0000000 --- a/manifests/service/openbsd.pp +++ /dev/null @@ -1,122 +0,0 @@ -# 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. -# -# @param ensure -# Controls if the managed resources shall be `present` or -# `absent`. If set to `absent`, the managed software packages will being -# uninstalled and any traces of the packages will be purged as well as -# possible. This may include existing configuration files (the exact -# behavior is provider). This is thus destructive and should be used with -# care. -# -# @param init_template -# Service file as a template -# -# @param pid_dir -# Directory where to store the serice pid file. -# -# @param service_flags -# Flags to pass to the service. -# -# @param status -# Defines the status of the service. If set to `enabled`, the service is -# started and will be enabled at boot time. If set to `disabled`, the -# service is stopped and will not be started at boot time. If set to `running`, -# the service is started but will not be enabled at boot time. You may use -# this to start a service on the first Puppet run instead of the system startup. -# If set to `unmanaged`, the 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. -# -# @author Richard Pijnenburg -# @author Tyler Langlois -# @author Gavin Williams -# -class elasticsearch::service::openbsd ( - Enum['absent', 'present'] $ensure = $elasticsearch::ensure, - Optional[String] $init_template = $elasticsearch::init_template, - Optional[String] $pid_dir = $elasticsearch::pid_dir, - Optional[String] $service_flags = undef, - Elasticsearch::Status $status = $elasticsearch::status, -) { - - #### Service management - - 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 - } - default: { } - } - } 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') { - # Note that service files are persisted even in the case of absent instances. - # This is to ensure that manifest can remain idempotent and have the service - # file available in order to permit Puppet to introspect system state. - # init file from template - if ($init_template != undef) { - elasticsearch_service_file { "/etc/rc.d/elasticsearch_${name}": - ensure => 'present', - content => file($init_template), - instance => $name, - pid_dir => $pid_dir, - notify => $notify_service, - package_name => 'elasticsearch', - } - -> file { "/etc/rc.d/elasticsearch_${name}": - ensure => 'file', - owner => 'root', - group => '0', - mode => '0555', - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } - - # action - service { "elasticsearch-instance-${name}": - ensure => $service_ensure, - enable => $service_enable, - name => "elasticsearch_${name}", - flags => $service_flags, - } - } -} diff --git a/manifests/service/openrc.pp b/manifests/service/openrc.pp deleted file mode 100644 index 0c1761c..0000000 --- a/manifests/service/openrc.pp +++ /dev/null @@ -1,167 +0,0 @@ -# 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. -# -# @param ensure -# Controls if the managed resources shall be `present` or -# `absent`. If set to `absent`, the managed software packages will being -# uninstalled and any traces of the packages will be purged as well as -# possible. This may include existing configuration files (the exact -# behavior is provider). This is thus destructive and should be used with -# care. -# -# @param init_defaults -# Defaults file content in hash representation -# -# @param init_defaults_file -# Defaults file as puppet resource -# -# @param init_template -# Service file as a template -# -# @param status -# Defines the status of the service. If set to `enabled`, the service is -# started and will be enabled at boot time. If set to `disabled`, the -# service is stopped and will not be started at boot time. If set to `running`, -# the service is started but will not be enabled at boot time. You may use -# this to start a service on the first Puppet run instead of the system startup. -# If set to `unmanaged`, the 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. -# -# @author Richard Pijnenburg -# @author Tyler Langlois -# @author Gavin Williams -# -class elasticsearch::service::openrc ( - Enum['absent', 'present'] $ensure = $elasticsearch::ensure, - Hash $init_defaults = {}, - Optional[String] $init_defaults_file = undef, - Optional[String] $init_template = undef, - Elasticsearch::Status $status = $elasticsearch::status, -) { - - #### Service management - - 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 - } - default: { } - } - } 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(has_key($init_defaults, 'ES_USER') and $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.') - } - - $new_init_defaults = merge( - { - 'ES_USER' => $elasticsearch::elasticsearch_user, - 'ES_GROUP' => $elasticsearch::elasticsearch_group, - 'MAX_OPEN_FILES' => '65536', - }, - $init_defaults - ) - - $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::defaults_location}/elasticsearch.${name}": - ensure => $ensure, - source => $init_defaults_file, - owner => 'root', - group => '0', - mode => '0644', - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } else { - augeas { "defaults_${name}": - incl => "${elasticsearch::defaults_location}/elasticsearch.${name}", - lens => 'Shellvars.lns', - changes => template("${module_name}/etc/sysconfig/defaults.erb"), - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } - - } elsif ($status != 'unmanaged') { - - file { "${elasticsearch::defaults_location}/elasticsearch.${name}": - ensure => 'absent', - subscribe => Service["elasticsearch.${$name}"], - } - - } - - - if ($status != 'unmanaged') { - # Note that service files are persisted even in the case of absent instances. - # This is to ensure that manifest can remain idempotent and have the service - # file available in order to permit Puppet to introspect system state. - # init file from template - if ($init_template != undef) { - elasticsearch_service_file { "/etc/init.d/elasticsearch.${name}": - ensure => 'present', - content => file($init_template), - instance => $name, - notify => $notify_service, - package_name => 'elasticsearch', - } - -> file { "/etc/init.d/elasticsearch.${name}": - ensure => 'file', - owner => 'root', - group => '0', - mode => '0755', - before => Service["elasticsearch-instance-${name}"], - notify => $notify_service, - } - } - - # action - service { "elasticsearch-instance-${name}": - ensure => $service_ensure, - enable => $service_enable, - name => "elasticsearch.${name}", - } - } -} diff --git a/manifests/service/systemd.pp b/manifests/service/systemd.pp deleted file mode 100644 index d7fdfb5..0000000 --- a/manifests/service/systemd.pp +++ /dev/null @@ -1,195 +0,0 @@ -# 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. -# -# @param ensure -# Controls if the managed resources shall be `present` or -# `absent`. If set to `absent`, the managed software packages will being -# uninstalled and any traces of the packages will be purged as well as -# possible. This may include existing configuration files (the exact -# behavior is provider). This is thus destructive and should be used with -# care. -# -# @param init_defaults -# Defaults file content in hash representation -# -# @param init_defaults_file -# Defaults file as puppet resource -# -# @param init_template -# Service file as a template -# -# @param status -# Defines the status of the service. If set to `enabled`, the service is -# started and will be enabled at boot time. If set to `disabled`, the -# service is stopped and will not be started at boot time. If set to `running`, -# the service is started but will not be enabled at boot time. You may use -# this to start a service on the first Puppet run instead of the system startup. -# If set to `unmanaged`, the 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. -# -# @author Richard Pijnenburg -# @author Tyler Langlois -# @author Gavin Williams -# -class elasticsearch::service::systemd ( - Enum['absent', 'present'] $ensure = $elasticsearch::ensure, - Hash $init_defaults = {}, - Optional[String] $init_defaults_file = undef, - Optional[String] $init_template = undef, - Elasticsearch::Status $status = $elasticsearch::status, -) { - - #### Service management - - 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 - } - default: { } - } - } 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(has_key($init_defaults, 'ES_USER') and $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.') - } - - $new_init_defaults = merge( - { - 'ES_USER' => $elasticsearch::elasticsearch_user, - 'ES_GROUP' => $elasticsearch::elasticsearch_group, - 'MAX_OPEN_FILES' => '65536', - 'MAX_THREADS' => '4096', - }, - $init_defaults - ) - - $_notify_service = $elasticsearch::restart_config_change ? { - true => [ Exec["systemd_reload_${name}"], Service["elasticsearch-instance-${name}"] ], - false => Exec["systemd_reload_${name}"] - } - - if ($ensure == 'present') { - - # Defaults file, either from file source or from hash to augeas commands - if ($init_defaults_file != undef) { - file { "${elasticsearch::defaults_location}/elasticsearch-${name}": - ensure => $ensure, - source => $init_defaults_file, - owner => 'root', - group => '0', - mode => '0644', - before => Service["elasticsearch-instance-${name}"], - notify => $_notify_service, - } - } else { - augeas { "defaults_${name}": - incl => "${elasticsearch::defaults_location}/elasticsearch-${name}", - lens => 'Shellvars.lns', - changes => template("${module_name}/etc/sysconfig/defaults.erb"), - before => Service["elasticsearch-instance-${name}"], - notify => $_notify_service, - } - } - - $_service_require = Exec["systemd_reload_${name}"] - - } else { # absent - - file { "${elasticsearch::defaults_location}/elasticsearch-${name}": - ensure => 'absent', - subscribe => Service["elasticsearch-instance-${name}"], - notify => Exec["systemd_reload_${name}"], - } - - $_service_require = undef - } - - exec { "systemd_reload_${name}": - command => '/bin/systemctl daemon-reload', - refreshonly => true, - } - - # init file from template - if ($init_template != undef) { - # Check for values in init defaults we may want to set in the init template - if (has_key($new_init_defaults, 'MAX_OPEN_FILES')) { - $nofile = $new_init_defaults['MAX_OPEN_FILES'] - } else { - $nofile = '65536' - } - - if (has_key($new_init_defaults, 'MAX_LOCKED_MEMORY')) { - $memlock = $new_init_defaults['MAX_LOCKED_MEMORY'] - } else { - $memlock = undef - } - - if (has_key($new_init_defaults, 'MAX_THREADS')) { - $nproc = $new_init_defaults['MAX_THREADS'] - } else { - $nproc = '4096' - } - - # elasticsearch_service_file { "${elasticsearch::systemd_service_path}/elasticsearch-${name}.service": - # ensure => 'present', - # content => file($init_template), - # defaults_location => $elasticsearch::defaults_location, - # group => $elasticsearch::elasticsearch_group, - # homedir => $elasticsearch::homedir, - # instance => $name, - # memlock => $memlock, - # nofile => $nofile, - # nproc => $nproc, - # package_name => 'elasticsearch', - # pid_dir => $elasticsearch::pid_dir, - # user => $elasticsearch::elasticsearch_user, - # notify => $_notify_service, - # } - # -> file { "${elasticsearch::systemd_service_path}/elasticsearch-${name}.service": - # ensure => 'file', - # owner => 'root', - # group => 'root', - # mode => '0644', - # before => Service["elasticsearch-instance-${name}"], - # notify => $_notify_service, - # } - } - - service { $elasticsearch::service_name: - ensure => $_service_ensure, - enable => $_service_enable, - provider => 'systemd', - require => $_service_require, - } -}