2021-02-12 11:01:43 +00:00
|
|
|
# -*- Mode: rpm-spec; indent-tabs-mode: t -*- */
|
2013-06-20 13:51:16 +00:00
|
|
|
# RPM macros for packages installing systemd unit files
|
|
|
|
#
|
|
|
|
###
|
|
|
|
#
|
2021-02-12 11:45:54 +00:00
|
|
|
# When a package install systemd unit files, it should use the
|
|
|
|
# following macros:
|
2013-06-20 13:51:16 +00:00
|
|
|
#
|
|
|
|
# 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
|
2019-02-25 09:47:37 +00:00
|
|
|
# %service_del_postun_without_restart demo.service
|
2015-08-05 15:23:06 +00:00
|
|
|
#
|
2021-02-12 11:45:54 +00:00
|
|
|
# Note: the upstream variants are also available and are aliases to
|
|
|
|
# their SUSE counterparts. However for consistency the SUSE macros
|
|
|
|
# should be preferred unless the package is intended to be portable
|
|
|
|
# across multiple distributions based on RPM.
|
2013-06-20 13:51:16 +00:00
|
|
|
|
|
|
|
%_unitdir /usr/lib/systemd/system
|
2014-11-18 13:57:10 +00:00
|
|
|
%_userunitdir /usr/lib/systemd/user
|
2013-06-20 13:51:16 +00:00
|
|
|
%_presetdir /usr/lib/systemd/system-preset
|
2018-02-12 16:58:33 +00:00
|
|
|
%_userpresetdir /usr/lib/systemd/user-preset
|
2013-06-20 13:51:16 +00:00
|
|
|
%_udevhwdbdir /usr/lib/udev/hwdb.d
|
|
|
|
%_udevrulesdir /usr/lib/udev/rules.d
|
|
|
|
%_journalcatalogdir /usr/lib/systemd/catalog
|
|
|
|
%_tmpfilesdir /usr/lib/tmpfiles.d
|
2015-01-12 09:12:57 +00:00
|
|
|
%_sysusersdir /usr/lib/sysusers.d
|
2013-06-20 13:51:16 +00:00
|
|
|
%_sysctldir /usr/lib/sysctl.d
|
2014-03-27 14:45:24 +00:00
|
|
|
%_ntpunitsdir /usr/lib/systemd/ntp-units.d
|
2014-11-18 13:57:10 +00:00
|
|
|
%_binfmtdir /usr/lib/binfmt.d
|
2020-08-25 06:25:03 +00:00
|
|
|
%_environmentdir /usr/lib/environment.d
|
|
|
|
%_modulesloaddir /usr/lib/modules-load.d
|
|
|
|
%_modprobedir /usr/lib/modprobe.d
|
2018-02-12 16:58:33 +00:00
|
|
|
%_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}
|
2013-06-20 13:51:16 +00:00
|
|
|
|
2019-03-01 09:27:15 +00:00
|
|
|
%_restart_on_update_force() /usr/bin/systemctl try-restart %{*} || : %{nil}
|
|
|
|
%_restart_on_update_never() : # Restart of %{*} skipped %{nil}
|
2019-02-27 14:16:36 +00:00
|
|
|
|
2019-03-01 09:27:15 +00:00
|
|
|
%_restart_on_update() \
|
2020-11-10 09:13:24 +00:00
|
|
|
if [ -e /etc/sysconfig/services ]; then \
|
2020-11-02 14:40:43 +00:00
|
|
|
DISABLE_RESTART_ON_UPDATE= \
|
2019-03-01 09:27:15 +00:00
|
|
|
. /etc/sysconfig/services \
|
2020-11-02 14:40:43 +00:00
|
|
|
case "$DISABLE_RESTART_ON_UPDATE" in \
|
|
|
|
yes|1) ;; \
|
|
|
|
*) /usr/bin/systemctl try-restart %{*} || : \
|
|
|
|
esac \
|
|
|
|
fi \
|
2019-03-01 09:27:15 +00:00
|
|
|
%{nil}
|
2019-02-27 14:16:36 +00:00
|
|
|
|
2021-02-12 11:01:43 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2013-06-20 13:51:16 +00:00
|
|
|
%service_add_pre() \
|
2021-02-12 11:01:43 +00:00
|
|
|
if [ -x /usr/bin/systemctl ]; then \
|
2017-11-02 16:12:23 +00:00
|
|
|
for service in %{?*} ; do \
|
2020-11-09 11:38:05 +00:00
|
|
|
if [ ! -e "/usr/lib/systemd/system/$service" ] && \
|
|
|
|
[ ! -e "/etc/init.d/${service%.*}" ]; then \
|
2020-11-23 18:03:40 +00:00
|
|
|
mkdir -p /run/systemd/rpm/needs-preset \
|
|
|
|
touch "/run/systemd/rpm/needs-preset/$service" \
|
2017-11-02 16:12:23 +00:00
|
|
|
fi \
|
|
|
|
done \
|
2013-06-20 13:51:16 +00:00
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
2021-02-12 11:01:43 +00:00
|
|
|
# Apply the presets if %pre told us to do so.
|
2020-11-23 17:29:55 +00:00
|
|
|
#
|
2013-06-20 13:51:16 +00:00
|
|
|
%service_add_post() \
|
2019-02-27 12:21:44 +00:00
|
|
|
if [ -x /usr/bin/systemctl ]; then \
|
2021-02-12 11:01:43 +00:00
|
|
|
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 \
|
2013-06-20 13:51:16 +00:00
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
|
|
|
# On uninstall, disable and stop services
|
2016-03-03 10:09:49 +00:00
|
|
|
#
|
2020-11-23 17:29:55 +00:00
|
|
|
%service_del_preun() \
|
2019-03-12 08:20:41 +00:00
|
|
|
if [ $1 -eq 0 -a -x /usr/bin/systemctl ]; then \
|
2015-07-10 08:14:04 +00:00
|
|
|
# Package removal, not upgrade \
|
2020-10-30 17:40:53 +00:00
|
|
|
/usr/bin/systemctl --no-reload disable --now %{?*} || : \
|
2013-06-20 13:51:16 +00:00
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
2019-02-25 09:47:37 +00:00
|
|
|
# On uninstall, tell systemd to reload its unit files.
|
|
|
|
# On update, tell systemd to reload its unit files but don't restart service.
|
|
|
|
#
|
2020-11-10 11:04:59 +00:00
|
|
|
# It ignores the content of /etc/sysconfig/services
|
|
|
|
#
|
2019-02-25 09:47:37 +00:00
|
|
|
%service_del_postun_without_restart() \
|
|
|
|
if [ -x /usr/bin/systemctl ]; then \
|
|
|
|
/usr/bin/systemctl daemon-reload || : \
|
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
2020-11-10 11:04:59 +00:00
|
|
|
# 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}
|
|
|
|
|
2013-06-20 13:51:16 +00:00
|
|
|
# On uninstall, tell systemd to reload its unit files
|
2016-03-03 10:09:49 +00:00
|
|
|
#
|
2020-11-10 11:04:59 +00:00
|
|
|
# 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)
|
2020-11-02 08:55:25 +00:00
|
|
|
#
|
2020-11-02 14:40:43 +00:00
|
|
|
# The default is to read DISABLE_RESTART_ON_UPDATE from /etc/sysconfig/services
|
2016-03-03 10:09:49 +00:00
|
|
|
#
|
|
|
|
%service_del_postun(fn) \
|
2020-11-10 11:04:59 +00:00
|
|
|
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 \
|
2013-06-20 13:51:16 +00:00
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
2019-02-25 09:47:37 +00:00
|
|
|
#
|
|
|
|
# Upstream variants
|
|
|
|
#
|
|
|
|
|
2021-02-12 11:45:54 +00:00
|
|
|
%systemd_pre() %{expand::%%service_add_pre %{?**}}
|
|
|
|
%systemd_post() %{expand::%%service_add_post %{?**}}
|
|
|
|
%systemd_preun() %{expand::%%service_del_preun %{?**}}
|
|
|
|
%systemd_postun() %{expand::%%service_del_postun_without_restart %{?**}}
|
|
|
|
%systemd_postun_with_restart() %{expand::%%service_del_postun %{?**}}
|
2014-11-18 13:57:10 +00:00
|
|
|
|
2018-05-22 12:56:47 +00:00
|
|
|
%systemd_user_post() %{expand:%systemd_post \\--global %%{?*}}
|
2014-11-18 13:57:10 +00:00
|
|
|
|
|
|
|
%systemd_user_preun() \
|
2019-03-12 08:20:41 +00:00
|
|
|
if [ $1 -eq 0 -a -x /usr/bin/systemctl ]; then \
|
2014-11-18 13:57:10 +00:00
|
|
|
# Package removal, not upgrade \
|
2020-11-23 18:03:40 +00:00
|
|
|
/usr/bin/systemctl --global disable %{?*} || : \
|
2014-11-18 13:57:10 +00:00
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
2015-01-12 09:12:57 +00:00
|
|
|
%systemd_user_postun() %{nil}
|
|
|
|
%systemd_user_postun_with_restart() %{nil}
|
|
|
|
|
2013-06-20 13:51:16 +00:00
|
|
|
%udev_hwdb_update() \
|
2015-07-10 08:14:04 +00:00
|
|
|
[ -x /usr/bin/udevadm ] && /usr/bin/udevadm hwdb --update || : \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{nil}
|
|
|
|
|
|
|
|
%udev_rules_update() \
|
2015-07-10 08:14:04 +00:00
|
|
|
[ -x /usr/bin/udevadm ] && /usr/bin/udevadm control --reload || : \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{nil}
|
|
|
|
|
|
|
|
%journal_catalog_update() \
|
2015-07-10 08:14:04 +00:00
|
|
|
[ -x /usr/bin/journalctl ] && /usr/bin/journalctl --update-catalog || : \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{nil}
|
2014-11-18 13:57:10 +00:00
|
|
|
|
|
|
|
%tmpfiles_create() \
|
2017-11-22 14:47:28 +00:00
|
|
|
[ -z "${TRANSACTIONAL_UPDATE}" -a -x /usr/bin/systemd-tmpfiles ] && \
|
2015-07-10 08:14:04 +00:00
|
|
|
/usr/bin/systemd-tmpfiles --create %{?*} || : \
|
2014-11-18 13:57:10 +00:00
|
|
|
%{nil}
|
|
|
|
|
2015-01-12 09:12:57 +00:00
|
|
|
%sysusers_create() \
|
2015-07-10 08:14:04 +00:00
|
|
|
[ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers %{?*} || : \
|
2015-01-12 09:12:57 +00:00
|
|
|
%{nil}
|
|
|
|
|
|
|
|
%sysusers_create_inline() \
|
2015-07-10 08:14:04 +00:00
|
|
|
if [ -x /usr/bin/systemd-sysusers ]; then \
|
|
|
|
echo %{?*} | systemd-sysusers - || : \
|
|
|
|
fi \
|
2015-01-12 09:12:57 +00:00
|
|
|
%{nil}
|
|
|
|
|
2014-11-18 13:57:10 +00:00
|
|
|
%sysctl_apply() \
|
2015-07-10 08:14:04 +00:00
|
|
|
[ -x /usr/lib/systemd/systemd-sysctl ] && \
|
|
|
|
/usr/lib/systemd/systemd-sysctl %{?*} || : \
|
2014-11-18 13:57:10 +00:00
|
|
|
%{nil}
|
|
|
|
|
|
|
|
%binfmt_apply() \
|
2015-07-10 08:14:04 +00:00
|
|
|
[ -x /usr/lib/systemd/systemd-binfmt ] && \
|
|
|
|
/usr/lib/systemd/systemd-binfmt %{?*} || : \
|
2014-11-18 13:57:10 +00:00
|
|
|
%{nil}
|