forked from pool/systemd-rpm-macros
Accepting request 320474 from home:sbrabec:branches:systemd-preset
- Add %systemd_preset_pre and %systemd_preset_posttrans that will do one shot presetting of all services with changed system preset. It makes possible to to fix bad default service state (bnc#900935#c46, FATE#318949, FATE#317727, bnc#921075). - Increment version to 3. OBS-URL: https://build.opensuse.org/request/show/320474 OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd-rpm-macros?expand=0&rev=10
This commit is contained in:
parent
a40b70d414
commit
5f77f48552
117
macros.systemd
117
macros.systemd
@ -18,7 +18,17 @@
|
||||
#
|
||||
# %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
|
||||
@ -216,3 +226,108 @@ fi \
|
||||
[ -x /usr/lib/systemd/systemd-binfmt ] && \
|
||||
/usr/lib/systemd/systemd-binfmt %{?*} || : \
|
||||
%{nil}
|
||||
|
||||
%systemd_preset_pre() \
|
||||
cd /usr/lib/systemd/system-preset; \
|
||||
declare -a PRESET_FILES; \
|
||||
declare -A PRESETS; \
|
||||
PRESET_FILES=(*.preset); \
|
||||
if ! test -f presets-all.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>presets-all.rpm-tmp; \
|
||||
for PRESET in "${!PRESETS[@]}" ; do \
|
||||
echo >&3 "${PRESETS[$PRESET]} $PRESET"; \
|
||||
done; \
|
||||
exec 3>&-; \
|
||||
fi; \
|
||||
%{nil}
|
||||
|
||||
%systemd_preset_posttrans() \
|
||||
cd /usr/lib/systemd/system-preset; \
|
||||
declare -a PRESET_FILES; \
|
||||
declare -A PRESETS_OLD; \
|
||||
declare -A PRESETS_OLD_WILDCARD; \
|
||||
declare -A PRESETS; \
|
||||
declare -A PRESETS_WILDCARD; \
|
||||
if test -f presets-all.rpm-tmp ; then \
|
||||
exec 3<presets-all.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 >service-states.rpm-tmp; \
|
||||
exec 3<service-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 presets-all.rpm-tmp service-states.rpm-tmp; \
|
||||
fi; \
|
||||
%{nil}
|
||||
|
@ -1,3 +1,12 @@
|
||||
-------------------------------------------------------------------
|
||||
Tue Aug 4 17:59:54 CEST 2015 - sbrabec@suse.com
|
||||
|
||||
- Add %systemd_preset_pre and %systemd_preset_posttrans that will
|
||||
do one shot presetting of all services with changed system
|
||||
preset. It makes possible to to fix bad default service state
|
||||
(bnc#900935#c46, FATE#318949, FATE#317727, bnc#921075).
|
||||
- Increment version to 3.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Mon Jun 15 11:33:28 UTC 2015 - jengelh@inai.de
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
Name: systemd-rpm-macros
|
||||
Version: 2
|
||||
Version: 3
|
||||
Release: 0
|
||||
Summary: RPM macros for systemd
|
||||
License: LGPL-2.1+
|
||||
|
Loading…
x
Reference in New Issue
Block a user