systemd.bbclass: support user units in postinst and prerm hooks

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.

(From OE-Core rev: ce62b88d8f71368e356b6409ada46a34a6017ddf)

Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Artur Kowalski 2025-01-20 13:46:05 +01:00 committed by Richard Purdie
parent db86156875
commit 2ff2277ba3

View 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
}