Puppet Class: puppet::agent::service::systemd

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

Overview

Set up running the agent via a systemd timer

Parameters:

  • enabled (Boolean) (defaults to: false)
  • hour (Optional[Integer[0,23]]) (defaults to: undef)
  • minute (Optional[Integer[0,59]]) (defaults to: undef)


3
4
5
6
7
8
9
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
# File 'manifests/agent/service/systemd.pp', line 3

class puppet::agent::service::systemd (
  Boolean                 $enabled = false,
  Optional[Integer[0,23]] $hour    = undef,
  Optional[Integer[0,59]] $minute  = undef,
) {
  unless $puppet::runmode == 'unmanaged' or 'systemd.timer' in $puppet::unavailable_runmodes {
    exec { 'systemctl-daemon-reload-puppet':
      refreshonly => true,
      path        => $::path,
      command     => 'systemctl daemon-reload',
    }

    if $enabled {
      # Use the same times as for cron
      $times = extlib::ip_to_cron($puppet::runinterval)

      # But only if they are not explicitly specified
      $_hour = pick($hour, $times[0])
      $_minute = pick($minute, $times[1])

      $command = $puppet::systemd_cmd ? {
        undef   => "${puppet::puppet_cmd} agent --config ${puppet::dir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure",
        default => $puppet::systemd_cmd,
      }

      $randomizeddelaysec = $puppet::systemd_randomizeddelaysec

      file { "/etc/systemd/system/${puppet::systemd_unit_name}.timer":
        content => template('puppet/agent/systemd.puppet-run.timer.erb'),
        notify  => [
          Exec['systemctl-daemon-reload-puppet'],
          Service['puppet-run.timer'],
        ],
      }

      file { "/etc/systemd/system/${puppet::systemd_unit_name}.service":
        content => template('puppet/agent/systemd.puppet-run.service.erb'),
        notify  => Exec['systemctl-daemon-reload-puppet'],
      }

      service { 'puppet-run.timer':
        ensure   => running,
        provider => 'systemd',
        name     => "${puppet::systemd_unit_name}.timer",
        enable   => true,
        require  => Exec['systemctl-daemon-reload-puppet'],
      }
    } else {
      # Reverse order - stop, delete files, exec
      service { 'puppet-run.timer':
        ensure   => stopped,
        provider => 'systemd',
        name     => "${puppet::systemd_unit_name}.timer",
        enable   => false,
        before   => [
          File["/etc/systemd/system/${puppet::systemd_unit_name}.timer"],
          File["/etc/systemd/system/${puppet::systemd_unit_name}.service"],
        ],
      }

      file { "/etc/systemd/system/${puppet::systemd_unit_name}.timer":
        ensure => absent,
        notify => Exec['systemctl-daemon-reload-puppet'],
      }

      file { "/etc/systemd/system/${puppet::systemd_unit_name}.service":
        ensure => absent,
        notify => Exec['systemctl-daemon-reload-puppet'],
      }
    }
  }
}