diff --git a/macros.systemd b/macros.systemd index c7ae439..be35537 100644 --- a/macros.systemd +++ b/macros.systemd @@ -18,6 +18,7 @@ # # %postun # %service_del_postun demo.service +# %service_del_postun_without_restart demo.service # %_unitdir /usr/lib/systemd/system @@ -50,33 +51,25 @@ OrderWithRequires(preun): systemd \ OrderWithRequires(postun): systemd \ %{nil} -%_restart_on_update_force() (\ - test "$YAST_IS_RUNNING" = instsys && exit 0 \ - %{?*:/usr/bin/systemctl try-restart %{*}} \ - ) || : %{nil} -%_restart_on_update_never() %{?*:# Restart of %{*} skipped} %{nil} -%_restart_on_update() (\ - test "$YAST_IS_RUNNING" = instsys && exit 0\ - test -f /etc/sysconfig/services -a \\\ - -z "$DISABLE_RESTART_ON_UPDATE" && . /etc/sysconfig/services\ - test "$DISABLE_RESTART_ON_UPDATE" = yes -o \\\ - "$DISABLE_RESTART_ON_UPDATE" = 1 && exit 0\ - %{?*:/usr/bin/systemctl try-restart %{*}}\ - ) || : %{nil} +%_restart_on_update_force() /usr/bin/systemctl try-restart %{*} || : %{nil} +%_restart_on_update_never() : # Restart of %{*} skipped %{nil} -%_stop_on_removal_force() ( \ - test "$YAST_IS_RUNNING" = instsys && exit 0\ - %{?*:/usr/bin/systemctl stop %{*}}\ - ) || : %{nil} -%_stop_on_removal_never() %{?*:# Stop of %{*} skipped} %{nil} -%_stop_on_removal() (\ - test "$YAST_IS_RUNNING" = instsys && exit 0\ - test -f /etc/sysconfig/services -a \\\ - -z "$DISABLE_STOP_ON_REMOVAL" && . /etc/sysconfig/services\ - test "$DISABLE_STOP_ON_REMOVAL" = yes -o \\\ - "$DISABLE_STOP_ON_REMOVAL" = 1 && exit 0\ - %{?*:/usr/bin/systemctl stop %{*}}\ - ) || : %{nil} +%_restart_on_update() \ + test -z "$DISABLE_RESTART_ON_UPDATE" -a -f /etc/sysconfig/services &&\\\ + . /etc/sysconfig/services \ + test "$DISABLE_RESTART_ON_UPDATE" != yes -a "$DISABLE_RESTART_ON_UPDATE" != 1 &&\\\ + /usr/bin/systemctl try-restart %{*} || : \ +%{nil} + +%_stop_on_removal_force() /usr/bin/systemctl stop %{*} || : %{nil} +%_stop_on_removal_never() : # Stop of %{*} skipped} %{nil} + +%_stop_on_removal() \ + test -z "$DISABLE_STOP_ON_REMOVAL" -a -f /etc/sysconfig/services &&\\\ + . /etc/sysconfig/services \ + test "$DISABLE_STOP_ON_REMOVAL" != yes -a "$DISABLE_STOP_ON_REMOVAL" != 1 &&\\\ + /usr/bin/systemctl stop %{*} || : \ +%{nil} %service_add_pre() \ test -n "$FIRST_ARG" || FIRST_ARG="$1" \ @@ -115,9 +108,10 @@ fi \ test -n "$FIRST_ARG" || FIRST_ARG="$1" \ [ -d /var/lib/systemd/migrated ] || mkdir -p /var/lib/systemd/migrated || : \ \ -if [ "$YAST_IS_RUNNING" != "instsys" -a -x /usr/bin/systemctl ]; then \ - /usr/bin/systemctl daemon-reload || : \ +if [ -x /usr/bin/systemctl ]; then \ + /usr/bin/systemctl daemon-reload || : \ fi \ + \ if [ "$FIRST_ARG" -eq 1 ]; then \ if [ -x /usr/bin/systemctl ]; then \ /usr/bin/systemctl preset %{?*} || : \ @@ -164,34 +158,46 @@ if [ "$FIRST_ARG" -eq 0 -a -x /usr/bin/systemctl ]; then \ fi \ %{nil} -# On uninstall, tell systemd to reload its unit files +# On uninstall, tell systemd to reload its unit files. +# On update, tell systemd to reload its unit files but don't restart service. # -# Options used if not in an installation systems -# -f that is fore service restart in removal -# -n that do not touch active service -# the default is to check for DISABLE_RESTART_ON_UPDATE environment -# variable if not found use the value read from /etc/sysconfig/services -# - -%service_del_postun(fn) \ +%service_del_postun_without_restart() \ 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 || : \ - %{expand:%%_restart_on_update%{-f:_force}%{!-f:%{-n:_never}} %{?*}} \ - fi \ -else # package uninstall \ +if [ "$FIRST_ARG" -eq 0 ]; then \ + # Package removal \ for service in %{?*} ; do \ sysv_service="${service%.*}" \ rm -f "/var/lib/systemd/migrated/$sysv_service" || : \ done \ +fi \ +if [ -x /usr/bin/systemctl ]; then \ + /usr/bin/systemctl daemon-reload || : \ +fi \ +%{nil} + +# On uninstall, tell systemd to reload its unit files +# +# Options used if not in an installation systems +# -f that is force service restart in removal (deprecated) +# -n that do not touch active service (depredacted) +# the default is to check for DISABLE_RESTART_ON_UPDATE environment +# variable if not found use the value read from /etc/sysconfig/services +# +%service_del_postun(fn) \ +test -n "$FIRST_ARG" || FIRST_ARG="$1" \ +%service_del_postun_without_restart %{?*} \ +if [ "$FIRST_ARG" -ge 1 ]; then \ + # Package upgrade, not uninstall \ if [ -x /usr/bin/systemctl ]; then \ - /usr/bin/systemctl daemon-reload || : \ + %{expand:%%_restart_on_update%{-f:_force}%{!-f:%{-n:_never}} %{?*}} \ fi \ fi \ %{nil} +# +# Upstream variants +# + %systemd_post() \ if [ $1 -eq 1 -a -x /usr/bin/systemctl ] ; then \ # Initial installation \ diff --git a/systemd-rpm-macros.changes b/systemd-rpm-macros.changes index 6ada8f7..0b42340 100644 --- a/systemd-rpm-macros.changes +++ b/systemd-rpm-macros.changes @@ -1,3 +1,74 @@ +------------------------------------------------------------------- +Fri Mar 1 08:18:07 UTC 2019 - Franck Bui + +- Fix %_restart_on_update_force: drop one extra trailing '}' + + Thanks Werner for spotting. + +------------------------------------------------------------------- +Wed Feb 27 17:43:13 UTC 2019 - Franck Bui + +- Simplify %_restart_on_update and %_stop_on_removal + + There's no need to spawn sub shells when these macros are used. + +------------------------------------------------------------------- +Wed Feb 27 16:57:04 UTC 2019 - Franck Bui + +- Macros arguments are mandatory + + Especially in %_restart_on_update_never and %_stop_on_removal_never, + let's assume that they always receive unit names as arguments. This + allows to make them slightly simpler (less rpm macro black magic). + + Callers will fail earlier if no arguments are passed anyway. + +------------------------------------------------------------------- +Wed Feb 27 14:13:28 UTC 2019 - Franck Bui + +- Make sure %_restart_on_update_never and %_stop_on_removal_never + don't expand to the empty string + + Otherwise sequences like the following would result in incorrect + shell syntax: + + if [ ]; then + %_restart_on_update_never + fi + +------------------------------------------------------------------- +Wed Feb 27 12:17:18 UTC 2019 - Franck Bui + +- Restore one daemon-reload command + + It was erroneously removed during the drop of $YAST_IS_RUNNING. + +------------------------------------------------------------------- +Mon Feb 25 09:55:28 UTC 2019 - Franck Bui + +- Bump version to 4 + +------------------------------------------------------------------- +Thu Feb 22 13:00:18 UTC 2019 - Franck Bui + +- Introduce %service_del_postun_without_restart + + This is another step to make the SUSE rpm macros closer to their + upstream counterparts. + + Introduce %service_del_postun_without_restart which should help in + getting rid of '-f' and '-n' switches of %service_del_postun. + +------------------------------------------------------------------- +Thu Feb 21 17:53:18 UTC 2019 - Franck Bui + +- Drop $YAST_IS_RUNNING in favor of $SYSTEMD_OFFLINE (bsc#1117489) + + libzypp now kindly defines SYSTEMD_OFFLINE when appropriate (see + bsc#1118758). Therefore we don't need to rely on YAST_IS_RUNNING + anymore. It's a tiny step to make the SUSE macros closer to their + upstream counterparts. + ------------------------------------------------------------------- Fri Nov 23 12:08:30 UTC 2018 - Franck Bui diff --git a/systemd-rpm-macros.spec b/systemd-rpm-macros.spec index a28052f..2a2b178 100644 --- a/systemd-rpm-macros.spec +++ b/systemd-rpm-macros.spec @@ -1,7 +1,7 @@ # # spec file for package systemd-rpm-macros # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: systemd-rpm-macros -Version: 3 +Version: 4 Release: 0 Summary: RPM macros for systemd License: LGPL-2.1-or-later