public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH v3 0/8] Systemd user presets support
@ 2025-01-20 12:45 Artur Kowalski
  2025-01-20 12:45 ` [PATCH v3 1/8] systemd-systemctl: add support for --global flag Artur Kowalski
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:45 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski, Alex Kiernan, Alexander Kanavin

This is v3 of the series. I renamed the `glob` variable to `opt_global` in
the first commit. With this last change in place the series are ready
for testing.

Artur Kowalski (8):
  systemd-systemctl: add support for --global flag
  systemd.bbclass: add ${sysconfdir}/systemd/user to search path
  systemd.bbclass: factor out service lookup logic into separate
    function
  systemd.bbclass: introduce systemd_service_searchpaths()
  systemd.bbclass: properly handle user units in systemd_create_presets
  systemd.bbclass: update postinst and prerm hooks
  systemd.bbclass: support user units in postinst and prerm hooks
  image.bbclass: enable systemd user services

 meta/classes-recipe/image.bbclass             |   1 +
 meta/classes-recipe/systemd.bbclass           | 118 +++++++++++++-----
 .../systemd/systemd-systemctl/systemctl       |  42 ++++---
 3 files changed, 112 insertions(+), 49 deletions(-)

-- 
2.47.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/8] systemd-systemctl: add support for --global flag
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
@ 2025-01-20 12:45 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path Artur Kowalski
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:45 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

The flag is similar to --user flag as it causes systemctl to operate on
user units, but it performs operations globally for all users. This is
required for user presets support.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 .../systemd/systemd-systemctl/systemctl       | 42 ++++++++++---------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 2229bc7b6d..81c246a5b2 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -29,15 +29,15 @@ class SystemdFile():
 
     _clearable_keys = ['WantedBy']
 
-    def __init__(self, root, path, instance_unit_name):
+    def __init__(self, root, path, instance_unit_name, unit_type):
         self.sections = dict()
         self._parse(root, path)
         dirname = os.path.basename(path.name) + ".d"
         for location in locations:
-            files = (root / location / "system" / dirname).glob("*.conf")
+            files = (root / location / unit_type / dirname).glob("*.conf")
             if instance_unit_name:
                 inst_dirname = instance_unit_name + ".d"
-                files = chain(files, (root / location / "system" / inst_dirname).glob("*.conf"))
+                files = chain(files, (root / location / unit_type / inst_dirname).glob("*.conf"))
             for path2 in sorted(files):
                 self._parse(root, path2)
 
@@ -182,21 +182,22 @@ class SystemdUnitNotFoundError(Exception):
 
 
 class SystemdUnit():
-    def __init__(self, root, unit):
+    def __init__(self, root, unit, unit_type):
         self.root = root
         self.unit = unit
+        self.unit_type = unit_type
         self.config = None
 
     def _path_for_unit(self, unit):
         for location in locations:
-            path = self.root / location / "system" / unit
+            path = self.root / location / self.unit_type / unit
             if path.exists() or path.is_symlink():
                 return path
 
         raise SystemdUnitNotFoundError(self.root, unit)
 
     def _process_deps(self, config, service, location, prop, dirstem, instance):
-        systemdir = self.root / SYSCONFDIR / "systemd" / "system"
+        systemdir = self.root / SYSCONFDIR / "systemd" / self.unit_type
 
         target = ROOT / location.relative_to(self.root)
         try:
@@ -229,7 +230,7 @@ class SystemdUnit():
             # ignore aliases
             return
 
-        config = SystemdFile(self.root, path, instance_unit_name)
+        config = SystemdFile(self.root, path, instance_unit_name, self.unit_type)
         if instance == "":
             try:
                 default_instance = config.get('Install', 'DefaultInstance')[0]
@@ -250,14 +251,14 @@ class SystemdUnit():
                 try:
                      units_enabled.append(unit)
                      if also not in units_enabled:
-                        SystemdUnit(self.root, also).enable(units_enabled)
+                        SystemdUnit(self.root, also, self.unit_type).enable(units_enabled)
                 except SystemdUnitNotFoundError as e:
                     sys.exit("Error: Systemctl also enable issue with  %s (%s)" % (service, e.unit))
 
         except KeyError:
             pass
 
-        systemdir = self.root / SYSCONFDIR / "systemd" / "system"
+        systemdir = self.root / SYSCONFDIR / "systemd" / self.unit_type
         target = ROOT / path.relative_to(self.root)
         try:
             for dest in config.get('Install', 'Alias'):
@@ -268,15 +269,15 @@ class SystemdUnit():
             pass
 
     def mask(self):
-        systemdir = self.root / SYSCONFDIR / "systemd" / "system"
+        systemdir = self.root / SYSCONFDIR / "systemd" / self.unit_type
         add_link(systemdir / self.unit, "/dev/null")
 
 
-def collect_services(root):
+def collect_services(root, unit_type):
     """Collect list of service files"""
     services = set()
     for location in locations:
-        paths = (root / location / "system").glob("*")
+        paths = (root / location / unit_type).glob("*")
         for path in paths:
             if path.is_dir():
                 continue
@@ -285,16 +286,16 @@ def collect_services(root):
     return services
 
 
-def preset_all(root):
-    presets = Presets('system-preset', root)
-    services = collect_services(root)
+def preset_all(root, unit_type):
+    presets = Presets('{}-preset'.format(unit_type), root)
+    services = collect_services(root, unit_type)
 
     for service in services:
         state = presets.state(service)
 
         if state == "enable" or state is None:
             try:
-                SystemdUnit(root, service).enable()
+                SystemdUnit(root, service, unit_type).enable()
             except SystemdUnitNotFoundError:
                 sys.exit("Error: Systemctl preset_all issue in %s" % service)
 
@@ -320,6 +321,7 @@ def main():
     parser.add_argument('--preset-mode',
                         choices=['full', 'enable-only', 'disable-only'],
                         default='full')
+    parser.add_argument('--global', dest="opt_global", action="store_true", default=False)
 
     args = parser.parse_args()
 
@@ -336,16 +338,18 @@ def main():
         parser.print_help()
         return 0
 
+    unit_type = "user" if args.opt_global else "system"
+
     if command == "mask":
         for service in args.service:
             try:
-                SystemdUnit(root, service).mask()
+                SystemdUnit(root, service, unit_type).mask()
             except SystemdUnitNotFoundError as e:
                 sys.exit("Error: Systemctl main mask issue in %s (%s)" % (service, e.unit))
     elif command == "enable":
         for service in args.service:
             try:
-                SystemdUnit(root, service).enable()
+                SystemdUnit(root, service, unit_type).enable()
             except SystemdUnitNotFoundError as e:
                 sys.exit("Error: Systemctl main enable issue in %s (%s)" % (service, e.unit))
     elif command == "preset-all":
@@ -353,7 +357,7 @@ def main():
             sys.exit("Too many arguments.")
         if args.preset_mode != "enable-only":
             sys.exit("Only enable-only is supported as preset-mode.")
-        preset_all(root)
+        preset_all(root, unit_type)
     else:
         raise RuntimeError()
 
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
  2025-01-20 12:45 ` [PATCH v3 1/8] systemd-systemctl: add support for --global flag Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 3/8] systemd.bbclass: factor out service lookup logic into separate function Artur Kowalski
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

