Defined Type: restic::service

Defined in:
manifests/service.pp

Summary

Configure a restic service

Overview

Parameters:

  • commands (Any)
  • config (Any)
  • configs (Any)
  • enable (Any)
  • group (Any)
  • user (Any)
  • timer (Any)
  • success_exit_status (Any) (defaults to: undef)


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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'manifests/service.pp', line 6

define restic::service (
  $commands,
  $config,
  $configs,
  $enable,
  $group,
  $user,
  $timer,
  $success_exit_status = undef,
) {
  assert_private()

  if $enable {
    $configs.each |$key,$data| {
      concat::fragment { "restic_fragment_${title}_${key}":
        content => "${key}='${data}'",
        target  => $config,
      }
    }

    $ensure = 'present'
  } else {
    $ensure = 'absent'
  }

  ##
  ## This might seem odd to you, but it's actually thought-out
  ## We use a concat resource for the unit file, because it allows people
  ## to inject pre/post scripts into the restic backup job. This is helpful
  ## if you want to e.g. trigger database backups/cleanups
  ##
  concat { "/lib/systemd/system/${title}.service":
    ensure         => $ensure,
    ensure_newline => true,
    owner          => 'root',
    group          => 'root',
    mode           => '0444',
    show_diff      => true,
  }

  concat::fragment { "/lib/systemd/system/${title}.service-base":
    content => epp("${module_name}/restic.service.epp", { config => $config, group => $group, user => $user, success_exit_status => $success_exit_status }),
    target  => "/lib/systemd/system/${title}.service",
  }

  $commands_template = @(END/L)
  <% $commands.each |$command| { -%>
  ExecStart=<%= $command %>
  <% } -%>
  | END

  concat::fragment { "/lib/systemd/system/${title}.service-commands":
    content => inline_epp($commands_template),
    target  => "/lib/systemd/system/${title}.service",
    order   => '25',
  }

  systemd::unit_file { "${title}.service":
    ensure    => $ensure,
    target    => "/lib/systemd/system/${title}.service",
    group     => 'root',
    mode      => '0440',
    owner     => 'root',
    path      => '/etc/systemd/system',
    show_diff => true,
  }

  $timer_ensure = $timer ? {
    String => $ensure,
    Undef  => 'absent',
  }

  $timer_enable = $timer ? {
    String => $enable,
    Undef  => false,
  }

  $timer_content = $timer ? {
    String => epp("${module_name}/restic.timer.epp", { timer => $timer, }),
    Undef  => undef,
  }

  systemd::timer { "${title}.timer":
    ensure        => $timer_ensure,
    active        => $timer_enable,
    enable        => $timer_enable,
    timer_content => $timer_content,
  }
}