Puppet Class: kafka::mirror::service

Defined in:
manifests/mirror/service.pp

Overview

Class: kafka::mirror::service

This private class is meant to be called from ‘kafka::mirror`. It manages the kafka-mirror service

Parameters:

  • user (String) (defaults to: $kafka::mirror::user)
  • group (String) (defaults to: $kafka::mirror::group)
  • config_dir (Stdlib::Absolutepath) (defaults to: $kafka::mirror::config_dir)
  • log_dir (Stdlib::Absolutepath) (defaults to: $kafka::mirror::log_dir)
  • bin_dir (Stdlib::Absolutepath) (defaults to: $kafka::mirror::bin_dir)
  • service_name (String) (defaults to: $kafka::mirror::service_name)
  • service_install (Boolean) (defaults to: $kafka::mirror::service_install)
  • service_ensure (Enum['running', 'stopped']) (defaults to: $kafka::mirror::service_ensure)
  • service_requires (Array[String]) (defaults to: $kafka::mirror::service_requires)
  • limit_nofile (Optional[String]) (defaults to: $kafka::mirror::limit_nofile)
  • limit_core (Optional[String]) (defaults to: $kafka::mirror::limit_core)
  • env (Hash) (defaults to: $kafka::mirror::env)
  • consumer_config (Hash) (defaults to: $kafka::mirror::consumer_config)
  • producer_config (Hash) (defaults to: $kafka::mirror::producer_config)
  • service_config (Hash) (defaults to: $kafka::mirror::service_config)
  • heap_opts (String) (defaults to: $kafka::mirror::heap_opts)
  • jmx_opts (String) (defaults to: $kafka::mirror::jmx_opts)
  • log4j_opts (String) (defaults to: $kafka::mirror::log4j_opts)


10
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
# File 'manifests/mirror/service.pp', line 10

class kafka::mirror::service(
  String $user                               = $kafka::mirror::user,
  String $group                              = $kafka::mirror::group,
  Stdlib::Absolutepath $config_dir           = $kafka::mirror::config_dir,
  Stdlib::Absolutepath $log_dir              = $kafka::mirror::log_dir,
  Stdlib::Absolutepath $bin_dir              = $kafka::mirror::bin_dir,
  String $service_name                       = $kafka::mirror::service_name,
  Boolean $service_install                   = $kafka::mirror::service_install,
  Enum['running', 'stopped'] $service_ensure = $kafka::mirror::service_ensure,
  Array[String] $service_requires            = $kafka::mirror::service_requires,
  Optional[String] $limit_nofile             = $kafka::mirror::limit_nofile,
  Optional[String] $limit_core               = $kafka::mirror::limit_core,
  Hash $env                                  = $kafka::mirror::env,
  Hash $consumer_config                      = $kafka::mirror::consumer_config,
  Hash $producer_config                      = $kafka::mirror::producer_config,
  Hash $service_config                       = $kafka::mirror::service_config,
  String $heap_opts                          = $kafka::mirror::heap_opts,
  String $jmx_opts                           = $kafka::mirror::jmx_opts,
  String $log4j_opts                         = $kafka::mirror::log4j_opts,
) {

  if $caller_module_name != $module_name {
    fail("Use of private class ${name} by ${caller_module_name}")
  }

  if $service_install {
    $env_defaults = {
      'KAFKA_HEAP_OPTS'  => $heap_opts,
      'KAFKA_JMX_OPTS'   => $jmx_opts,
      'KAFKA_LOG4J_OPTS' => $log4j_opts,
    }
    $environment = deep_merge($env_defaults, $env)

    if $::service_provider == 'systemd' {
      include ::systemd

      file { "/etc/systemd/system/${service_name}.service":
        ensure  => file,
        mode    => '0644',
        content => template('kafka/unit.erb'),
      }

      file { "/etc/init.d/${service_name}":
        ensure => absent,
      }

      File["/etc/systemd/system/${service_name}.service"]
      ~> Exec['systemctl-daemon-reload']
      -> Service[$service_name]

    } else {
      file { "/etc/init.d/${service_name}":
        ensure  => file,
        mode    => '0755',
        content => template('kafka/init.erb'),
        before  => Service[$service_name],
      }
    }

    service { $service_name:
      ensure     => $service_ensure,
      enable     => true,
      hasstatus  => true,
      hasrestart => true,
    }
  }
}