# -*- 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 # # 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. %_systemd_util_dir /usr/lib/systemd %_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 %_user_tmpfilesdir /usr/share/user-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} # In case you're wondering why "Suggests:" is also used: libzypp # doesn't understand "OrderWithRequires:" yet, see bsc#1187332 for # details. %systemd_ordering \ OrderWithRequires(pre): systemd \ OrderWithRequires(post): systemd \ OrderWithRequires(preun): systemd \ OrderWithRequires(postun): systemd \ Suggests: systemd \ %{nil} %__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. # # 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. # %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 \ %{nil} # Apply the presets if %pre told us to do so. # %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 \ %{nil} # On uninstall, disable and stop services. # %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 \ %{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() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# service_del_postun_without_restart}} \ %{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() \ %{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 \ %{nil} # On uninstall, tell systemd to reload its unit files. # On update, tell systemd to reload and restart service unless # DISABLE_RESTART_ON_UPDATE from /etc/sysconfig/services says otherwise. # %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 \ %{nil} # # Upstream variants # %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_with_restart %{?**}} # # 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 \ %{nil} %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 \ %{nil} %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 \ %{nil} %systemd_user_postun() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun}} \ %{nil} %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 \ %{nil} # # The following macros are empty as we have file triggers in place for hwdb, # journal catalog, udev rules, binfmt and sysctl. # %udev_hwdb_update() %{nil} %udev_rules_update() %{nil} %journal_catalog_update() %{nil} # Currently the 2 following macros don't have any interesting users. Leave them # empty until a specific need appears. %sysctl_apply() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysctl_apply}} \ %{nil} %binfmt_apply() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# binfmt_apply}} \ %{nil} # # 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}} \ [ -d /run/systemd/system ] && [ -x /usr/bin/systemd-tmpfiles ] && \ /usr/bin/systemd-tmpfiles --create %{?*} || : \ %{nil} %sysusers_create() \ %{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysusers_create}} \ [ -x /usr/bin/systemd-sysusers ] && /usr/bin/systemd-sysusers %{?*} || : \ %{nil} # 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() \ %{expand:%%{?!__systemd_twoargs_%#:%%{error:The %%%%tmpfiles_create_package macro requires two arguments}}} \ [ -d /run/systemd/system ] && \ /usr/bin/systemd-tmpfiles --replace=%_tmpfilesdir/%1.conf --create - <