We already search for system units ${sysconfdir}/systemd/system but we
don't search for user units in corresponding directory under ${sysconfdir}.
Keep the behaviour consistent so that both unit types are searched in
${systemd_{system,user}_unitdir} and ${sysconfdir}/systemd/{system,user}.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/systemd.bbclass | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 4b4470b7b3..c167689d2a 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -147,7 +147,10 @@ python systemd_populate_packages() {
 
     # Check service-files and call systemd_add_files_and_parse for each entry
     def systemd_check_services():
-        searchpaths = [oe.path.join(d.getVar("sysconfdir"), "systemd", "system"),]
+        searchpaths = [
+            oe.path.join(d.getVar("sysconfdir"), "systemd", "system"),
+            oe.path.join(d.getVar("sysconfdir"), "systemd", "user"),
+        ]
         searchpaths.append(d.getVar("systemd_system_unitdir"))
         searchpaths.append(d.getVar("systemd_user_unitdir"))
         systemd_packages = d.getVar('SYSTEMD_PACKAGES')
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/8] systemd.bbclass: factor out service lookup logic into separate function
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
  2025-01-20 12:45 ` [PATCH v3 1/8] systemd-systemctl: add support for --global flag Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 4/8] systemd.bbclass: introduce systemd_service_searchpaths() Artur Kowalski
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

Factor out the logic into systemd_service_path(). This will be needed by
following commits to avoid code duplication.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/systemd.bbclass | 41 ++++++++++++++++-------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index c167689d2a..14fef2d7a6 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -68,6 +68,28 @@ systemd_populate_packages[vardeps] += "systemd_prerm systemd_postinst"
 systemd_populate_packages[vardepsexclude] += "OVERRIDES"
 
 
+def systemd_service_path(service, searchpaths, d):
+    path_found = ''
+
+    # Deal with adding, for example, 'ifplugd@eth0.service' from
+    # 'ifplugd@.service'
+    base = None
+    at = service.find('@')
+    if at != -1:
+        ext = service.rfind('.')
+        base = service[:at] + '@' + service[ext:]
+
+    for path in searchpaths:
+        if os.path.lexists(oe.path.join(d.getVar("D"), path, service)):
+            path_found = path
+            break
+        elif base is not None:
+            if os.path.exists(oe.path.join(d.getVar("D"), path, base)):
+                path_found = path
+                break
+
+    return path_found, base
+
 python systemd_populate_packages() {
     import re
     import shlex
@@ -158,24 +180,7 @@ python systemd_populate_packages() {
         # scan for all in SYSTEMD_SERVICE[]
         for pkg_systemd in systemd_packages.split():
             for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split():
-                path_found = ''
-
-                # Deal with adding, for example, 'ifplugd@eth0.service' from
-                # 'ifplugd@.service'
-                base = None
-                at = service.find('@')
-                if at != -1:
-                    ext = service.rfind('.')
-                    base = service[:at] + '@' + service[ext:]
-
-                for path in searchpaths:
-                    if os.path.lexists(oe.path.join(d.getVar("D"), path, service)):
-                        path_found = path
-                        break
-                    elif base is not None:
-                        if os.path.exists(oe.path.join(d.getVar("D"), path, base)):
-                            path_found = path
-                            break
+                path_found, base = systemd_service_path(service, searchpaths, d)
 
                 if path_found != '':
                     systemd_add_files_and_parse(pkg_systemd, path_found, service)
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/8] systemd.bbclass: introduce systemd_service_searchpaths()
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
                   ` (2 preceding siblings ...)
  2025-01-20 12:46 ` [PATCH v3 3/8] systemd.bbclass: factor out service lookup logic into separate function Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 5/8] systemd.bbclass: properly handle user units in systemd_create_presets Artur Kowalski
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

systemd_service_searchpaths accepts boolean value indicating whether we
are dealing with system or user units and returns search paths
accordingly.

Previously search path list was created in systemd_check_services() but
following commits will introduce additional places. The
systemd_service_searchpaths helper function is meant to reduce code
duplication.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/systemd.bbclass | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 14fef2d7a6..a3c2c6eb20 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -90,6 +90,18 @@ def systemd_service_path(service, searchpaths, d):
 
     return path_found, base
 
+def systemd_service_searchpaths(user, d):
+    if user:
+        return [
+            oe.path.join(d.getVar("sysconfdir"), "systemd", "user"),
+            d.getVar("systemd_user_unitdir"),
+        ]
+    else:
+        return [
+            oe.path.join(d.getVar("sysconfdir"), "systemd", "system"),
+            d.getVar("systemd_system_unitdir"),
+        ]
+
 python systemd_populate_packages() {
     import re
     import shlex
@@ -169,12 +181,9 @@ python systemd_populate_packages() {
 
     # Check service-files and call systemd_add_files_and_parse for each entry
     def systemd_check_services():
-        searchpaths = [
-            oe.path.join(d.getVar("sysconfdir"), "systemd", "system"),
-            oe.path.join(d.getVar("sysconfdir"), "systemd", "user"),
-        ]
-        searchpaths.append(d.getVar("systemd_system_unitdir"))
-        searchpaths.append(d.getVar("systemd_user_unitdir"))
+        searchpaths = systemd_service_searchpaths(False, d)
+        searchpaths.extend(systemd_service_searchpaths(True, d))
+
         systemd_packages = d.getVar('SYSTEMD_PACKAGES')
 
         # scan for all in SYSTEMD_SERVICE[]
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 5/8] systemd.bbclass: properly handle user units in systemd_create_presets
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
                   ` (3 preceding siblings ...)
  2025-01-20 12:46 ` [PATCH v3 4/8] systemd.bbclass: introduce systemd_service_searchpaths() Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 6/8] systemd.bbclass: update postinst and prerm hooks Artur Kowalski
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

Previously user units were handled the same way as system units, that
is all preset files were created in system-preset directory, but user
presets should be in user-preset directory.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/systemd.bbclass | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index a3c2c6eb20..592f15a4b7 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -102,6 +102,12 @@ def systemd_service_searchpaths(user, d):
             d.getVar("systemd_system_unitdir"),
         ]
 
+def systemd_service_exists(service, user, d):
+    searchpaths = systemd_service_searchpaths(user, d)
+    path, _ = systemd_service_path(service, searchpaths, d)
+
+    return path != ''
+
 python systemd_populate_packages() {
     import re
     import shlex
@@ -197,13 +203,27 @@ python systemd_populate_packages() {
                     bb.fatal("Didn't find service unit '{0}', specified in SYSTEMD_SERVICE:{1}. {2}".format(
                         service, pkg_systemd, "Also looked for service unit '{0}'.".format(base) if base is not None else ""))
 
-    def systemd_create_presets(pkg, action):
-        presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir"), "system-preset/98-%s.preset" % pkg)
+    def systemd_create_presets(pkg, action, user):
+        # Check there is at least one service of given type (system/user), don't
+        # create empty files.
+        needs_preset = False
+        for service in d.getVar('SYSTEMD_SERVICE:%s' % pkg).split():
+            if systemd_service_exists(service, user, d):
+                needs_preset = True
+                break
+
+        if not needs_preset:
+            return
+
+        prefix = "user" if user else "system"
+        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:
             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))
-        d.appendVar("FILES:%s" % pkg, ' ' + oe.path.join(d.getVar("systemd_unitdir"), "system-preset/98-%s.preset" % pkg))
+        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
     if os.path.exists(d.getVar("D")):
@@ -213,7 +233,8 @@ python systemd_populate_packages() {
                 systemd_generate_package_scripts(pkg)
                 action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg)
                 if action in ("enable", "disable"):
-                    systemd_create_presets(pkg, action)
+                    systemd_create_presets(pkg, action, False)
+                    systemd_create_presets(pkg, action, True)
                 elif action not in ("mask", "preset"):
                     bb.fatal("SYSTEMD_AUTO_ENABLE:%s '%s' is not 'enable', 'disable', 'mask' or 'preset'" % (pkg, action))
         systemd_check_services()
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 6/8] systemd.bbclass: update postinst and prerm hooks
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
                   ` (4 preceding siblings ...)
  2025-01-20 12:46 ` [PATCH v3 5/8] systemd.bbclass: properly handle user units in systemd_create_presets Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 7/8] systemd.bbclass: support user units in " Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 8/8] image.bbclass: enable systemd user services Artur Kowalski
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

Since SYSTEMD_SERVICE_ESCAPED may contain both system and user services
we need to filter out user services in call to systemctl. Introduce
helper systemd_filter_services() which takes space-separated list of
services and returns services of requested type.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/systemd.bbclass | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 592f15a4b7..177ee5d974 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -37,17 +37,19 @@ if systemctl >/dev/null 2>/dev/null; then
 	fi
 
 	if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
-		for service in ${SYSTEMD_SERVICE_ESCAPED}; do
+		for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do
 			systemctl ${OPTS} enable "$service"
 		done
 	fi
 
 	if [ -z "$D" ]; then
 		systemctl daemon-reload
-		systemctl preset ${SYSTEMD_SERVICE_ESCAPED}
+		[ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \
+			systemctl preset ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 
 		if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
-			systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED}
+			[ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \
+				systemctl --no-block restart ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 		fi
 	fi
 fi
@@ -56,9 +58,10 @@ fi
 systemd_prerm() {
 if systemctl >/dev/null 2>/dev/null; then
 	if [ -z "$D" ]; then
-		systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
-
-		systemctl disable ${SYSTEMD_SERVICE_ESCAPED}
+		if [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ]; then
+			systemctl stop ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
+			systemctl disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
+		fi
 	fi
 fi
 }
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 7/8] systemd.bbclass: support user units in postinst and prerm hooks
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
                   ` (5 preceding siblings ...)
  2025-01-20 12:46 ` [PATCH v3 6/8] systemd.bbclass: update postinst and prerm hooks Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-20 12:46 ` [PATCH v3 8/8] image.bbclass: enable systemd user services Artur Kowalski
  7 siblings, 0 replies; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

