From: Artur Kowalski Date: Mon, 20 Jan 2025 12:46:05 +0000 (+0100) Subject: systemd.bbclass: support user units in postinst and prerm hooks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce62b88d8f71368e356b6409ada46a34a6017ddf;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git 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. Signed-off-by: Artur Kowalski Signed-off-by: Richard Purdie --- diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 0bce015509..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 }