Add systemd module, required by rabbitmq
[mirror/dsa-puppet.git] / 3rdparty / modules / systemd / manifests / unit_file.pp
1 # Creates a systemd unit file
2 #
3 # @api public
4 #
5 # @see systemd.unit(5)
6 #
7 # @attr name [Pattern['^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']]
8 #   The target unit file to create
9 #
10 #   * Must not contain ``/``
11 #
12 # @attr path
13 #   The main systemd configuration path
14 #
15 # @attr content
16 #   The full content of the unit file
17 #
18 #   * Mutually exclusive with ``$source``
19 #
20 # @attr source
21 #   The ``File`` resource compatible ``source``
22 #
23 #   * Mutually exclusive with ``$content``
24 #
25 # @attr target
26 #   If set, will force the file to be a symlink to the given target
27 #
28 #   * Mutually exclusive with both ``$source`` and ``$content``
29 #
30 # @attr enable
31 #   If set, will manage the unit enablement status.
32 #
33 # @attr active
34 #   If set, will manage the state of the unit.
35 #
36 define systemd::unit_file(
37   Enum['present', 'absent', 'file']        $ensure  = 'present',
38   Stdlib::Absolutepath                     $path    = '/etc/systemd/system',
39   Optional[String]                         $content = undef,
40   Optional[String]                         $source  = undef,
41   Optional[Stdlib::Absolutepath]           $target  = undef,
42   Optional[Variant[Boolean, Enum['mask']]] $enable  = undef,
43   Optional[Boolean]                        $active  = undef,
44 ) {
45   include systemd
46
47   assert_type(Systemd::Unit, $name)
48
49   if $target {
50     $_ensure = 'link'
51   } else {
52     $_ensure = $ensure ? {
53       'present' => 'file',
54       default   => $ensure,
55     }
56   }
57
58   file { "${path}/${name}":
59     ensure  => $_ensure,
60     content => $content,
61     source  => $source,
62     target  => $target,
63     owner   => 'root',
64     group   => 'root',
65     mode    => '0444',
66     notify  => Class['systemd::systemctl::daemon_reload'],
67   }
68
69   if $enable != undef or $active != undef {
70     service { $name:
71       ensure    => $active,
72       enable    => $enable,
73       provider  => 'systemd',
74       subscribe => File["${path}/${name}"],
75       require   => Class['systemd::systemctl::daemon_reload'],
76     }
77   }
78 }