Handle user units in a manner similar to system units where possible.
Not everything is supported by systemd, but systemd limitations only
affect runtime package management - during update user services are not
reloaded/restart and each user must re-login or manually restart
services.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/systemd.bbclass | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 177ee5d974..4c9f51d33d 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -40,14 +40,24 @@ if systemctl >/dev/null 2>/dev/null; then
 		for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do
 			systemctl ${OPTS} enable "$service"
 		done
+
+		for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}; do
+			systemctl --global ${OPTS} enable "$service"
+		done
 	fi
 
 	if [ -z "$D" ]; then
+		# Reload only system service manager
+		# --global for daemon-reload is not supported: https://github.com/systemd/systemd/issues/19284
 		systemctl daemon-reload
 		[ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \
 			systemctl preset ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 
+		[ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}" ] && \
+			systemctl --global preset ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}
+
 		if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
+			# --global flag for restart is not supported by systemd (see above)
 			[ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ] && \
 				systemctl --no-block restart ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 		fi
@@ -62,6 +72,10 @@ if systemctl >/dev/null 2>/dev/null; then
 			systemctl stop ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 			systemctl disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 		fi
+
+		# same as above, --global flag is not supported for stop so do disable only
+		[ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}" ] && \
+			systemctl --global disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}
 	fi
 fi
 }
