Revert "Add puppet/archive module"
[mirror/dsa-puppet.git] / 3rdparty / modules / systemd / manifests / service_limits.pp
1 # Adds a set of custom limits to the service
2 #
3 # @api public
4 #
5 # @see systemd.exec(5)
6 #
7 # @attr name [Pattern['^.+\.(service|socket|mount|swap)$']]
8 #   The name of the service that you will be modifying
9 #
10 # @param $ensure
11 #   Whether to drop a file or remove it
12 #
13 # @param path
14 #   The path to the main systemd settings directory
15 #
16 # @param limits
17 #   A Hash of service limits matching the settings in ``systemd.exec(5)``
18 #
19 #   * Mutually exclusive with ``$source``
20 #
21 # @param source
22 #   A ``File`` resource compatible ``source``
23 #
24 #  * Mutually exclusive with ``$limits``
25 #
26 # @param restart_service
27 #   Restart the managed service after setting the limits
28 #
29 define systemd::service_limits(
30   Enum['present', 'absent', 'file'] $ensure          = 'present',
31   Stdlib::Absolutepath              $path            = '/etc/systemd/system',
32   Optional[Systemd::ServiceLimits]  $limits          = undef,
33   Optional[String]                  $source          = undef,
34   Boolean                           $restart_service = true
35 ) {
36
37   include systemd
38
39   if $name !~ Pattern['^.+\.(service|socket|mount|swap)$'] {
40     fail('$name must match Pattern["^.+\.(service|socket|mount|swap)$"]')
41   }
42
43   if $limits and !empty($limits) {
44     $_content = template("${module_name}/limits.erb")
45   }
46   else {
47     $_content = undef
48   }
49
50   if $ensure != 'absent' {
51     if ($limits and !empty($limits)) and $source {
52       fail('You may not supply both limits and source parameters to systemd::service_limits')
53     }
54     elsif ($limits == undef or empty($limits)) and ($source == undef) {
55       fail('You must supply either the limits or source parameter to systemd::service_limits')
56     }
57   }
58
59   systemd::dropin_file { "${name}-90-limits.conf":
60     ensure   => $ensure,
61     unit     => $name,
62     filename => '90-limits.conf',
63     path     => $path,
64     content  => $_content,
65     source   => $source,
66   }
67
68   if $restart_service {
69     exec { "restart ${name} because limits":
70       command     => "systemctl restart ${name}",
71       path        => $::path,
72       refreshonly => true,
73       subscribe   => File["${path}/${name}.d/90-limits.conf"],
74       require     => Class['systemd::systemctl::daemon_reload'],
75     }
76   }
77 }