Skip to content

Commit

Permalink
Allow percent (%) character in unit names.
Browse files Browse the repository at this point in the history
This allows relations to be set up between similar instances of
two templated units.

For example:

```puppet
systemd::manage_dropin{'user-aklog.conf':
  ensure     => present,
  unit       => '[email protected]',
  unit_entry => {
    'Documentation' => 'Run an aklog log before we start systemd --user',
    'After'         => ['user-aklog@%i.service'],
    'Requires'      => ['user-aklog@%i.service'],
  },
}
```

Previously the `%` character was considered illegal in a unit name.
  • Loading branch information
traylenator committed Dec 14, 2023
1 parent 9ab215d commit b80a8ea
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
14 changes: 13 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,18 @@ systemd::manage_dropin { 'maxloglevel.conf':
}
```

##### have a unit instance auto run before user-<uid>.service

```puppet
systemd::manage_dropin { 'user-aklog.conf':
unit => '[email protected]',
unit_entry => {
'After' => 'user-aklog@%i.service',
'Requires' => 'user-aklog@%i.service'
}
}
```

#### Parameters

The following parameters are available in the `systemd::manage_dropin` defined type:
Expand Down Expand Up @@ -2289,7 +2301,7 @@ custom datatype that validates different filenames for systemd units and unit te
* **See also**
* https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]`
Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]`

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

Expand Down
9 changes: 9 additions & 0 deletions manifests/manage_dropin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
# }
# }
#
# @example have a unit instance auto run before user-<uid>.service
# systemd::manage_dropin { 'user-aklog.conf':
# unit => '[email protected]',
# unit_entry => {
# 'After' => 'user-aklog@%i.service',
# 'Requires' => 'user-aklog@%i.service'
# }
# }
#
# @param unit The unit to create a dropfile for
# @param filename The target unit file to create. The filename of the drop in. The full path is determined using the path, unit and this filename.
# @param ensure The state of this dropin file
Expand Down
17 changes: 17 additions & 0 deletions spec/defines/manage_dropin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@
}
end

context 'with an instance to instance relation' do
let(:params) do
super().merge(
unit_entry: {
'After' => ['user-runtime-dir@%i.service'],
'Requires' => ['user-runtime-dir@%i.service'],
}
)
end

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^After=user-runtime-dir@%i.service$}).
with_content(%r{^Requires=user-runtime-dir@%i.service$})
}
end

context 'with a timer entry' do
let(:params) do
super().merge(
Expand Down
1 change: 1 addition & 0 deletions spec/type_aliases/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'extra.dot.scope',
'a:colon.path',
'an_underscore.device',
'a_referenced_template_instance@%i.service',
'a-dash.slice',
].each do |unit|
it { is_expected.to allow_value(unit.to_s) }
Expand Down
2 changes: 1 addition & 1 deletion types/unit.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @summary custom datatype that validates different filenames for systemd units and unit templates
# @see https://www.freedesktop.org/software/systemd/man/systemd.unit.html
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]

0 comments on commit b80a8ea

Please sign in to comment.