Defined Type: systemd::service

Defined in:
modules/systemd/manifests/service.pp

Summary

Manages a systemd-based unit as a puppet service, properly handling:

Overview

  • the unit file

  • the puppet service definition and state

Parameters:

  • unit_type (Systemd::Unit::Type) (defaults to: 'service')

    The unit type we are defining as a service

  • content (String)

    The content of the file.

  • ensure (Wmflib::Ensure) (defaults to: 'present')

    The usual meta-parameter, defaults to present.

  • restart (Boolean) (defaults to: false)

    Whether to handle restarting the service when the file changes.

  • override (Boolean) (defaults to: false)

    If the are creating an override to system-provided units or not.

  • override_filename (Optional[String[1]]) (defaults to: undef)

    When creating an override, filename to use instead of the one forged by systemd::unit.

  • monitoring_enabled (Boolean) (defaults to: false)

    Periodically check the last execution of the unit and alarm if it ended up in a failed state.

  • monitoring_contact_group (String) (defaults to: 'admins')

    The monitoring's contact group to send the alarm to.

  • monitoring_notes_url (Optional[Stdlib::HTTPUrl]) (defaults to: undef)

    The notes url used to resolve issues, if monitoring_enabled is true this is required

  • monitoring_critical (Boolean) (defaults to: false)

    If monitoring is enabled allows paging if the execution of the unit ended up in a failed state.

  • team (Optional[Wmflib::Team]) (defaults to: undef)

    The team which owns this service

  • service_params (Hash) (defaults to: {})

    Additional service parameters we want to specify



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
77
78
# File 'modules/systemd/manifests/service.pp', line 21

define systemd::service (
    String $content,
    Wmflib::Ensure            $ensure                   = 'present',
    Systemd::Unit::Type       $unit_type                = 'service',
    Boolean                   $restart                  = false,
    Boolean                   $override                 = false,
    Optional[String[1]]       $override_filename        = undef,
    Boolean                   $monitoring_enabled       = false,
    String                    $monitoring_contact_group = 'admins',
    Optional[Stdlib::HTTPUrl] $monitoring_notes_url     = undef,
    Boolean                   $monitoring_critical      = false,
    Optional[Wmflib::Team]    $team                     = undef,
    Hash                      $service_params           = {},
) {
    if $unit_type == 'service' {
        $label = $title
        $provider = undef
    } else {
        # Use a fully specified label for the unit.
        $label = "${title}.${unit_type}"
        # Force the provider of the service to be systemd if the unit type is
        # not service.
        $provider = 'systemd'
    }

    $enable = $ensure ? {
        'present' => true,
        default   => false,
    }

    $base_params = {
        ensure   => stdlib::ensure($ensure, 'service'),
        enable   => $enable,
        provider => $provider,
    }
    $params = merge($base_params, $service_params)
    ensure_resource('service', $label, $params)

    systemd::unit { $label:
        ensure            => $ensure,
        content           => $content,
        override          => $override,
        override_filename => $override_filename,
        restart           => $restart,
        team              => $team,
    }
    if $monitoring_enabled {
        unless $monitoring_notes_url {
            fail('Must provide $monitoring_notes_url if $monitoring_enabled')
        }
        systemd::monitor { $title:
            ensure        => $ensure,
            notes_url     => $monitoring_notes_url,
            contact_group => $monitoring_contact_group,
            critical      => $monitoring_critical,
        }
    }
}