systemd-rpm-macros/macros.systemd

353 lines
10 KiB
Plaintext

# -*- Mode: makefile; 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
#
###
#
# When a package install systemd preset files, it should use the following macros:
#
# %pre -p /bin/bash
# %systemd_preset_pre
#
# %posttrans -p /bin/bash
# %systemd_preset_posttrans
#
###
# This is for systemctl
%systemd_requires \
Requires(pre): systemd \
Requires(post): systemd \
Requires(preun): systemd \
Requires(postun): systemd \
%_unitdir /usr/lib/systemd/system
%_userunitdir /usr/lib/systemd/user
%_presetdir /usr/lib/systemd/system-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
%_restart_check_systemctl \
test -f /etc/sysconfig/services && . /etc/sysconfig/services \
test "$YAST_IS_RUNNING" = instsys && exit 0 \
test "$DISABLE_RESTART_ON_UPDATE" = yes && exit 0 \
/usr/bin/systemctl try-restart %{nil}
%_stop_check_systemctl \
test -f /etc/sysconfig/services && . /etc/sysconfig/services \
test "$YAST_IS_RUNNING" = instsys && exit 0 \
test "$DISABLE_STOP_ON_REMOVAL" = yes && exit 0 \
/usr/bin/systemctl stop %{nil}
%service_add_pre() \
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
# disable migration if initial install under systemd \
[ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || : \
if [ "$FIRST_ARG" -eq 1 ]; then \
for service in %{?*} ; do \
sysv_service="${service%%.*}" \
touch "/var/lib/systemd/migrated/$sysv_service" || : \
done \
else \
if [ "$FIRST_ARG" -gt 1 ]; then \
for service in %{?*} ; do \
if [ ! -e "/usr/lib/systemd/system/$service" ]; then \
touch "/run/rpm-%{name}-update-$service-new-in-upgrade" \
fi \
done \
fi \
for service in %{?*} ; do \
sysv_service="${service%%.*}" \
if [ ! -e "/var/lib/systemd/migrated/$sysv_service" ]; then \
services_to_migrate="$services_to_migrate $sysv_service" \
fi \
done \
if [ -n "$services_to_migrate" -a -x /usr/sbin/systemd-sysv-convert ]; then \
/usr/sbin/systemd-sysv-convert --save $services_to_migrate || : \
fi \
fi \
%{nil}
# On install, tell systemd to reload its unit files
%service_add_post() \
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
[ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || : \
for service in %{?*} ; do \
sysv_service="${service%%.*}" \
if [ ! -e "/var/lib/systemd/migrated/$sysv_service" ]; then \
services_to_migrate="$services_to_migrate $sysv_service" \
touch "/var/lib/systemd/migrated/$sysv_service" || : \
fi \
done \
if [ -x /usr/bin/systemctl ]; then \
/usr/bin/systemctl daemon-reload || : \
fi \
if [ -n "$services_to_migrate" ]; then \
if [ -x /usr/sbin/systemd-sysv-convert ]; then \
/usr/sbin/systemd-sysv-convert --apply $services_to_migrate || : \
fi \
elif [ "$FIRST_ARG" -eq 1 ]; then \
if [ -x /usr/bin/systemctl ]; then \
/usr/bin/systemctl preset %{?*} || : \
fi \
elif [ "$FIRST_ARG" -gt 1 ]; then \
for service in %{?*} ; do \
if [ ! -e "/run/rpm-%{name}-update-$service-new-in-upgrade" ]; then \
continue \
fi \
rm -f "/run/rpm-%{name}-update-$service-new-in-upgrade" \
if [ ! -x /usr/bin/systemctl ]; then \
continue \
fi \
/usr/bin/systemctl preset "$service" || : \
done \
fi \
%{nil}
# On uninstall, disable and stop services
%service_del_preun() \
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
if [ "$FIRST_ARG" -eq 0 -a -x /usr/bin/systemctl ]; then \
# Package removal, not upgrade \
/usr/bin/systemctl --no-reload disable %{?*} || : \
( %_stop_check_systemctl %{?*} || : ) \
fi \
%{nil}
# On uninstall, tell systemd to reload its unit files
%service_del_postun() \
test -n "$FIRST_ARG" || FIRST_ARG="$1" \
if [ "$FIRST_ARG" -ge 1 ]; then \
# Package upgrade, not uninstall \
if [ -x /usr/bin/systemctl ]; then \
/usr/bin/systemctl daemon-reload || : \
( %_restart_check_systemctl %{?*} || : ) \
fi \
else # package uninstall \
for service in %{?*} ; do \
sysv_service="${service%.*}" \
rm -f "/var/lib/systemd/migrated/$sysv_service" || : \
done \
if [ -x /usr/bin/systemctl ]; then \
/usr/bin/systemctl daemon-reload || : \
fi \
fi \
%{nil}
%systemd_post() \
if [ "$1" -eq 0 -a -x /usr/bin/systemctl ]; then \
# Package removal, not upgrade \
/usr/bin/systemctl --no-reload disable %{?*} || : \
( %_stop_check_systemctl %{?*} || : ) \
fi \
%{nil}
%systemd_user_post() %systemd_post --user --global %{?*}
%systemd_preun() \
if [ "$1" -eq 0 -a -x /usr/bin/systemctl ]; then \
# Package removal, not upgrade \
/usr/bin/systemctl --no-reload disable %{?*} || : \
( %_stop_check_systemctl %{?*} || : ) \
fi \
%{nil}
%systemd_user_preun() \
if [ "$1" -eq 0 -a -x /usr/bin/systemctl ]; then \
# Package removal, not upgrade \
/usr/bin/systemctl --no-reload --user --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() \
[ -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}
%systemd_preset_pre() \
if ! test -f /usr/lib/systemd/system-preset/99-default-disable.preset ; then \
mkdir -p /usr/lib/systemd/system-preset; \
touch /usr/lib/systemd/system-preset/systemd_preset-skip.rpm-tmp; \
else \
cd /usr/lib/systemd/system-preset; \
declare -a PRESET_FILES; \
declare -A PRESETS; \
PRESET_FILES=(*.preset); \
if ! test -f systemd_preset-old.rpm-tmp ; then \
for ((i=${#PRESET_FILES[@]}-1 ; i>= 0 ; i-- )) ; do \
FILE=${PRESET_FILES[i]}; \
exec 3<"$FILE"; \
while read -u3 ENABLE SERVICE PAD ; do \
if test -z "$SERVICE" ; then \
continue; \
fi; \
case "$ENABLE" in \
enable|disable) \
PRESETS[$SERVICE]=$ENABLE;; \
esac; \
done; \
exec 3<&-; \
done; \
exec 3>systemd_preset-old.rpm-tmp; \
for PRESET in "${!PRESETS[@]}" ; do \
echo >&3 "${PRESETS[$PRESET]} $PRESET"; \
done; \
exec 3>&-; \
fi; \
fi; \
%{nil}
%systemd_preset_posttrans() \
if test -f /usr/lib/systemd/system-preset/systemd_preset-skip.rpm-tmp ; then \
rm -f /usr/lib/systemd/system-preset/systemd_preset-{old,skip}.rpm-tmp; \
fi; \
cd /usr/lib/systemd/system-preset; \
if test -f systemd_preset-old.rpm-tmp ; then \
declare -a PRESET_FILES; \
declare -A PRESETS_OLD; \
declare -A PRESETS_OLD_WILDCARD; \
declare -A PRESETS; \
declare -A PRESETS_WILDCARD; \
exec 3<systemd_preset-old.rpm-tmp; \
while read -u3 ENABLE SERVICE PAD ; do \
if test -z "$SERVICE" ; then \
continue; \
fi; \
case "$ENABLE" in \
enable|disable) \
case $SERVICE in \
*"*"*|*"?"*) PRESETS_OLD_WILDCARD[$SERVICE]=$ENABLE;; \
*) PRESETS_OLD[$SERVICE]=$ENABLE;; \
esac;; \
esac; \
done; \
exec 3<&-; \
PRESET_FILES=(*.preset); \
for ((i=${#PRESET_FILES[@]}-1 ; i>= 0 ; i-- )) ; do \
FILE=${PRESET_FILES[i]}; \
exec 3<"$FILE"; \
while read -u3 ENABLE SERVICE PAD ; do \
if test -z "$SERVICE" ; then \
continue; \
fi; \
case "$ENABLE" in \
enable|disable) \
case $SERVICE in \
*"*"*|*"?"*) PRESETS_WILDCARD[$SERVICE]=$ENABLE;; \
*) PRESETS[$SERVICE]=$ENABLE;; \
esac;; \
esac; \
done; \
exec 3<&-; \
done; \
if test -x /usr/bin/systemctl ; then \
/usr/bin/systemctl --type=service,socket list-unit-files; \
fi >systemd_preset-states.rpm-tmp; \
exec 3<systemd_preset-states.rpm-tmp; \
read -u3 PAD; \
while read -u3 SERVICE ENABLE PAD ; do \
if test -z "$SERVICE" ; then \
break; \
fi; \
ENABLE_OLD=enable; \
for PRESET in "${!PRESETS_OLD_WILDCARD[@]}" ; do \
case "$SERVICE" in \
$PRESET) ENABLE_OLD=${PRESETS_OLD_WILDCARD[$PRESET]};; \
esac; \
done; \
if test -n "${PRESETS_OLD[$SERVICE]}" ; then \
ENABLE_OLD="${PRESETS_OLD[$SERVICE]}"; \
fi; \
ENABLE_NEW=enable; \
for PRESET in "${!PRESETS_WILDCARD[@]}" ; do \
case "$SERVICE" in \
$PRESET) ENABLE_NEW=${PRESETS_WILDCARD[$PRESET]};; \
esac; \
done; \
if test -n "${PRESETS[$SERVICE]}" ; then \
ENABLE_NEW="${PRESETS[$SERVICE]}"; \
fi; \
if test "$ENABLE_OLD" != "$ENABLE_NEW" ; then \
echo "Resetting $SERVICE to the new default: $ENABLE_NEW"; \
/usr/bin/systemctl preset "$SERVICE" || :; \
fi; \
done; \
exec 3<&-; \
rm -f systemd_preset-old.rpm-tmp systemd_preset-states.rpm-tmp; \
fi; \
%{nil}