1 # Adds a set of custom limits to the service
7 # @attr name [Pattern['^.+\.(service|socket|mount|swap)$']]
8 # The name of the service that you will be modifying
11 # Whether to drop a file or remove it
14 # The path to the main systemd settings directory
17 # A Hash of service limits matching the settings in ``systemd.exec(5)``
19 # * Mutually exclusive with ``$source``
22 # A ``File`` resource compatible ``source``
24 # * Mutually exclusive with ``$limits``
26 # @param restart_service
27 # Restart the managed service after setting the limits
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
39 if $name !~ Pattern['^.+\.(service|socket|mount|swap)$'] {
40 fail('$name must match Pattern["^.+\.(service|socket|mount|swap)$"]')
43 if $limits and !empty($limits) {
44 $_content = template("${module_name}/limits.erb")
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')
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')
59 systemd::dropin_file { "${name}-90-limits.conf":
62 filename => '90-limits.conf',
69 exec { "restart ${name} because limits":
70 command => "systemctl restart ${name}",
73 subscribe => File["${path}/${name}.d/90-limits.conf"],
74 require => Class['systemd::systemctl::daemon_reload'],