From 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 22:49:52 +0200 Subject: Adding upstream version 255.4. Signed-off-by: Daniel Baumann --- src/rpm/macros.systemd.in | 199 +++++++++++++++++++++++++++++++++++++++ src/rpm/meson.build | 25 +++++ src/rpm/systemd-update-helper.in | 141 +++++++++++++++++++++++++++ src/rpm/triggers.systemd.in | 82 ++++++++++++++++ src/rpm/triggers.systemd.sh.in | 87 +++++++++++++++++ 5 files changed, 534 insertions(+) create mode 100644 src/rpm/macros.systemd.in create mode 100644 src/rpm/meson.build create mode 100755 src/rpm/systemd-update-helper.in create mode 100644 src/rpm/triggers.systemd.in create mode 100644 src/rpm/triggers.systemd.sh.in (limited to 'src/rpm') diff --git a/src/rpm/macros.systemd.in b/src/rpm/macros.systemd.in new file mode 100644 index 0000000..241e4b9 --- /dev/null +++ b/src/rpm/macros.systemd.in @@ -0,0 +1,199 @@ +# -*- Mode: rpm-spec; indent-tabs-mode: nil -*- */ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. + +# RPM macros for packages installing systemd unit files + +%_systemd_util_dir {{LIBEXECDIR}} +%_unitdir {{SYSTEM_DATA_UNIT_DIR}} +%_userunitdir {{USER_DATA_UNIT_DIR}} +%_presetdir {{SYSTEM_PRESET_DIR}} +%_userpresetdir {{USER_PRESET_DIR}} +%_udevhwdbdir {{UDEV_HWDB_DIR}} +%_udevrulesdir {{UDEV_RULES_DIR}} +%_journalcatalogdir {{SYSTEMD_CATALOG_DIR}} +%_binfmtdir {{BINFMT_DIR}} +%_sysctldir {{SYSCTL_DIR}} +%_sysusersdir {{SYSUSERS_DIR}} +%_tmpfilesdir {{TMPFILES_DIR}} +%_user_tmpfilesdir {{USER_TMPFILES_DIR}} +%_environmentdir {{ENVIRONMENT_DIR}} +%_modulesloaddir {{MODULESLOAD_DIR}} +%_modprobedir {{MODPROBE_DIR}} +%_systemdgeneratordir {{SYSTEM_GENERATOR_DIR}} +%_systemdusergeneratordir {{USER_GENERATOR_DIR}} +%_systemd_system_env_generator_dir {{SYSTEM_ENV_GENERATOR_DIR}} +%_systemd_user_env_generator_dir {{USER_ENV_GENERATOR_DIR}} + +# Because we had one release with a typo... +# This is temporary (Remove after systemd 240 is released) +%_environmnentdir %{warn:Use %%_environmentdir instead}%_environmentdir + +%systemd_requires \ +Requires(post): systemd \ +Requires(preun): systemd \ +Requires(postun): systemd \ +%{nil} + +%systemd_ordering \ +OrderWithRequires(post): systemd \ +OrderWithRequires(preun): systemd \ +OrderWithRequires(postun): systemd \ +%{nil} + +%__systemd_someargs_0(:) %{error:The %%%1 macro requires some arguments} +%__systemd_twoargs_2() %{nil} + +%systemd_post() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_post}} \ +if [ $1 -eq 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Initial installation \ + {{SYSTEMD_UPDATE_HELPER_PATH}} install-system-units %{?*} || : \ +fi \ +%{nil} + +%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 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package removal, not upgrade \ + {{SYSTEMD_UPDATE_HELPER_PATH}} remove-system-units %{?*} || : \ +fi \ +%{nil} + +%systemd_user_preun() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \ +if [ $1 -eq 0 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package removal, not upgrade \ + {{SYSTEMD_UPDATE_HELPER_PATH}} remove-user-units %{?*} || : \ +fi \ +%{nil} + +%systemd_postun() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun}} \ +%{nil} + +%systemd_user_postun() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun}} \ +%{nil} + +%systemd_postun_with_restart() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \ +if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package upgrade, not uninstall \ + {{SYSTEMD_UPDATE_HELPER_PATH}} mark-restart-system-units %{?*} || : \ +fi \ +%{nil} + +%systemd_user_postun_with_restart() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun_with_restart}} \ +if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package upgrade, not uninstall \ + {{SYSTEMD_UPDATE_HELPER_PATH}} mark-restart-user-units %{?*} || : \ +fi \ +%{nil} + +%systemd_postun_with_reload() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_reload}} \ +if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package upgrade, not uninstall \ + {{SYSTEMD_UPDATE_HELPER_PATH}} mark-reload-system-units %{?*} || : \ +fi \ +%{nil} + +%systemd_user_postun_with_reload() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun_with_reload}} \ +if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package upgrade, not uninstall \ + {{SYSTEMD_UPDATE_HELPER_PATH}} mark-reload-user-units %{?*} || : \ +fi \ +%{nil} + +%systemd_user_daemon_reexec() \ +if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \ + # Package upgrade, not uninstall \ + {{SYSTEMD_UPDATE_HELPER_PATH}} user-reexec || : \ +fi \ +%{nil} + +%udev_hwdb_update() %{nil} + +%udev_rules_update() %{nil} + +%journal_catalog_update() %{nil} + +# Deprecated. Use %tmpfiles_create_package instead +%tmpfiles_create() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# tmpfiles_create}} \ +command -v systemd-tmpfiles >/dev/null && systemd-tmpfiles --create %{?*} || : \ +%{nil} + +# Deprecated. Use %sysusers_create_package instead +%sysusers_create() \ +%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysusers_create}} \ +command -v systemd-sysusers >/dev/null && systemd-sysusers %{?*} || : \ +%{nil} + +%sysusers_create_inline() \ +command -v systemd-sysusers >/dev/null && systemd-sysusers - < 2 ? tuple[2] : '', + build_by_default : true) +endforeach diff --git a/src/rpm/systemd-update-helper.in b/src/rpm/systemd-update-helper.in new file mode 100755 index 0000000..c81e16c --- /dev/null +++ b/src/rpm/systemd-update-helper.in @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eu +set -o pipefail + +command="${1:?}" +shift + +command -v systemctl >/dev/null || exit 0 + +case "$command" in + install-system-units) + systemctl --no-reload preset "$@" + ;; + + install-user-units) + systemctl --no-reload preset --global "$@" + ;; + + remove-system-units) + if [ -d /run/systemd/system ]; then + systemctl --no-reload disable --now --no-warn "$@" + else + systemctl --no-reload disable --no-warn "$@" + fi + ;; + + remove-user-units) + systemctl --global disable --no-warn "$@" + + [ -d /run/systemd/system ] || exit 0 + + users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p') + for user in $users; do + SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ + systemctl --user -M "$user@" disable --now --no-warn "$@" & + done + wait + ;; + + mark-restart-system-units) + [ -d /run/systemd/system ] || exit 0 + + for unit in "$@"; do + systemctl set-property "$unit" Markers=+needs-restart & + done + wait + ;; + + mark-reload-system-units) + [ -d /run/systemd/system ] || exit 0 + + for unit in "$@"; do + systemctl set-property "$unit" Markers=+needs-reload & + done + wait + ;; + + mark-restart-user-units) + [ -d /run/systemd/system ] || exit 0 + + users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p') + for user in $users; do + for unit in "$@"; do + SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ + systemctl --user -M "$user@" set-property "$unit" Markers=+needs-restart & + done + done + wait + ;; + + mark-reload-user-units) + [ -d /run/systemd/system ] || exit 0 + + users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p') + for user in $users; do + for unit in "$@"; do + SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ + systemctl --user -M "$user@" set-property "$unit" Markers=+needs-reload & + done + done + wait + ;; + + system-reload-restart|system-reload|system-restart) + if [ -n "$*" ]; then + echo "Unexpected arguments for '$command': $*" + exit 2 + fi + + [ -d /run/systemd/system ] || exit 0 + + if [[ "$command" =~ reload ]]; then + systemctl daemon-reload + fi + + if [[ "$command" =~ restart ]]; then + systemctl reload-or-restart --marked + fi + ;; + + user-reload-restart|user-reload|user-restart|user-reexec) + if [ -n "$*" ]; then + echo "Unexpected arguments for '$command': $*" + exit 2 + fi + + [ -d /run/systemd/system ] || exit 0 + + users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p') + + if [[ "$command" =~ reexec ]]; then + for user in $users; do + SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ + systemctl --user -M "$user@" daemon-reexec & + done + wait + fi + + if [[ "$command" =~ reload ]]; then + for user in $users; do + SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ + systemctl --user -M "$user@" daemon-reload & + done + wait + fi + + if [[ "$command" =~ restart ]]; then + for user in $users; do + SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \ + systemctl --user -M "$user@" reload-or-restart --marked & + done + wait + fi + ;; + + *) + echo "Unknown verb '$command'" + exit 3 + ;; +esac diff --git a/src/rpm/triggers.systemd.in b/src/rpm/triggers.systemd.in new file mode 100644 index 0000000..d480ab8 --- /dev/null +++ b/src/rpm/triggers.systemd.in @@ -0,0 +1,82 @@ +# -*- Mode: rpm-spec; indent-tabs-mode: nil -*- */ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# Copyright © 2018 Neal Gompa + +# The contents of this are an example to be copied into systemd.spec. +# +# Minimum rpm version supported: 4.14.0 + +%transfiletriggerin -P 900900 -p -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +-- This script will run after any package is initially installed or +-- upgraded. We care about the case where a package is initially +-- installed, because other cases are covered by the *un scriptlets, +-- so sometimes we will reload needlessly. +assert(rpm.execute("{{SYSTEMD_UPDATE_HELPER_PATH}}", "system-reload-restart")) + +%transfiletriggerin -P 900899 -p -- {{USER_DATA_UNIT_DIR}} /etc/systemd/user +assert(rpm.execute("{{SYSTEMD_UPDATE_HELPER_PATH}}", "user-reload-restart")) + +%transfiletriggerpostun -P 1000100 -p -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +-- On removal, we need to run daemon-reload after any units have been +-- removed. +-- On upgrade, we need to run daemon-reload after any new unit files +-- have been installed, but before %postun scripts in packages get +-- executed. +assert(rpm.execute("{{SYSTEMD_UPDATE_HELPER_PATH}}", "system-reload")) + +%transfiletriggerpostun -P 1000100 -p -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +-- Execute daemon-reload in user managers. +assert(rpm.execute("{{SYSTEMD_UPDATE_HELPER_PATH}}", "user-reload")) + +%transfiletriggerpostun -P 10000 -p -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +-- We restart remaining system services that should be restarted here. +assert(rpm.execute("{{SYSTEMD_UPDATE_HELPER_PATH}}", "system-restart")) + +%transfiletriggerpostun -P 9999 -p -- {{USER_DATA_UNIT_DIR}} /etc/systemd/user +-- We restart remaining user services that should be restarted here. +assert(rpm.execute("{{SYSTEMD_UPDATE_HELPER_PATH}}", "user-restart")) + +%transfiletriggerin -P 1000700 -p -- {{SYSUSERS_DIR}} +-- This script will process files installed in {{SYSUSERS_DIR}} to create +-- specified users automatically. The priority is set such that it +-- will run before the tmpfiles file trigger. +assert(rpm.execute("systemd-sysusers")) + +%transfiletriggerin -P 1000700 udev -p -- {{UDEV_HWDB_DIR}} +-- This script will automatically invoke hwdb update if files have been +-- installed or updated in {{UDEV_HWDB_DIR}}. +assert(rpm.execute("systemd-hwdb", "update")) + +%transfiletriggerin -P 1000700 -p -- {{SYSTEMD_CATALOG_DIR}} +-- This script will automatically invoke journal catalog update if files +-- have been installed or updated in {{SYSTEMD_CATALOG_DIR}}. +assert(rpm.execute("journalctl", "--update-catalog")) + +%transfiletriggerin -P 1000700 -p -- {{BINFMT_DIR}} +-- This script will automatically apply binfmt rules if files have been +-- installed or updated in {{BINFMT_DIR}}. +if posix.access("/run/systemd/system") then + assert(rpm.execute("{{LIBEXECDIR}}/systemd-binfmt")) +end + +%transfiletriggerin -P 1000600 -p -- {{TMPFILES_DIR}} +-- This script will process files installed in {{TMPFILES_DIR}} to create +-- tmpfiles automatically. The priority is set such that it will run +-- after the sysusers file trigger, but before any other triggers. +assert(rpm.execute("systemd-tmpfiles", "--create")) + +%transfiletriggerin -P 1000600 udev -p -- {{UDEV_RULES_DIR}} +-- This script will automatically update udev with new rules if files +-- have been installed or updated in {{UDEV_RULES_DIR}}. +if posix.access("/run/udev/control") then + assert(rpm.execute("udevadm", "control", "--reload")) +end + +%transfiletriggerin -P 1000500 -p -- {{SYSCTL_DIR}} +-- This script will automatically apply sysctl rules if files have been +-- installed or updated in {{SYSCTL_DIR}}. +if posix.access("/run/systemd/system") then + assert(rpm.execute("{{LIBEXECDIR}}/systemd-sysctl")) +end diff --git a/src/rpm/triggers.systemd.sh.in b/src/rpm/triggers.systemd.sh.in new file mode 100644 index 0000000..1b94f7d --- /dev/null +++ b/src/rpm/triggers.systemd.sh.in @@ -0,0 +1,87 @@ +# -*- Mode: rpm-spec; indent-tabs-mode: nil -*- */ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# Copyright 2018 Neal Gompa + +# The contents of this are an example to be copied into systemd.spec. +# +# Minimum rpm version supported: 4.14.0 + +%transfiletriggerin -P 900900 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +# This script will run after any package is initially installed or +# upgraded. We care about the case where a package is initially +# installed, because other cases are covered by the *un scriptlets, +# so sometimes we will reload needlessly. +{{SYSTEMD_UPDATE_HELPER_PATH}} system-reload-restart || : + +%transfiletriggerin -P 900899 -- {{USER_DATA_UNIT_DIR}} /etc/systemd/user +{{SYSTEMD_UPDATE_HELPER_PATH}} user-reload-restart || : + +%transfiletriggerpostun -P 1000100 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +# On removal, we need to run daemon-reload after any units have been +# removed. +# On upgrade, we need to run daemon-reload after any new unit files +# have been installed, but before %postun scripts in packages get +# executed. +{{SYSTEMD_UPDATE_HELPER_PATH}} system-reload || : + +%transfiletriggerpostun -P 1000099 -- {{USER_DATA_UNIT_DIR}} /etc/systemd/user +# Execute daemon-reload in user managers. +{{SYSTEMD_UPDATE_HELPER_PATH}} user-reload || : + +%transfiletriggerpostun -P 10000 -- {{SYSTEM_DATA_UNIT_DIR}} /etc/systemd/system +# We restart remaining system services that should be restarted here. +{{SYSTEMD_UPDATE_HELPER_PATH}} system-restart || : + +%transfiletriggerpostun -P 9999 -- {{USER_DATA_UNIT_DIR}} /etc/systemd/user +# We restart remaining user services that should be restarted here. +{{SYSTEMD_UPDATE_HELPER_PATH}} user-restart || : + +%transfiletriggerin -P 1000700 -- {{SYSUSERS_DIR}} +# This script will process files installed in {{SYSUSERS_DIR}} to create +# specified users automatically. The priority is set such that it +# will run before the tmpfiles file trigger. +systemd-sysusers || : + +%transfiletriggerin -P 1000700 udev -- {{UDEV_HWDB_DIR}} +# This script will automatically invoke hwdb update if files have been +# installed or updated in {{UDEV_HWDB_DIR}}. +systemd-hwdb update || : + +%transfiletriggerin -P 1000700 -- {{SYSTEMD_CATALOG_DIR}} +# This script will automatically invoke journal catalog update if files +# have been installed or updated in {{SYSTEMD_CATALOG_DIR}}. +journalctl --update-catalog || : + +%transfiletriggerin -P 1000700 -- {{BINFMT_DIR}} +# This script will automatically apply binfmt rules if files have been +# installed or updated in {{BINFMT_DIR}}. +if test -d "/run/systemd/system"; then + # systemd-binfmt might fail if binfmt_misc kernel module is not loaded + # during install + {{LIBEXECDIR}}/systemd-binfmt || : +fi + +%transfiletriggerin -P 1000600 -- {{TMPFILES_DIR}} +# This script will process files installed in {{TMPFILES_DIR}} to create +# tmpfiles automatically. The priority is set such that it will run +# after the sysusers file trigger, but before any other triggers. +if test -d "/run/systemd/system"; then + systemd-tmpfiles --create || : +fi + +%transfiletriggerin -P 1000600 udev -- {{UDEV_RULES_DIR}} +# This script will automatically update udev with new rules if files +# have been installed or updated in {{UDEV_RULES_DIR}}. +if test -e /run/udev/control; then + udevadm control --reload || : +fi + +%transfiletriggerin -P 1000500 -- {{SYSCTL_DIR}} +# This script will automatically apply sysctl rules if files have been +# installed or updated in {{SYSCTL_DIR}}. +if test -d "/run/systemd/system"; then + {{LIBEXECDIR}}/systemd-sysctl || : +fi -- cgit v1.2.3