Puppet Class: otelcol::service

Defined in:
manifests/service.pp

Summary

Manages the Otelcol service

Overview

Examples:

Make sure Otelcol is running

include 'otelcol::service'

Disable otelcol service

class { 'otelcol::service':
  ensure => stopped,
}

Parameters:

  • ensure (Stdlib::Ensure::Service) (defaults to: $otelcol::service_ensure)

    Ensure service status

  • enable (Boolean) (defaults to: $otelcol::service_enable)

    Enable service on boot

  • config_check_command (Optional[String]) (defaults to: undef)
  • config_check (Boolean) (defaults to: $otelcol::service_configcheck)


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

class otelcol::service (
  Stdlib::Ensure::Service $ensure            = $otelcol::service_ensure,
  Boolean $enable                            = $otelcol::service_enable,
  Optional[String] $config_check_command     = undef,
  Boolean $config_check                      = $otelcol::service_configcheck,
) {
  # include install
  include otelcol::install

  if $config_check {
    if $config_check_command {
      $_config_check_command = $config_check_command
    } else {
      $_config_check_command = case $facts['os']['family'] {
        'windows': { "${otelcol::service_name}.exe validate --config=\"${otelcol::config_file}\"" }
        default: { "${otelcol::service_name} validate --config=\"${otelcol::config_file}\"" }
      }
    }

    exec { 'otelcol_config_check':
      command     => $_config_check_command,
      refreshonly => true,
      path        => [
        '/usr/local/sbin',
        '/usr/local/bin',
        '/usr/sbin',
        '/usr/bin',
        '/sbin',
        '/bin',
        '%PROGRAMFILES%\\OpenTelemetry Collector',
        'C:/Program Files/OpenTelemetry Collector',
      ],
    }
  }

  $service_require = $config_check ? {
    true => [Exec['otelcol_config_check'], Package['otelcol']],
    false => Package['otelcol'],
  }

  service { 'otelcol':
    ensure    => $ensure,
    enable    => $enable,
    name      => $otelcol::service_name,
    require   => $service_require,
    subscribe => [Concat['otelcol-config']],
  }
}