From patchwork Sun Jan 12 14:31:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2BA3E7719F for ; Sun, 12 Jan 2025 14:40:33 +0000 (UTC) Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by mx.groups.io with SMTP id smtpd.web11.36893.1736692498207531798 for ; Sun, 12 Jan 2025 06:34:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jkhChtx/; spf=pass (domain: gmail.com, ip: 209.85.208.49, mailfrom: arturkow2000@gmail.com) Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d3f28a4fccso4984698a12.2 for ; Sun, 12 Jan 2025 06:34:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736692496; x=1737297296; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wRFHxfKTMh/ajsdRUV48QHvGrdnwOumqPeJZY1VuhUM=; b=jkhChtx/ICkjeC9PSuMHiWuOjwwvFJLLaV98pnO0jdsgx8Ch06ADSz4dkZYz6XTuNa ytKA8lGwdbY10e9yqNuUANxt1Nj9uzdp0xHUnR5d3IzyEOdvoy7qfP8wrJOJ76CE3fT1 Lkxd8L8yylXglvjh8XiVhiYDaG+MSrW+Q4kgMZUPG0yeSmAVnTh5erObEdEqafUK7gXZ 0on8HjfLBqgbNYqe4yoHwtaHPh8Gxf3IMdAAB1iUrImkVyWQg8+Ku8Pw7Y0OYqbjjF7k PJS6/7M6uw/BZevGdNDEv+yVsZKQlfvEEX0+Zl6p56A3jc2XtoKTVDcv87Y39YEZcCoL wfGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736692496; x=1737297296; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wRFHxfKTMh/ajsdRUV48QHvGrdnwOumqPeJZY1VuhUM=; b=FfxifmmsCOiGVjLsUaMGFInFkGevRTIhLDeJvy51Viy4HvgKcShVnv1AHvyLem3Ze3 9UBuXGjJndF5Rw2EX21lFyQGPUdwbPPol4dCJVAnzzbyljEhsJhmZCOV9t2uLLaHdhuB L+agZ/IIkjRZ8AP3aCbCr8AkbdVlkzPotG9cSKwgpePyx2pirC/18RU756V5SqZfTUDf rLU0LZBcJT3ofIhSWpn0VgcIq1KyD2jTA0DzwqZQrxam1vxesWlcK+4yKG2UaNRNU3C1 MFihY1fJpN/XIIE7Uhdk6XTWN1BnLFNU9Udz6OP3Axrn0uKnaE4s7uuceC7SCaWNEjaI BJPg== X-Gm-Message-State: AOJu0YxvGwPcu30oP0HruziQio0ZgCalWZDHXPww5A/pk+YP5msRr8dD 30Ta1ceOD5zHiaRUve9SMNpzmfzgAZjzinwWg7vYaibnzLrlhwHbWbvgWQ== X-Gm-Gg: ASbGnctap41Ma7Bfj9c1LAgI/Vpo/c8Vy0x1zItzkQ3i6mTDK0XCnAj926ge6+f4ziE 9sXeQEL+dwwOkIf/YOndIOwxmWfZi/tn3PcKUF7Ar1BtSYFziF1LMiUs96Ss7b1JTWbvRWZWgd9 MZoEcro1vvkveeUTpT+/pj+XwoEZUPiPF5L3wRDeRFVsq+e7m6J+z7IkrW8rl736jTscPff/v6V KMmE/6ERlXzRp5cjbNMXC99X7JluB5dqPfD6xeOwInUsxFWG5sVuqBJpED0JzHs X-Google-Smtp-Source: AGHT+IGkSZQvo8UfDQVu+ydmk9UMz8SRVvrZPcBqyUm8l6mYgqlKv0062FA6edoaTDxEpEaWcNyu4A== X-Received: by 2002:a05:6402:401d:b0:5d0:c9e6:30bc with SMTP id 4fb4d7f45d1cf-5d972e06c2emr15766111a12.10.1736692495957; Sun, 12 Jan 2025 06:34:55 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:dec6:9e22:e5fb:f0d5]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d99d05bec4sm3207739a12.14.2025.01.12.06.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 06:34:55 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH 1/3] systemd-systemctl: add support for --global flag Date: Sun, 12 Jan 2025 15:31:39 +0100 Message-ID: <20250112143141.1300189-2-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250112143141.1300189-1-arturkow2000@gmail.com> References: <20250112143141.1300189-1-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sun, 12 Jan 2025 14:40:33 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209686 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 to for user presets support. Signed-off-by: Artur Kowalski --- .../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..9b8fe81459 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="glob", 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.glob 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() From patchwork Sun Jan 12 14:31:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0F5FE7719C for ; Sun, 12 Jan 2025 14:40:33 +0000 (UTC) Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by mx.groups.io with SMTP id smtpd.web10.36620.1736692499515932187 for ; Sun, 12 Jan 2025 06:34:59 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=j54/fBI2; spf=pass (domain: gmail.com, ip: 209.85.208.47, mailfrom: arturkow2000@gmail.com) Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d3e8f64d5dso6733332a12.3 for ; Sun, 12 Jan 2025 06:34:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736692497; x=1737297297; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XWsN5zIfL084OB2rcs87AqX0oiiorNISdvb7uMWAESY=; b=j54/fBI2QPjK0oAq3QWfzcDOxQ+w71h5dvlhGLxGWgzTQWCIloovJ80YQXMiY/Ys+n Yj9vWPmlEoVgARpqd/cJtfqNUHiWcrryY2pb3mD1iZ3O9JQunIaQ2x5nV0tCqQfEmCYg b9Qixq7WOfChVCEHOFXkf0rVvNfBwJMGcCqKsE9LKE6PFcp+KcIl2Ffv0goQuXLcczLj urbvRhIg3Znp3LHnv0+gQieHkZh+Ei2ob2sweGLa+uJ6YqNB17b4kmlJjhST+vwsM4Wy nleIbfxPtU4nXbfxheD8Z+ox2pn4sYwKti8aJOjRmK/NiFSXyTOLZ8vgtCe7paq/Tl6I 8mlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736692497; x=1737297297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XWsN5zIfL084OB2rcs87AqX0oiiorNISdvb7uMWAESY=; b=usOafFniwVN30xUkn/thtLkVSFWZUrP1BQJ0G2ZF6m5eB+/wgX9SbY3exI4JYEIpFT gdL4qNP2PG5Bz5OjT/yrgk8MeHgW/zLfEhDvfFyjrcwA2RSblAjFQWiE9u1Etn3DhO5T QRgdj8tqSiXq59+pKRmeawbzNGSXRH9VQdvIdbI+UIytKKX4a86GUIFCV02DtrddMBmW oC+WylU6J7WrvARHBhRwDv97L+UefuBoG0xAH3lyAgc9cnbMI5KCmfr08BKDua74o6Ko zpBzFNPjFSpE76t4cgxqCOdoxXawCVrNMr2m0Kvh4D3uAI3lXjI40T4EkK+3Un8bD97I 4QkQ== X-Gm-Message-State: AOJu0Yw56uVRJs8cy9FArdUDjKWeAyr960pHrVJI6ITHnN/xZPNnZnt6 YM0qQIZUPHxgVj4XW/h/cMvK72PETW/CPkQj5DnFnFcmPQbeCv8ZD7fE3w== X-Gm-Gg: ASbGnctB7t+9pN5IeTUYwbjADBqpXxUcDHV/NsXh8x1TVajPWz9ESHMv8qIeldDN/I9 AMAsaGPGno4bvSVEMLI4BALid7hFb2GdwanHtc544En1jBJdmRBpZ9PYB5wm6ugfzpzCxmibERa vr9rsgHzpR4ht0uhT9oXpYxqbnLtlvKo440b8zQpRbOqmZ2Su9W7wi2OtuTgo1+ejYPmia8mqYW hXdcwnVChnm2VMjeWQeOnfYIetKkRDXHpjgMA/IioS4tG6kI08KPbSXLsMgW9Qk X-Google-Smtp-Source: AGHT+IGapDBnnEn102Gw3pR3taPL3WHiN18L/oY+WcYWDQ5XahuwRqWyCE3m03kyRRfidODy4m3lLA== X-Received: by 2002:a05:6402:2815:b0:5d3:d8bb:3c5c with SMTP id 4fb4d7f45d1cf-5d972e095dfmr14839707a12.12.1736692497260; Sun, 12 Jan 2025 06:34:57 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:dec6:9e22:e5fb:f0d5]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d99d05bec4sm3207739a12.14.2025.01.12.06.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 06:34:56 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH 2/3] systemd.bbclass: add support for user presets Date: Sun, 12 Jan 2025 15:31:40 +0100 Message-ID: <20250112143141.1300189-3-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250112143141.1300189-1-arturkow2000@gmail.com> References: <20250112143141.1300189-1-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sun, 12 Jan 2025 14:40:33 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209687 Previously user units were causing build erros when listed in SYSTEMD_SERVICE and SYSTEMD_AUTO_ENABLE was set. Signed-off-by: Artur Kowalski --- meta/classes-recipe/systemd.bbclass | 120 +++++++++++++++++++++------- 1 file changed, 93 insertions(+), 27 deletions(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 4b4470b7b3..80f4da3bdf 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -37,17 +37,29 @@ 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 + + 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 - systemctl preset ${SYSTEMD_SERVICE_ESCAPED} + [ -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 - systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED} + # --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 fi fi @@ -56,9 +68,14 @@ fi systemd_prerm() { if systemctl >/dev/null 2>/dev/null; then if [ -z "$D" ]; then - systemctl stop ${SYSTEMD_SERVICE_ESCAPED} + # same as above, --global flag is not supported for stop + 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 - systemctl disable ${SYSTEMD_SERVICE_ESCAPED} + [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}" ] && \ + systemctl --global disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)} fi fi } @@ -67,6 +84,44 @@ fi 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 + +def systemd_service_exists(service, user, d): + searchpaths = [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "user"), + d.getVar("systemd_user_unitdir"), + ] if user else [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "system"), + d.getVar("systemd_system_unitdir"), + ] + + path, _ = systemd_service_path(service, searchpaths, 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 @@ -147,7 +202,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') @@ -155,24 +213,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) @@ -180,13 +221,38 @@ 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, prefix, searchpaths): + # 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(): + path_found, _ = systemd_service_path(service, searchpaths, d) + if path_found != '': + needs_preset = True + break + + if not needs_preset: + return + + 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(): + path_found, _ = systemd_service_path(service, searchpaths, d) + if path_found == '': + 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))) + + def systemd_create_presets(pkg, action): + _systemd_create_presets(pkg, action, "system", [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "system"), + d.getVar("systemd_system_unitdir"), + ]) + _systemd_create_presets(pkg, action, "user", [ + oe.path.join(d.getVar("sysconfdir"), "systemd", "user"), + d.getVar("systemd_user_unitdir"), + ]) # Run all modifications once when creating package if os.path.exists(d.getVar("D")): From patchwork Sun Jan 12 14:31:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Kowalski X-Patchwork-Id: 55394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBACEE7719E for ; Sun, 12 Jan 2025 14:40:33 +0000 (UTC) Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by mx.groups.io with SMTP id smtpd.web11.36896.1736692500749316195 for ; Sun, 12 Jan 2025 06:35:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CzClPzAr; spf=pass (domain: gmail.com, ip: 209.85.208.52, mailfrom: arturkow2000@gmail.com) Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5d3d143376dso4957954a12.3 for ; Sun, 12 Jan 2025 06:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736692499; x=1737297299; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nYi/TTm+1enNtA4IV/T4w0oMOjdGSmQfvoH4tld4LEs=; b=CzClPzArN25sUIdZ7M3zEgG2w2Jej7/idnJm0Q+uKcroqG9jnLRg8PMBM0sBtlpFA0 /yyyb2df1F5xwIE3BtzAhli4ItiWPojSVhJRAFnM4bTK3DlPZFpv50kOyskuZF60S3n5 AqNJjt2I1EmEGDqmmfrI3C70/yOEgcj/OmP3nNoweIPY1IjtCwgdLYbAaqmSv1gbh9Gg EJY1uKPQ9n25hApfhcAJT3NTKSYMGaSODOJq4/lfk5BmE//BkOvXSqslJiCInWb12VZl OqKt87UYu8fD3ZocrrDErs7+tObHVUjlJ3lU5mHw8oQgsJ8D8zIN3Zu3DZtTuechiQ3h vofw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736692499; x=1737297299; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nYi/TTm+1enNtA4IV/T4w0oMOjdGSmQfvoH4tld4LEs=; b=cb5NIVIJfzm/2Z34ouZrb0ncyT7Mnd/0+4L6l67xRt2KmrNmI3bVQjlR/ezdjhgOHQ qx8Y49U2K4jw6DFXMFHvUHkPtz9V6HMv/F+7Mx1J8mPAo/WTZLMGYqsMnI0KeIGYVwGs EwnydpMXCJ7A5WNwnaejPlnvWt9LVSWUVXFrXlOgADL7ARH4hOIMsBI4Ft21vBhz7/bd N8RVmeFMjaAyNFqfVty+n0yJ1DOFglqz9UdRSEXyuH48JSVR8um1cX54VpShPbvTH+0/ taw7UoGB1MdWuBTe6FZGyvi0l4LDmLpNzjETk0T//bBpnG+hanql/JZnf4BA2iKOFNqL o2sw== X-Gm-Message-State: AOJu0Yw1d1w3KELQuKTIR0F5lyAOKg8Y8RT8Me6logbimfH1qCc0TEwt HmztZ9lc9leRpC/Oj4O41kQ+hNN4umDJNRLiL5dTELfP+F4Xxqbt+o+dCQ== X-Gm-Gg: ASbGncs6YrPEtJbyYv5VTAQacDqersNIZl+sN5aHXzOf2OhdrdyIet/2OFC6/acdzuT r4VilEyhh6NcgCmeWMdLAX5rxbQhA7yr2jD8Pon0hEzPoCDFKPN109owVlQGIymJHMvi5R0wMnB s5KyxatSsjZFYrlj0WM35DU/NvFNfxhOsbD+paxc1hR11bKIHqy4np3G6Q2NIClOOogPoD0k9kl 4Jc35OdlhJo7p9yl5jM3i8t30m7dVZCCrPeSPid8m3GQ1mJeaOnzrU5QmZq2sqb X-Google-Smtp-Source: AGHT+IG3EuIO6OeT+xrbFHT46386Nhavi5dago6Dot1aTTj2mlPSBr4uIx/8OdZs77mXSE6tgqkBFQ== X-Received: by 2002:a05:6402:5254:b0:5d3:fc60:a504 with SMTP id 4fb4d7f45d1cf-5d972e17891mr16021187a12.20.1736692498554; Sun, 12 Jan 2025 06:34:58 -0800 (PST) Received: from eta.play.pl ([2a02:a312:c49b:a180:dec6:9e22:e5fb:f0d5]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d99d05bec4sm3207739a12.14.2025.01.12.06.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 06:34:57 -0800 (PST) From: "Artur Kowalski" To: openembedded-core@lists.openembedded.org Cc: Artur Kowalski Subject: [PATCH 3/3] image.bbclass: enable systemd user services Date: Sun, 12 Jan 2025 15:31:41 +0100 Message-ID: <20250112143141.1300189-4-arturkow2000@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250112143141.1300189-1-arturkow2000@gmail.com> References: <20250112143141.1300189-1-arturkow2000@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sun, 12 Jan 2025 14:40:33 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/209688 Run systemctl preset-all with --global flag so user unit's are enabled the same way system units are. Signed-off-by: Artur Kowalski --- 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 }