systemd: rework trigger script

* apk-tools passes the directories it triggers on as arguments to the
  trigger script. Use them to only run the relevant parts of the
  triggers.
* Remove "|| :" from commands, as we run the script without "set -e", it
  won't fail if a single command fails. Put explicit "exit 0" at the end
  to ensure this even if the last command beforehand failed.
* Print messages for each action so we know what is happening.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6346
[ci:skip-build]: already built successfully in CI
This commit is contained in:
Oliver Smith
2025-03-27 20:33:05 +01:00
parent fe59d6ebc5
commit 9c9c62143b
2 changed files with 95 additions and 53 deletions
+1 -4
View File
@@ -6,16 +6,13 @@ pkgname=systemd
# currently tracking git MR
pkgver=256.11
_pkgver="musl-v${pkgver//_/-}-split-usr"
pkgrel=4
pkgrel=5
pkgdesc="System and service manager"
url="https://github.com/systemd/systemd"
arch="all !ppc64le !s390x" # blocked by pmboostrap not supporting
license="MIT AND GPL-2.0-only AND LGPL-2.1-or-later"
options="pmb:strict !check" # few tests fail, need to debug. We use alpine dbus for building, systemd-dbus for runtime
# FIXME: it turns out abuild doesn't let you have arbitrary triggers?! what century is this???
# So we have to trigger everything on everything and do a bunch of reloading that
# isn't necessary most of the time...
triggers="$pkgname.trigger=/usr/lib/systemd/catalog:\
/usr/lib/udev/hwdb.d:\
/usr/lib/binfmt.d:\
+94 -49
View File
@@ -1,62 +1,107 @@
#!/bin/sh
# When adding new paths to trigger on here, make sure to also add them in
# triggers= in the APKBUILD.
TRIGGERPATHS="$*"
SYSTEM_SERVICES_CHANGED=false
USER_SERVICES_CHANGED=false
# All the things we can do even if systemd isn't running
trigger_always() {
for triggerpath in $TRIGGERPATHS; do
case "$triggerpath" in
/usr/lib/systemd/catalog)
echo "Running journalctl --update-catalog..."
journalctl --update-catalog
;;
/usr/lib/udev/hwdb.d)
echo "Running systemd-hwdb update..."
systemd-hwdb update
;;
/usr/lib/sysusers.d)
echo "Running systemd-sysusers..."
systemd-sysusers
;;
/usr/lib/systemd/system|/etc/systemd/system)
SYSTEM_SERVICES_CHANGED=true
;;
/usr/lib/systemd/user|/etc/systemd/user)
USER_SERVICES_CHANGED=true
;;
esac
done
}
# Update journald catalog
# FIXME: trigger only on /usr/lib/systemd/catalog
journalctl --update-catalog || :
trigger_systemd_running() {
for triggerpath in $TRIGGERPATHS; do
case "$triggerpath" in
/usr/lib/binfmt.d)
echo "Running systemd-binfmt..."
/usr/lib/systemd/systemd-binfmt
;;
/usr/lib/tmpfiles.d)
echo "Running systemd-tmpfiles --create..."
systemd-tmpfiles --create
;;
/usr/lib/udev/rules.d)
# We can't do this as a trigger for the udevd
# subpackage because it might end up running AFTER the
# systemd trigger.
echo "Marking systemd-udevd for reload..."
systemctl set-property systemd-udevd.service Markers=+needs-reload
;;
/usr/lib/sysctl.d)
echo "Running systemd-sysctl..."
/usr/lib/systemd/systemd-sysctl
;;
esac
done
}
# Update the hwdb if it was modified
# FIXME: trigger only on /usr/lib/udev/hwdb.d
systemd-hwdb update || :
trigger_user_and_system_services() {
if $SYSTEM_SERVICES_CHANGED || $USER_SERVICES_CHANGED; then
echo "Running systemd daemon-reload..."
systemctl daemon-reload
fi
# Process new sysusers
# FIXME: trigger only on /usr/lib/sysusers.d
systemd-sysusers || :
# This doesn't do anything yet but will trigger a daemon-reexec once we
# upgrade to systemd 257:
# https://github.com/systemd/systemd/commit/a375e145190482e8a2f0971bffb332e31211622f
if $USER_SERVICES_CHANGED; then
echo "Running systemd reload user@*.service..."
systemctl reload "user@*.service"
fi
# OK, if systemd isn't running then we're done, else we have more
# to do!
# Reload or restart marked system units. Units get marked in their
# respective package post-upgrade scripts
if $SYSTEM_SERVICES_CHANGED; then
echo "Reloading/restarting marked system services..."
systemctl reload-or-restart --marked
fi
if $USER_SERVICES_CHANGED; then
local uids
uids="$(systemctl list-units 'user@*' --legend=no \
| sed -n -r 's/.*user@([0-9]+).service.*/\1/p')"
for uid in $uids; do
echo "Reloading/restarting marked user services for uid=$uid..."
systemctl \
--user \
-M "$uid@" \
reload-or-restart \
--marked &
done
wait
fi
}
trigger_always
if ! [ -d "/run/systemd/system" ]; then
echo "Skipping other triggers because systemd isn't running"
exit 0
fi
# Can fail if binfmt_misc is not loaded
# FIXME: trigger only on /usr/lib/binfmt.d
/usr/lib/systemd/systemd-binfmt || :
trigger_systemd_running
trigger_user_and_system_services
# Create new tmpfiles
# FIXME: trigger only on /usr/lib/tmpfiles.d
systemd-tmpfiles --create
# FIXME: trigger only on /usr/lib/udev/rules.d
# We can't do this as a trigger for the udevd subpackage because it might
# end up running AFTER the systemd trigger. Urgh!
systemctl set-property systemd-udevd.service Markers=+needs-reload &
# FIXME: trigger only on /usr/lib/sysctl.d
/usr/lib/systemd/systemd-sysctl || :
# FIXME: the rest of this should trigger on. The system and user parts
# could trigger separately but the ordering is still important (systemd
# itself should be reloaded at the system and user level before services
# are reloaded or restarted).
# /usr/lib/systemd/system:/usr/lib/systemd/user:/etc/systemd/system:/etc/systemd/user
# First do a system-wide daemon-reload
systemctl daemon-reload
# And reload the user services. This doesn't do anything yet but will trigger
# a daemon-reexec once we upgrade to systemd 257. See
# https://github.com/systemd/systemd/commit/a375e145190482e8a2f0971bffb332e31211622f
systemctl reload "user@*.service"
# Then reload or restart marked system units. Units get marked in their respective
# package post-upgrade scripts
systemctl reload-or-restart --marked
users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')
for user in $users; do
systemctl --user -M "$user@" reload-or-restart --marked &
done
wait
exit 0