@@ -111,6 +125,9 @@ def systemd_service_exists(service, user, d):
 
     return path != ''
 
+def systemd_filter_services(services, user, d):
+    return ' '.join(service for service in services.split() if systemd_service_exists(service, user, d))
+
 python systemd_populate_packages() {
     import re
     import shlex
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 8/8] image.bbclass: enable systemd user services
  2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
                   ` (6 preceding siblings ...)
  2025-01-20 12:46 ` [PATCH v3 7/8] systemd.bbclass: support user units in " Artur Kowalski
@ 2025-01-20 12:46 ` Artur Kowalski
  2025-01-24 12:51   ` [OE-core] " Markus Volk
  7 siblings, 1 reply; 12+ messages in thread
From: Artur Kowalski @ 2025-01-20 12:46 UTC (permalink / raw)
  To: openembedded-core; +Cc: Artur Kowalski

Run systemctl preset-all with --global flag so user unit's are enabled
the same way system units are.

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
---
 meta/classes-recipe/image.bbclass | 1 +
 1 file changed, 1 insertion(+)

diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass
index 84a2017eb5..f08818db03 100644
--- a/meta/classes-recipe/image.bbclass
+++ b/meta/classes-recipe/image.bbclass
@@ -702,6 +702,7 @@ reproducible_final_image_task () {
 systemd_preset_all () {
     if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then
 	systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all
+	systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only preset-all
     fi
 }
 
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [OE-core] [PATCH v3 8/8] image.bbclass: enable systemd user services
  2025-01-20 12:46 ` [PATCH v3 8/8] image.bbclass: enable systemd user services Artur Kowalski
@ 2025-01-24 12:51   ` Markus Volk
  2025-01-24 18:24     ` Artur Kowalski
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Volk @ 2025-01-24 12:51 UTC (permalink / raw)
  To: arturkow2000; +Cc: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 1999 bytes --]

With this patch applied I see an error in image creation after 
do_rootfs if gnome-shell is installed:

| Error: Systemctl preset_all issue in org.gnome.Shell@wayland.service
| WARNING: 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/temp/run.systemd_preset_all.2011511:158 
exit 1 from 'systemctl 
--root="/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs" 
--global --preset-mode=enable-only preset-all'



On Mon, Jan 20 2025 at 13:46:06 +01:00:00, Artur Kowalski via 
lists.openembedded.org <arturkow2000=gmail.com@lists.openembedded.org> 
wrote:
> Run systemctl preset-all with --global flag so user unit's are enabled
> the same way system units are.
> 
> Signed-off-by: Artur Kowalski <arturkow2000@gmail.com 
> <mailto:arturkow2000@gmail.com>>
> ---
>  meta/classes-recipe/image.bbclass | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/meta/classes-recipe/image.bbclass 
> b/meta/classes-recipe/image.bbclass
> index 84a2017eb5..f08818db03 100644
> --- a/meta/classes-recipe/image.bbclass
> +++ b/meta/classes-recipe/image.bbclass
> @@ -702,6 +702,7 @@ reproducible_final_image_task () {
>  systemd_preset_all () {
>      if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then
>  	systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only 
> preset-all
> +	systemctl --root="${IMAGE_ROOTFS}" --global 
> --preset-mode=enable-only preset-all
>      fi
>  }
> 
> --
> 2.47.1
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#210039): 
> <https://lists.openembedded.org/g/openembedded-core/message/210039>
> Mute This Topic: <https://lists.openembedded.org/mt/110714552/3618223>
> Group Owner: openembedded-core+owner@lists.openembedded.org 
> <mailto:openembedded-core+owner@lists.openembedded.org>
> Unsubscribe: 
> <https://lists.openembedded.org/g/openembedded-core/unsub> 
> [f_l_k@t-online.de <mailto:f_l_k@t-online.de>]
> -=-=-=-=-=-=-=-=-=-=-=-
> 


[-- Attachment #2: Type: text/html, Size: 2506 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [OE-core] [PATCH v3 8/8] image.bbclass: enable systemd user services
  2025-01-24 12:51   ` [OE-core] " Markus Volk
@ 2025-01-24 18:24     ` Artur Kowalski
  2025-01-24 21:24       ` Markus Volk
  0 siblings, 1 reply; 12+ messages in thread
From: Artur Kowalski @ 2025-01-24 18:24 UTC (permalink / raw)
  To: Markus Volk; +Cc: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 1575 bytes --]

