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

index 0bce015509eabe8d92e9179f0b110962af509594..4c9f51d33d6fab325575d0b8412336c0fcdd142f 100644 (file)
@@ -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
 }