forked from pool/systemd-rpm-macros
Before presests were applied at a) package installation b) new units introduced via a package update (but after making sure that it was not a SysV initscript being converted). The problem is that a) didn't handle package a renaming or split properly since the package with the new name is installed rather being updated and therefore the presets were applied even if they were already with the old name. We now cover this case (and the other ones) by applying presets only if the units are new and the services are not being migrated. This regardless of whether this happens during an install or an update. OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd-rpm-macros?expand=0&rev=59
242 lines
7.1 KiB
Plaintext
242 lines
7.1 KiB
Plaintext
# -*- Mode: rpm-spec; indent-tabs-mode: t -*- */
|
|
# RPM macros for packages installing systemd unit files
|
|
#
|
|
###
|
|
#
|
|
# When a package install systemd unit files, it should use the following macros:
|
|
#
|
|
# add %systemd_requires in the specfile
|
|
#
|
|
# %pre
|
|
# %service_add_pre demo.service demo1.service
|
|
#
|
|
# %post
|
|
# %service_add_post demo.service demo1.service
|
|
#
|
|
# %preun
|
|
# %service_del_preun demo.service
|
|
#
|
|
# %postun
|
|
# %service_del_postun demo.service
|
|
# %service_del_postun_without_restart demo.service
|
|
#
|
|
|
|
%_unitdir /usr/lib/systemd/system
|
|
%_userunitdir /usr/lib/systemd/user
|
|
%_presetdir /usr/lib/systemd/system-preset
|
|
%_userpresetdir /usr/lib/systemd/user-preset
|
|
%_udevhwdbdir /usr/lib/udev/hwdb.d
|
|
%_udevrulesdir /usr/lib/udev/rules.d
|
|
%_journalcatalogdir /usr/lib/systemd/catalog
|
|
%_tmpfilesdir /usr/lib/tmpfiles.d
|
|
%_sysusersdir /usr/lib/sysusers.d
|
|
%_sysctldir /usr/lib/sysctl.d
|
|
%_ntpunitsdir /usr/lib/systemd/ntp-units.d
|
|
%_binfmtdir /usr/lib/binfmt.d
|
|
%_environmentdir /usr/lib/environment.d
|
|
%_modulesloaddir /usr/lib/modules-load.d
|
|
%_modprobedir /usr/lib/modprobe.d
|
|
%_systemdgeneratordir /usr/lib/systemd/system-generators
|
|
%_systemdusergeneratordir /usr/lib/systemd/user-generators
|
|
%_systemd_system_env_generator_dir /usr/lib/systemd/system-environment-generators
|
|
%_systemd_user_env_generator_dir /usr/lib/systemd/user-environment-generators
|
|
|
|
%systemd_requires \
|
|
Requires(pre): systemd \
|
|
Requires(post): systemd \
|
|
Requires(preun): systemd \
|
|
Requires(postun): systemd \
|
|
%{nil}
|
|
|
|
%systemd_ordering \
|
|
OrderWithRequires(post): systemd \
|
|
OrderWithRequires(preun): systemd \
|
|
OrderWithRequires(postun): systemd \
|
|
%{nil}
|
|
|
|
%_restart_on_update_force() /usr/bin/systemctl try-restart %{*} || : %{nil}
|
|
%_restart_on_update_never() : # Restart of %{*} skipped %{nil}
|
|
|
|
%_restart_on_update() \
|
|
if [ -e /etc/sysconfig/services ]; then \
|
|
DISABLE_RESTART_ON_UPDATE= \
|
|
. /etc/sysconfig/services \
|
|
case "$DISABLE_RESTART_ON_UPDATE" in \
|
|
yes|1) ;; \
|
|
*) /usr/bin/systemctl try-restart %{*} || : \
|
|
esac \
|
|
fi \
|
|
%{nil}
|
|
|
|
# Figure out when presets need to be applied. This information is only
|
|
# recorded during %pre and is actually applied during %post.
|
|
#
|
|
# Presets might need to be applied during package install but also
|
|
# during package update. On update, packages might introduce new
|
|
# services but we need to make sure that's not happening during the
|
|
# migration of SysV initscripts. On package install, presets might
|
|
# have been already applied because of package renaming or split.
|
|
#
|
|
%service_add_pre() \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
for service in %{?*} ; do \
|
|
if [ ! -e "/usr/lib/systemd/system/$service" ] && \
|
|
[ ! -e "/etc/init.d/${service%.*}" ]; then \
|
|
mkdir -p /run/systemd/rpm/needs-preset \
|
|
touch "/run/systemd/rpm/needs-preset/$service" \
|
|
fi \
|
|
done \
|
|
fi \
|
|
%{nil}
|
|
|
|
# Apply the presets if %pre told us to do so.
|
|
#
|
|
%service_add_post() \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
for service in %{?*} ; do \
|
|
if [ -e "/run/systemd/rpm/needs-preset/$service" ]; then \
|
|
/usr/bin/systemctl preset "$service" || : \
|
|
rm -f /run/systemd/rpm/needs-preset/$service \
|
|
else \
|
|
/usr/lib/systemd/systemd-sysv-convert --apply %{?*} || : \
|
|
fi \
|
|
done \
|
|
fi \
|
|
%{nil}
|
|
|
|
# On uninstall, disable and stop services
|
|
#
|
|
%service_del_preun() \
|
|
if [ $1 -eq 0 -a -x /usr/bin/systemctl ]; then \
|
|
# Package removal, not upgrade \
|
|
/usr/bin/systemctl --no-reload disable --now %{?*} || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
# On uninstall, tell systemd to reload its unit files.
|
|
# On update, tell systemd to reload its unit files but don't restart service.
|
|
#
|
|
# It ignores the content of /etc/sysconfig/services
|
|
#
|
|
%service_del_postun_without_restart() \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
/usr/bin/systemctl daemon-reload || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
# On uninstall, tell systemd to reload its unit files.
|
|
# On update, tell systemd to reload its unit files and restart service.
|
|
#
|
|
# It ignores the content of /etc/sysconfig/services
|
|
#
|
|
%service_del_postun_with_restart() \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
/usr/bin/systemctl daemon-reload || : \
|
|
if [ $1 -ge 1 ]; then \
|
|
# Package upgrade, not uninstall \
|
|
/usr/bin/systemctl try-restart %{?*} || : \
|
|
fi \
|
|
fi \
|
|
%{nil}
|
|
|
|
# On uninstall, tell systemd to reload its unit files
|
|
#
|
|
# Deprecated options, please do not use in new code:
|
|
# -f : force restart on update (replaced by %service_del_postun_with_restart)
|
|
# -n : don't restart on update (replaced by %service_del_postun_without_restart)
|
|
#
|
|
# The default is to read DISABLE_RESTART_ON_UPDATE from /etc/sysconfig/services
|
|
#
|
|
%service_del_postun(fn) \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
/usr/bin/systemctl daemon-reload || : \
|
|
if [ $1 -ge 1 ]; then \
|
|
# Package upgrade, not uninstall \
|
|
%{expand:%%_restart_on_update%{-f:_force}%{!-f:%{-n:_never}} %{?*}} \
|
|
fi \
|
|
fi \
|
|
%{nil}
|
|
|
|
#
|
|
# Upstream variants
|
|
#
|
|
|
|
%systemd_post() \
|
|
if [ $1 -eq 1 -a -x /usr/bin/systemctl ] ; then \
|
|
# Initial installation \
|
|
/usr/bin/systemctl --no-reload preset %{?*} || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
%systemd_user_post() %{expand:%systemd_post \\--global %%{?*}}
|
|
|
|
%systemd_preun() \
|
|
if [ $1 -eq 0 -a -x /usr/bin/systemctl ]; then \
|
|
# Package removal, not upgrade \
|
|
/usr/bin/systemctl --no-reload disable --now %{?*} || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
%systemd_user_preun() \
|
|
if [ $1 -eq 0 -a -x /usr/bin/systemctl ]; then \
|
|
# Package removal, not upgrade \
|
|
/usr/bin/systemctl --global disable %{?*} || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
%systemd_postun() \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
/usr/bin/systemctl daemon-reload || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
%systemd_user_postun() %{nil}
|
|
%systemd_user_postun_with_restart() %{nil}
|
|
|
|
%systemd_postun_with_restart() \
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
/usr/bin/systemctl daemon-reload || : \
|
|
fi \
|
|
if [ $1 -ge 1 -a -x /usr/bin/systemctl ]; then \
|
|
# Package upgrade, not uninstall \
|
|
/usr/bin/systemctl try-restart %{?*} || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
%udev_hwdb_update() \
|
|
[ -x /usr/bin/udevadm ] && /usr/bin/udevadm hwdb --update || : \
|
|
%{nil}
|
|
|
|
%udev_rules_update() \
|
|
[ -x /usr/bin/udevadm ] && /usr/bin/udevadm control --reload || : \
|
|
%{nil}
|
|
|
|
%journal_catalog_update() \
|
|
[ -x /usr/bin/journalctl ] && /usr/bin/journalctl --update-catalog || : \
|
|
%{nil}
|
|
|
|
%tmpfiles_create() \
|
|
[ -z "${TRANSACTIONAL_UPDATE}" -a -x /usr/bin/systemd-tmpfiles ] && \
|
|
/usr/bin/systemd-tmpfiles --create %{?*} || : \
|
|
%{nil}
|
|
|
|
%sysusers_create() \
|
|
[ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers %{?*} || : \
|
|
%{nil}
|
|
|
|
%sysusers_create_inline() \
|
|
if [ -x /usr/bin/systemd-sysusers ]; then \
|
|
echo %{?*} | systemd-sysusers - || : \
|
|
fi \
|
|
%{nil}
|
|
|
|
%sysctl_apply() \
|
|
[ -x /usr/lib/systemd/systemd-sysctl ] && \
|
|
/usr/lib/systemd/systemd-sysctl %{?*} || : \
|
|
%{nil}
|
|
|
|
%binfmt_apply() \
|
|
[ -x /usr/lib/systemd/systemd-binfmt ] && \
|
|
/usr/lib/systemd/systemd-binfmt %{?*} || : \
|
|
%{nil}
|