diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-22 11:22:33 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-24 11:46:23 +0200 |
commit | 6d825ab2d42d3219e49a192bf99f9c09134a0df4 (patch) | |
tree | 3411f53c879744b5e40ecdb60aed91fe9c7bd8cf /src/rpm/macros.systemd.in | |
parent | 7d9ee15d0fc2af87481ee371b278dbe7e68165ef (diff) | |
download | systemd-6d825ab2d42d3219e49a192bf99f9c09134a0df4.tar.gz |
rpm: use a helper script to actually invoke systemctl commands
Instead of embedding the commands to invoke directly in the macros,
let's use a helper script as indirection. This has a couple of advantages:
- the macro language is awkward, we need to suffix most commands by "|| :"
and "\", which is easy to get wrong. In the new scheme, the macro becomes
a single simple command.
- in the script we can use normal syntax highlighting, shellcheck, etc.
- it's also easier to test the invoked commands by invoking the helper
manually.
- most importantly, the logic is contained in the helper, i.e. we can
update systemd rpm and everything uses the new helper. Before, we would
have to rebuild all packages to update the macro definition.
This raises the question whether it makes sense to use the lua scriptlets when
the real work is done in a bash script. I think it's OK: we still have the
efficient lua scripts that do the short scripts, and we use a single shared
implementation in bash to do the more complex stuff.
The meson version is raised to 0.47 because that's needed for install_mode.
We were planning to raise the required version anyway…
Diffstat (limited to 'src/rpm/macros.systemd.in')
-rw-r--r-- | src/rpm/macros.systemd.in | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/rpm/macros.systemd.in b/src/rpm/macros.systemd.in index 3129ab2d61..bbdf036da7 100644 --- a/src/rpm/macros.systemd.in +++ b/src/rpm/macros.systemd.in @@ -46,31 +46,33 @@ OrderWithRequires(postun): systemd \ %systemd_post() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_post}} \ -if [ $1 -eq 1 ] && command -v systemctl >/dev/null; then \ +if [ $1 -eq 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ # Initial installation \ - systemctl --no-reload preset %{?*} || : \ + {{SYSTEMD_UPDATE_HELPER_PATH}} install-system-units %{?*} || : \ fi \ %{nil} -%systemd_user_post() %{expand:%systemd_post \\--global %%{?*}} +%systemd_user_post() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_post}} \ +if [ $1 -eq 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Initial installation \ + {{SYSTEMD_UPDATE_HELPER_PATH}} install-user-units %{?*} || : \ +fi \ +%{nil} %systemd_preun() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_preun}} \ -if [ $1 -eq 0 ] && command -v systemctl >/dev/null; then \ +if [ $1 -eq 0 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ # Package removal, not upgrade \ - if [ -d /run/systemd/system ]; then \ - systemctl --no-reload disable --now %{?*} || : \ - else \ - systemctl --no-reload disable %{?*} || : \ - fi \ + {{SYSTEMD_UPDATE_HELPER_PATH}} remove-system-units %{?*} || : \ fi \ %{nil} %systemd_user_preun() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \ -if [ $1 -eq 0 ] && command -v systemctl >/dev/null; then \ +if [ $1 -eq 0 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ # Package removal, not upgrade \ - systemctl --global disable %{?*} || : \ + {{SYSTEMD_UPDATE_HELPER_PATH}} remove-user-units %{?*} || : \ fi \ %{nil} @@ -84,11 +86,9 @@ fi \ %systemd_postun_with_restart() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \ -if [ $1 -ge 1 ] && command -v systemctl >/dev/null; then \ +if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ # Package upgrade, not uninstall \ - for unit in %{?*}; do \ - systemctl set-property $unit Markers=+needs-restart || : \ - done \ + {{SYSTEMD_UPDATE_HELPER_PATH}} mark-restart-system-units %{?*} || : \ fi \ %{nil} |