diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2025-05-29 13:44:27 -0400 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-06-02 22:17:24 +0100 |
| commit | e47d08d330cf16712dc2f03001871dfbd88bf8e7 (patch) | |
| tree | 5c857305644c8bd3f45e45f98c903f7b269c2002 | |
| parent | 303a4e377c6ecaae11b04021ea36b159352ea4df (diff) | |
| download | poky-e47d08d330cf16712dc2f03001871dfbd88bf8e7.tar.gz | |
systemd.bbclass: generate preset for templates
There was a regression introduced by the change to use
systemd-systemctl-native rather than a python fake implementation,
which caused template units to not be properly enabled when set in
the SYSTEMD_SERVICE variable. Through investigation, it seems that
the best way to re-enable template instances is to handle them
explicitly in the systemd.bbclass and enable them with `preset`, like
most units are handled[1,2].
Per the systemd.preset manpage, the format for template units is
different than for regular units[3]. We need to coalesce all the
template instances onto a single line and emit them as an additional
space-deliminated argument.
Ran this against openbmc's phosphor-ipmi-net recipe and generated
the following preset file:
```
$ cat packages-split/phosphor-ipmi-net/usr/lib/systemd/system-preset/98-phosphor-ipmi-net.preset
enable phosphor-ipmi-net@.service eth0
enable phosphor-ipmi-net@.socket eth0
```
[1]: https://lore.kernel.org/openembedded-core/Z2ch.1747051947055246176.oktf@lists.openembedded.org/
[2]: https://lore.kernel.org/openembedded-core/aDdoTVtCmElpURYD@heinlein/
[3]: https://www.freedesktop.org/software/systemd/man/latest/systemd.preset.html
Fixes: 7a580800db39 ("systemd: Build the systemctl executable")
(From OE-Core rev: f33d9b1f434e40a459614d8dc21ce45e11581008)
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/classes-recipe/systemd.bbclass | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 4c9f51d33d..12c59647be 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass | |||
| @@ -224,6 +224,8 @@ python systemd_populate_packages() { | |||
| 224 | service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else "")) | 224 | service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else "")) |
| 225 | 225 | ||
| 226 | def systemd_create_presets(pkg, action, user): | 226 | def systemd_create_presets(pkg, action, user): |
| 227 | import re | ||
| 228 | |||
| 227 | # Check there is at least one service of given type (system/user), don't | 229 | # Check there is at least one service of given type (system/user), don't |
| 228 | # create empty files. | 230 | # create empty files. |
| 229 | needs_preset = False | 231 | needs_preset = False |
| @@ -239,10 +241,17 @@ python systemd_populate_packages() { | |||
| 239 | presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)) | 241 | presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)) |
| 240 | bb.utils.mkdirhier(os.path.dirname(presetf)) | 242 | bb.utils.mkdirhier(os.path.dirname(presetf)) |
| 241 | with open(presetf, 'a') as fd: | 243 | with open(presetf, 'a') as fd: |
| 244 | template_services = {} | ||
| 242 | for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split(): | 245 | for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split(): |
| 243 | if not systemd_service_exists(service, user, d): | 246 | if not systemd_service_exists(service, user, d): |
| 244 | continue | 247 | continue |
| 245 | fd.write("%s %s\n" % (action,service)) | 248 | if '@' in service and '@.' not in service: |
| 249 | (servicename, instance, service_type) = re.split('[@.]', service) | ||
| 250 | template_services.setdefault(servicename + '@.' + service_type, []).append(instance) | ||
| 251 | else: | ||
| 252 | fd.write("%s %s\n" % (action,service)) | ||
| 253 | for template, instances in template_services.items(): | ||
| 254 | fd.write("%s %s %s\n" % (action, template, ' '.join(instances))) | ||
| 246 | d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))) | 255 | d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))) |
| 247 | 256 | ||
| 248 | # Run all modifications once when creating package | 257 | # Run all modifications once when creating package |
