Skip to content

Commit b80a8ea

Browse files
committed
Allow percent (%) character in unit names.
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 => 'user@.service', 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.
1 parent 9ab215d commit b80a8ea

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

REFERENCE.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,18 @@ systemd::manage_dropin { 'maxloglevel.conf':
837837
}
838838
```
839839

840+
##### have a unit instance auto run before user-<uid>.service
841+
842+
```puppet
843+
systemd::manage_dropin { 'user-aklog.conf':
844+
unit => 'user@.service',
845+
unit_entry => {
846+
'After' => 'user-aklog@%i.service',
847+
'Requires' => 'user-aklog@%i.service'
848+
}
849+
}
850+
```
851+
840852
#### Parameters
841853

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

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

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

manifests/manage_dropin.pp

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
# }
4242
# }
4343
#
44+
# @example have a unit instance auto run before user-<uid>.service
45+
# systemd::manage_dropin { 'user-aklog.conf':
46+
# unit => 'user@.service',
47+
# unit_entry => {
48+
# 'After' => 'user-aklog@%i.service',
49+
# 'Requires' => 'user-aklog@%i.service'
50+
# }
51+
# }
52+
#
4453
# @param unit The unit to create a dropfile for
4554
# @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.
4655
# @param ensure The state of this dropin file

spec/defines/manage_dropin_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@
6464
}
6565
end
6666

67+
context 'with an instance to instance relation' do
68+
let(:params) do
69+
super().merge(
70+
unit_entry: {
71+
'After' => ['user-runtime-dir@%i.service'],
72+
'Requires' => ['user-runtime-dir@%i.service'],
73+
}
74+
)
75+
end
76+
77+
it {
78+
is_expected.to contain_systemd__dropin_file('foobar.conf').
79+
with_content(%r{^After=user-runtime-dir@%i.service$}).
80+
with_content(%r{^Requires=user-runtime-dir@%i.service$})
81+
}
82+
end
83+
6784
context 'with a timer entry' do
6885
let(:params) do
6986
super().merge(

spec/type_aliases/unit_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'extra.dot.scope',
1414
'a:colon.path',
1515
'an_underscore.device',
16+
'a_referenced_template_instance@%i.service',
1617
'a-dash.slice',
1718
].each do |unit|
1819
it { is_expected.to allow_value(unit.to_s) }

types/unit.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# @summary custom datatype that validates different filenames for systemd units and unit templates
22
# @see https://www.freedesktop.org/software/systemd/man/systemd.unit.html
3-
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]
3+
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]

0 commit comments

Comments
 (0)