2023-05-09 14:09:13 +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
|
|
|
|
2021-11-17 12:27:43 +00:00
|
|
|
%_systemd_util_dir /usr/lib/systemd
|
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
|
2022-11-23 17:12:56 +00:00
|
|
|
%_user_tmpfilesdir /usr/share/user-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}
|
|
|
|
|
2021-06-30 09:59:17 +00:00
|
|
|
# In case you're wondering why "Suggests:" is also used: libzypp
|
|
|
|
# doesn't understand "OrderWithRequires:" yet, see bsc#1187332 for
|
|
|
|
# details.
|
2018-02-12 16:58:33 +00:00
|
|
|
%systemd_ordering \
|
2021-06-30 09:59:17 +00:00
|
|
|
OrderWithRequires(pre): systemd \
|
2018-02-12 16:58:33 +00:00
|
|
|
OrderWithRequires(post): systemd \
|
|
|
|
OrderWithRequires(preun): systemd \
|
|
|
|
OrderWithRequires(postun): systemd \
|
2021-06-30 09:59:17 +00:00
|
|
|
Suggests: systemd \
|
2018-02-12 16:58:33 +00:00
|
|
|
%{nil}
|
2013-06-20 13:51:16 +00:00
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
%__systemd_someargs_0(:) %{error:The %%%1 macro requires some arguments}
|
|
|
|
%__systemd_twoargs_2() %{nil}
|
|
|
|
|
|
|
|
# Find when presets need to be applied. This information is only recorded during
|
|
|
|
# %pre and is actually applied during %post.
|
2021-02-12 11:01:43 +00:00
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
# Presets might need to be applied during package updates too as new services
|
|
|
|
# might be introduced in this case. Note that on package installations, presets
|
|
|
|
# might have been already applied. This can happen when packages have been
|
|
|
|
# renamed or splitted into sub-packages.
|
2021-02-12 11:01:43 +00:00
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
%service_add_pre() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_add_pre}} \
|
|
|
|
if [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
/usr/lib/systemd/systemd-update-helper mark-install-system-units %{?*} || : \
|
|
|
|
fi \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{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
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
%service_add_post() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_add_post}} \
|
|
|
|
if [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
/usr/lib/systemd/systemd-update-helper install-system-units %{?*} || : \
|
|
|
|
fi \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{nil}
|
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
# On uninstall, disable and stop services.
|
2016-03-03 10:09:49 +00:00
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
%service_del_preun() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_del_preun}} \
|
|
|
|
if [ $1 -eq 0 ] && [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
# Package removal, not upgrade \
|
|
|
|
/usr/lib/systemd/systemd-update-helper remove-system-units %{?*} || : \
|
|
|
|
fi \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{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
|
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
%service_del_postun_without_restart() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_del_postun_without_restart}} \
|
2019-02-25 09:47:37 +00:00
|
|
|
%{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
|
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
%service_del_postun_with_restart() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_del_postun_with_restart}} \
|
|
|
|
if [ $1 -ge 1 ] && [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
# Package upgrade, not uninstall \
|
|
|
|
/usr/lib/systemd/systemd-update-helper mark-restart-system-units %{?*} || : \
|
|
|
|
fi \
|
2020-11-10 11:04:59 +00:00
|
|
|
%{nil}
|
|
|
|
|
2023-03-29 11:35:52 +00:00
|
|
|
# On uninstall, tell systemd to reload its unit files.
|
|
|
|
# On update, tell systemd to reload and restart service unless
|
2023-05-09 14:09:13 +00:00
|
|
|
# DISABLE_RESTART_ON_UPDATE from /etc/sysconfig/services says otherwise.
|
2016-03-03 10:09:49 +00:00
|
|
|
#
|
2023-05-09 14:09:13 +00:00
|
|
|
%service_del_postun() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_del_postun}} \
|
|
|
|
if [ $1 -ge 1 ] && [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
# Package upgrade, not uninstall \
|
|
|
|
DISABLE_RESTART_ON_UPDATE=no \
|
|
|
|
[ -e /etc/sysconfig/services ] && . /etc/sysconfig/services || : \
|
|
|
|
\
|
|
|
|
case "$DISABLE_RESTART_ON_UPDATE" in \
|
|
|
|
yes|1) ;; \
|
|
|
|
*) /usr/lib/systemd/systemd-update-helper mark-restart-system-units %{?*} || : \
|
|
|
|
esac \
|
|
|
|
fi \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{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 %{?**}}
|
2023-03-29 11:35:52 +00:00
|
|
|
%systemd_postun_with_restart() %{expand::%%service_del_postun_with_restart %{?**}}
|
2014-11-18 13:57:10 +00:00
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
#
|
|
|
|
# Variants dealing with user units.
|
|
|
|
#
|
|
|
|
|
|
|
|
%systemd_user_pre() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_pre}} \
|
|
|
|
if [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
/usr/lib/systemd/systemd-update-helper mark-install-user-units %{?*} || : \
|
|
|
|
fi \
|
2021-03-05 11:09:08 +00:00
|
|
|
%{nil}
|
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
%systemd_user_post() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_post}} \
|
|
|
|
if [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
/usr/lib/systemd/systemd-update-helper install-user-units %{?*} || : \
|
|
|
|
fi \
|
2021-03-05 10:58:52 +00:00
|
|
|
%{nil}
|
2014-11-18 13:57:10 +00:00
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
%systemd_user_preun() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \
|
|
|
|
if [ $1 -eq 0 ] && [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
# Package removal, not upgrade \
|
|
|
|
/usr/lib/systemd/systemd-update-helper remove-user-units %{?*} || : \
|
|
|
|
fi \
|
2014-11-18 13:57:10 +00:00
|
|
|
%{nil}
|
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
%systemd_user_postun() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun}} \
|
|
|
|
%{nil}
|
2015-01-12 09:12:57 +00:00
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
%systemd_user_postun_with_restart() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun_with_restart}} \
|
|
|
|
if [ $1 -ge 1 ] && [ -x /usr/lib/systemd/systemd-update-helper ]; then \
|
|
|
|
# Package upgrade, not uninstall \
|
|
|
|
/usr/lib/systemd/systemd-update-helper mark-restart-user-units %{?*} || : \
|
|
|
|
fi \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{nil}
|
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
#
|
|
|
|
# The following macros are empty as we have file triggers in place for hwdb,
|
2023-05-10 09:30:02 +00:00
|
|
|
# journal catalog, udev rules, binfmt and sysctl.
|
2023-05-09 14:09:13 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
%udev_hwdb_update() %{nil}
|
|
|
|
|
|
|
|
%udev_rules_update() %{nil}
|
|
|
|
|
|
|
|
%journal_catalog_update() %{nil}
|
|
|
|
|
2023-05-10 09:30:02 +00:00
|
|
|
# Currently the 2 following macros don't have any interesting users. Leave them
|
|
|
|
# empty until a specific need appears.
|
2023-05-09 14:09:13 +00:00
|
|
|
|
2023-05-10 12:40:05 +00:00
|
|
|
%sysctl_apply() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysctl_apply}} \
|
|
|
|
%{nil}
|
2023-05-09 14:09:13 +00:00
|
|
|
|
2023-05-10 12:40:05 +00:00
|
|
|
%binfmt_apply() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# binfmt_apply}} \
|
|
|
|
%{nil}
|
2013-06-20 13:51:16 +00:00
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
#
|
|
|
|
# Since we moved to file triggers the 2 following macros are deprecated. If the
|
|
|
|
# sysusers or tmpfiles data need to be created in advance (when a system user
|
|
|
|
# needs to be installed in %%pre so proper ownership are used when package's
|
|
|
|
# files are installed for example) then use the '*_create_package()' variants.
|
|
|
|
#
|
|
|
|
|
|
|
|
%tmpfiles_create() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# tmpfiles_create}} \
|
2023-05-10 09:30:02 +00:00
|
|
|
[ -d /run/systemd/system ] && [ -x /usr/bin/systemd-tmpfiles ] && \
|
2023-05-09 14:09:13 +00:00
|
|
|
/usr/bin/systemd-tmpfiles --create %{?*} || : \
|
2013-06-20 13:51:16 +00:00
|
|
|
%{nil}
|
2014-11-18 13:57:10 +00:00
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
%sysusers_create() \
|
|
|
|
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysusers_create}} \
|
|
|
|
[ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers %{?*} || : \
|
2014-11-18 13:57:10 +00:00
|
|
|
%{nil}
|
|
|
|
|
2021-05-20 10:17:34 +00:00
|
|
|
# This may be used by package installation scripts to create files according to
|
|
|
|
# their tmpfiles configuration from a package installation script, even before
|
|
|
|
# the files of that package are installed on disk.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# Source1: %{name}-tmpfiles.conf
|
|
|
|
# ...
|
|
|
|
# %install
|
|
|
|
# install -D %SOURCE1 %{buildroot}%{_tmpfilesdir}/%{name}.conf
|
|
|
|
# %pre
|
|
|
|
# %tmpfiles_create_package %{name} %SOURCE1
|
|
|
|
# %files
|
|
|
|
# %{_tmpfilesdir}/%{name}.conf
|
|
|
|
#
|
|
|
|
%tmpfiles_create_package() \
|
2023-05-09 14:09:13 +00:00
|
|
|
%{expand:%%{?!__systemd_twoargs_%#:%%{error:The %%%%tmpfiles_create_package macro requires two arguments}}} \
|
2023-05-10 09:30:02 +00:00
|
|
|
[ -d /run/systemd/system ] && \
|
2021-05-20 10:17:34 +00:00
|
|
|
/usr/bin/systemd-tmpfiles --replace=%_tmpfilesdir/%1.conf --create - <<SYSTEMD_INLINE_EOF || : \
|
|
|
|
%(cat %2) \
|
|
|
|
SYSTEMD_INLINE_EOF\
|
2022-10-03 13:00:50 +00:00
|
|
|
fi \
|
2021-05-20 10:17:34 +00:00
|
|
|
%{nil}
|
|
|
|
|
|
|
|
# This should be used by package installation scripts which require users or
|
|
|
|
# groups to be present before the files installed by the package are present on
|
|
|
|
# disk (for example because some files are owned by those users or groups).
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# Source1: %{name}-sysusers.conf
|
2023-05-09 14:09:13 +00:00
|
|
|
# ...
|
|
|
|
# %install
|
2021-05-20 10:17:34 +00:00
|
|
|
# install -D %SOURCE1 %{buildroot}%{_sysusersdir}/%{name}.conf
|
|
|
|
# %pre
|
|
|
|
# %sysusers_create_package %{name} %SOURCE1
|
|
|
|
# %files
|
|
|
|
# %{_sysusersdir}/%{name}.conf
|
|
|
|
#
|
|
|
|
%sysusers_create_package() \
|
2023-05-09 14:09:13 +00:00
|
|
|
%{expand:%%{?!__systemd_twoargs_%#:%%{error:The %%%%sysusers_create_package macro requires two arguments}}} \
|
|
|
|
[ -x /usr/bin/systemd-sysusers ] && \
|
|
|
|
/usr/bin/systemd-sysusers --replace=%_sysusersdir/%1.conf - <<SYSTEMD_INLINE_EOF || : \
|
2021-05-20 10:17:34 +00:00
|
|
|
%(cat %2) \
|
|
|
|
SYSTEMD_INLINE_EOF\
|
|
|
|
%{nil}
|
|
|
|
|
2023-05-09 14:09:13 +00:00
|
|
|
# Deprecated. Use %sysusers_create_package instead
|
|
|
|
%sysusers_create_inline() \
|
|
|
|
[ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers - <<SYSTEMD_INLINE_EOF || : \
|
|
|
|
%{?*} \
|
|
|
|
SYSTEMD_INLINE_EOF\
|
2014-11-18 13:57:10 +00:00
|
|
|
%{nil}
|