Skip to content

Commit

Permalink
Deprecate systemd::service_limits
Browse files Browse the repository at this point in the history
The `systemd::service_limts` and corresponding type
`Systemd::Servicelimits` is deprecated.

Switch to `systemd::dropin_file` for a source attributed
`systemd::service_limits` or `systemd::manage_unit` for a
`limits` attributed `systemd::service_limits`.
  • Loading branch information
traylenator committed Mar 12, 2024
1 parent 63a41e0 commit 8a0e809
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ Finished on controller-0:
}
```

## Deprecate Notices

The type `systemd::service_limits` is deprecated and `systemd::manage_dropin` or `systemd::dropin_file` can
be used instead.

## Transfer Notice

This plugin was originally authored by [Camptocamp](http://www.camptocamp.com).
Expand Down
10 changes: 5 additions & 5 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* [`systemd::manage_unit`](#systemd--manage_unit): Generate unit file from template
* [`systemd::modules_load`](#systemd--modules_load): Creates a modules-load.d drop file
* [`systemd::network`](#systemd--network): Creates network config for systemd-networkd
* [`systemd::service_limits`](#systemd--service_limits): Adds a set of custom limits to the service
* [`systemd::service_limits`](#systemd--service_limits): Deprecate - Adds a set of custom limits to the service
* [`systemd::timer`](#systemd--timer): Create a timer and optionally a service unit to execute with the timer unit
* [`systemd::timer_wrapper`](#systemd--timer_wrapper): Helper to define timer and accompanying services for a given task (cron like interface).
* [`systemd::tmpfile`](#systemd--tmpfile): Creates a systemd tmpfile
Expand All @@ -60,7 +60,7 @@
* [`Systemd::LogindSettings::Ensure`](#Systemd--LogindSettings--Ensure): defines allowed ensure states for systemd-logind settings
* [`Systemd::MachineInfoSettings`](#Systemd--MachineInfoSettings): Matches Systemd machine-info (hostnamectl) file Struct
* [`Systemd::OomdSettings`](#Systemd--OomdSettings): Configurations for oomd.conf
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Matches Systemd Service Limit Struct
* [`Systemd::ServiceLimits`](#Systemd--ServiceLimits): Deprecated - Matches Systemd Service Limit Struct
* [`Systemd::Unit`](#Systemd--Unit): custom datatype that validates different filenames for systemd units and unit templates
* [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes
* [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes
Expand Down Expand Up @@ -1534,7 +1534,7 @@ Default value: `true`

### <a name="systemd--service_limits"></a>`systemd::service_limits`

Adds a set of custom limits to the service
Deprecate - Adds a set of custom limits to the service

* **See also**
* systemd.exec(5)
Expand Down Expand Up @@ -1583,7 +1583,7 @@ Default value: `false`

##### <a name="-systemd--service_limits--limits"></a>`limits`

Data type: `Optional[Systemd::ServiceLimits]`
Data type: `Optional[Systemd::Servicelimits]`

A Hash of service limits matching the settings in ``systemd.exec(5)``

Expand Down Expand Up @@ -2502,7 +2502,7 @@ Struct[{

### <a name="Systemd--ServiceLimits"></a>`Systemd::ServiceLimits`

Matches Systemd Service Limit Struct
Deprecated - Matches Systemd Service Limit Struct

Alias of

Expand Down
56 changes: 45 additions & 11 deletions manifests/service_limits.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Adds a set of custom limits to the service
# Deprecate - Adds a set of custom limits to the service
#
# @api public
#
Expand Down Expand Up @@ -33,7 +33,7 @@
Enum['present', 'absent', 'file'] $ensure = 'present',
Stdlib::Absolutepath $path = '/etc/systemd/system',
Boolean $selinux_ignore_defaults = false,
Optional[Systemd::ServiceLimits] $limits = undef,
Optional[Systemd::Servicelimits] $limits = undef,
Optional[String] $source = undef,
Boolean $restart_service = false,
) {
Expand Down Expand Up @@ -63,14 +63,48 @@
}
}

systemd::dropin_file { "${name}-90-limits.conf":
ensure => $ensure,
unit => $name,
filename => '90-limits.conf',
path => $path,
selinux_ignore_defaults => $selinux_ignore_defaults,
content => $_content,
source => $source,
notify_service => true,
if $limits {

Check failure on line 67 in manifests/service_limits.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or single newline after an opening brace (check: manifest_whitespace_opening_brace_after)
# Some typing changed between Systemd::Servicelimits and Systemd::Unit::Service
$_now_tupled = [
'IODeviceWeight',
'IOReadBandwidthMax',
'IOWriteBandwidthMax',
'IOReadIOPSMax',
'IOWriteIOPSMax',
]

$_my_limits = $limits.map | $_directive, $_value | {
if $_directive in $_now_tupled {
{ $_directive => $_value.map | $_pair | { Array($_pair).flatten } } # Convert { 'a' => 'b' } to ['a', b']

Check failure on line 79 in manifests/service_limits.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or single newline after an opening brace (check: manifest_whitespace_opening_brace_after)
} else {
{ $_directive => $_value }
}
}.reduce | $_memo, $_value | { $_memo + $_value }

deprecation("systemd::servicelimits - ${title}",'systemd::servicelimits is deprecated, user systemd::manage_dropin')
systemd::manage_dropin { '#{name}-90-limits.conf':
ensure => $ensure,
unit => $name,
filename => '90-limits.conf',
path => $path,
selinux_ignore_defaults => $selinux_ignore_defaults,
service_entry => $_my_limits,
notify_service => true,
}

Check failure on line 94 in manifests/service_limits.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or newline before a closing brace (check: manifest_whitespace_closing_brace_before)

} else {

Check failure on line 97 in manifests/service_limits.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or single newline after an opening brace (check: manifest_whitespace_opening_brace_after)
deprecation("systemd::servicelimits ${title}",'systemd::servicelimits is deprecated, user systemd::dropin_file or systemd::manage_dropin')
systemd::dropin_file { '#{name}-90-limits.conf':
ensure => $ensure,
unit => $name,
filename => '90-limits.conf',
path => $path,
selinux_ignore_defaults => $selinux_ignore_defaults,
source => $source,
notify_service => true,
}

Check failure on line 107 in manifests/service_limits.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

there should be a single space or newline before a closing brace (check: manifest_whitespace_closing_brace_before)

}
}
3 changes: 2 additions & 1 deletion types/servicelimits.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Matches Systemd Service Limit Struct
# @summary Deprecated - Matches Systemd Service Limit Struct
#
type Systemd::ServiceLimits = Struct[
{
Optional['LimitCPU'] => Pattern['^\d+(s|m|h|d|w|M|y)?(:\d+(s|m|h|d|w|M|y)?)?$'],
Expand Down

0 comments on commit 8a0e809

Please sign in to comment.