Can you provide your `log.do_image` file? I will try to reproduce this 
locally too.


W dniu 24.01.2025 o 13:51, Markus Volk pisze:
> With this patch applied I see an error in image creation after 
> do_rootfs if gnome-shell is installed:
>
> | Error: Systemctl preset_all issue in org.gnome.Shell@wayland.service
> | WARNING: 
> /home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/temp/run.systemd_preset_all.2011511:158 
> exit 1 from 'systemctl 
> --root="/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs" 
> --global --preset-mode=enable-only preset-all'
>
>
>
> On Mon, Jan 20 2025 at 13:46:06 +01:00:00, Artur Kowalski via 
> lists.openembedded.org <arturkow2000=gmail.com@lists.openembedded.org> 
> wrote:
>> Run systemctl preset-all with --global flag so user unit's are 
>> enabled the same way system units are. Signed-off-by: Artur Kowalski 
>> <arturkow2000@gmail.com> --- meta/classes-recipe/image.bbclass | 1 + 
>> 1 file changed, 1 insertion(+) diff --git 
>> a/meta/classes-recipe/image.bbclass 
>> b/meta/classes-recipe/image.bbclass index 84a2017eb5..f08818db03 
>> 100644 --- a/meta/classes-recipe/image.bbclass +++ 
>> b/meta/classes-recipe/image.bbclass @@ -702,6 +702,7 @@ 
>> reproducible_final_image_task () { systemd_preset_all () { if [ -e 
>> ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then systemctl 
>> --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all + 
>> systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only 
>> preset-all fi }
>> -- 
>> 2.47.1
>> 

[-- Attachment #2: Type: text/html, Size: 2805 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [OE-core] [PATCH v3 8/8] image.bbclass: enable systemd user services
  2025-01-24 18:24     ` Artur Kowalski
@ 2025-01-24 21:24       ` Markus Volk
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Volk @ 2025-01-24 21:24 UTC (permalink / raw)
  To: Artur Kowalski; +Cc: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 7032 bytes --]

DEBUG: Executing python function do_image
NOTE: Executing systemd_preset_all ...
DEBUG: Executing shell function systemd_preset_all
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/recipe-sysroot-native/usr/bin/systemctl:222: 
DeprecationWarning: 'count' is passed as positional argument
  unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
ln -s /usr/lib/systemd/system/systemd-boot-update.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/sysinit.target.wants/systemd-boot-update.service
ln -s /usr/lib/systemd/system/remote-cryptsetup.target 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/multi-user.target.wants/remote-cryptsetup.target
ln -s /usr/lib/systemd/system/systemd-resolved.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/sysinit.target.wants/systemd-resolved.service
ln -s /usr/lib/systemd/system/systemd-resolved.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/dbus-org.freedesktop.resolve1.service
ln -s /usr/lib/systemd/system/remote-fs.target 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/multi-user.target.wants/remote-fs.target
ln -s /usr/lib/systemd/system/reboot.target 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/ctrl-alt-del.target
ln -s /usr/lib/systemd/system/getty@.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/getty.target.wants/getty@tty1.service
ln -s /usr/lib/systemd/system/systemd-journald-audit.socket 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/sockets.target.wants/systemd-journald-audit.socket
ln -s /usr/lib/systemd/system/systemd-journald-audit.socket 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/systemd-journald.service.wants/systemd-journald-audit.socket
ln -s /usr/lib/systemd/system/systemd-userdbd.socket 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/system/sockets.target.wants/systemd-userdbd.socket
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/recipe-sysroot-native/usr/bin/systemctl:222: 
DeprecationWarning: 'count' is passed as positional argument
  unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
ln -s 
/usr/lib/systemd/user/xdg-desktop-portal-rewrite-launchers.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/user/graphical-session-pre.target.wants/xdg-desktop-portal-rewrite-launchers.service
ln -s /usr/lib/systemd/user/localsearch-3.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/user/gnome-session.target.wants/localsearch-3.service
ln -s /usr/lib/systemd/user/gnome-keyring-daemon.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/user/default.target.wants/gnome-keyring-daemon.service
ln -s /usr/lib/systemd/user/gnome-keyring-daemon.socket 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/user/sockets.target.wants/gnome-keyring-daemon.socket
ln -s /usr/lib/systemd/user/pipewire-pulse.service 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/user/default.target.wants/pipewire-pulse.service
ln -s /usr/lib/systemd/user/pipewire-pulse.socket 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs/etc/systemd/user/sockets.target.wants/pipewire-pulse.socket
Error: Systemctl preset_all issue in org.gnome.Shell@wayland.service
WARNING: 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/temp/run.systemd_preset_all.16269:158 
exit 1 from 'systemctl 
--root="/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs" 
--global --preset-mode=enable-only preset-all'
WARNING: Backtrace (BB generated script):
	#1: systemd_preset_all, 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/temp/run.systemd_preset_all.16269, 
line 158
	#2: main, 
/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/temp/run.systemd_preset_all.16269, 
line 162
DEBUG: Python function do_image finished

This is all there is in log.do_image

On Fri, Jan 24 2025 at 19:24:52 +01:00:00, Artur Kowalski 
<arturkow2000@gmail.com> wrote:
> Can you provide your `log.do_image` file? I will try to reproduce 
> this locally too.
> 
> 
> W dniu 24.01.2025 o 13:51, Markus Volk pisze:
>> With this patch applied I see an error in image creation after 
>> do_rootfs if gnome-shell is installed:
>> 
>> | Error: Systemctl preset_all issue in 
>> org.gnome.Shell@wayland.service 
>> <mailto:org.gnome.Shell@wayland.service>
>> | WARNING: 
>> /home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/temp/run.systemd_preset_all.2011511:158 
>> exit 1 from 'systemctl 
>> --root="/home/flk/poky/build/tmp/work/intel_corei7_64-poky-linux/gnome-image/1.0/rootfs" 
>> --global --preset-mode=enable-only preset-all'
>> 
>> 
>> 
>>  On Mon, Jan 20 2025 at 13:46:06 +01:00:00, Artur Kowalski via 
>> lists.openembedded.org 
>> <arturkow2000=gmail.com@lists.openembedded.org> 
>> <mailto:arturkow2000=gmail.com@lists.openembedded.org> wrote:
>>> Run systemctl preset-all with --global flag so user unit's are 
>>> enabled
>>> the same way system units are.
>>> 
>>> Signed-off-by: Artur Kowalski <arturkow2000@gmail.com 
>>> <mailto:arturkow2000@gmail.com>>
>>> ---
>>>  meta/classes-recipe/image.bbclass | 1 +
>>>  1 file changed, 1 insertion(+)
>>> 
>>> diff --git a/meta/classes-recipe/image.bbclass 
>>> b/meta/classes-recipe/image.bbclass
>>> index 84a2017eb5..f08818db03 100644
>>> --- a/meta/classes-recipe/image.bbclass
>>> +++ b/meta/classes-recipe/image.bbclass
>>> @@ -702,6 +702,7 @@ reproducible_final_image_task () {
>>>  systemd_preset_all () {
>>>      if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; 
>>> then
>>>  	systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only 
>>> preset-all
>>> +	systemctl --root="${IMAGE_ROOTFS}" --global 
>>> --preset-mode=enable-only preset-all
>>>      fi
>>>  }
>>> 
>>> --
>>> 2.47.1
>>> 
>>> 
>>> -=-=-=-=-=-=-=-=-=-=-=-
>>> Links: You receive all messages sent to this group.
>>> View/Reply Online (#210039): 
>>> <https://lists.openembedded.org/g/openembedded-core/message/210039>
>>> Mute This Topic: 
>>> <https://lists.openembedded.org/mt/110714552/3618223>
>>> Group Owner: openembedded-core+owner@lists.openembedded.org 
>>> <mailto:openembedded-core+owner@lists.openembedded.org>
>>> Unsubscribe: 
>>> <https://lists.openembedded.org/g/openembedded-core/unsub> 
>>> [f_l_k@t-online.de <mailto:f_l_k@t-online.de>]
>>> -=-=-=-=-=-=-=-=-=-=-=-
>>> 


[-- Attachment #2: Type: text/html, Size: 9016 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-01-24 21:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 12:45 [PATCH v3 0/8] Systemd user presets support Artur Kowalski
2025-01-20 12:45 ` [PATCH v3 1/8] systemd-systemctl: add support for --global flag Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 2/8] systemd.bbclass: add ${sysconfdir}/systemd/user to search path Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 3/8] systemd.bbclass: factor out service lookup logic into separate function Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 4/8] systemd.bbclass: introduce systemd_service_searchpaths() Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 5/8] systemd.bbclass: properly handle user units in systemd_create_presets Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 6/8] systemd.bbclass: update postinst and prerm hooks Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 7/8] systemd.bbclass: support user units in " Artur Kowalski
2025-01-20 12:46 ` [PATCH v3 8/8] image.bbclass: enable systemd user services Artur Kowalski
2025-01-24 12:51   ` [OE-core] " Markus Volk
2025-01-24 18:24     ` Artur Kowalski
2025-01-24 21:24       ` Markus Volk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox