* [PATCH] systemd.bbclass: generate preset for templates
@ 2025-05-28 21:33 Patrick Williams
2025-05-29 17:40 ` Patrick Williams
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Williams @ 2025-05-28 21:33 UTC (permalink / raw)
To: openembedded-core; +Cc: Patrick Williams
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")
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
---
meta/classes-recipe/systemd.bbclass | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index e1fe4ed072..3cc53c44d9 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -224,6 +224,8 @@ python systemd_populate_packages() {
service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else ""))
def systemd_create_presets(pkg, action, user):
+ import re
+
# Check there is at least one service of given type (system/user), don't
# create empty files.
needs_preset = False
@@ -239,10 +241,17 @@ python systemd_populate_packages() {
presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))
bb.utils.mkdirhier(os.path.dirname(presetf))
with open(presetf, 'a') as fd:
+ template_services = {}
for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split():
if not systemd_service_exists(service, user, d):
continue
- fd.write("%s %s\n" % (action,service))
+ if '@' in service:
+ (subservice, instance, service_type) = re.split('[@.]', service)
+ template_services.setdefault(subservice + '@.' + service_type, []).append(instance)
+ else:
+ fd.write("%s %s\n" % (action,service))
+ for template, instances in template_services.items():
+ fd.write("%s %s %s\n" % (action, template, ' '.join(instances)))
d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)))
# Run all modifications once when creating package
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] systemd.bbclass: generate preset for templates
2025-05-28 21:33 [PATCH] systemd.bbclass: generate preset for templates Patrick Williams
@ 2025-05-29 17:40 ` Patrick Williams
0 siblings, 0 replies; 2+ messages in thread
From: Patrick Williams @ 2025-05-29 17:40 UTC (permalink / raw)
To: openembedded-core
[-- Attachment #1: Type: text/plain, Size: 3695 bytes --]
On Wed, May 28, 2025 at 05:33:06PM -0400, Patrick Williams wrote:
> 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")
> Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
> ---
> meta/classes-recipe/systemd.bbclass | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
> index e1fe4ed072..3cc53c44d9 100644
> --- a/meta/classes-recipe/systemd.bbclass
> +++ b/meta/classes-recipe/systemd.bbclass
> @@ -224,6 +224,8 @@ python systemd_populate_packages() {
> service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else ""))
>
> def systemd_create_presets(pkg, action, user):
> + import re
> +
> # Check there is at least one service of given type (system/user), don't
> # create empty files.
> needs_preset = False
> @@ -239,10 +241,17 @@ python systemd_populate_packages() {
> presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg))
> bb.utils.mkdirhier(os.path.dirname(presetf))
> with open(presetf, 'a') as fd:
> + template_services = {}
> for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split():
> if not systemd_service_exists(service, user, d):
> continue
> - fd.write("%s %s\n" % (action,service))
> + if '@' in service:
I somehow sent out an older version of this patch. Will send an update.
If a service is "@.service", this is just a template file, and shouldn't
be added to the instance registration.
> + (subservice, instance, service_type) = re.split('[@.]', service)
> + template_services.setdefault(subservice + '@.' + service_type, []).append(instance)
> + else:
> + fd.write("%s %s\n" % (action,service))
> + for template, instances in template_services.items():
> + fd.write("%s %s %s\n" % (action, template, ' '.join(instances)))
> d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "%s-preset/98-%s.preset" % (prefix, pkg)))
>
> # Run all modifications once when creating package
> --
> 2.49.0
>
--
Patrick Williams
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-29 17:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-28 21:33 [PATCH] systemd.bbclass: generate preset for templates Patrick Williams
2025-05-29 17:40 ` Patrick Williams
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.