]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
systemd.bbclass: update postinst and prerm hooks
authorArtur Kowalski <arturkow2000@gmail.com>
Mon, 20 Jan 2025 12:46:04 +0000 (13:46 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 21 Jan 2025 12:07:52 +0000 (12:07 +0000)
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>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/systemd.bbclass

index 592f15a4b7bc8ddca5b1caedc04d6df2cf9a7f4d..0bce015509eabe8d92e9179f0b110962af509594 100644 (file)
@@ -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
 }
@@ -108,6 +111,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