Accepting request 223099 from home:jsmeix:branches:Printing

Cautious clean up of systemd units via RPM scriptlets (related to bnc#857372)

OBS-URL: https://build.opensuse.org/request/show/223099
OBS-URL: https://build.opensuse.org/package/show/Printing/cups?expand=0&rev=278
This commit is contained in:
Johannes Meixner 2014-02-19 15:37:56 +00:00 committed by Git OBS Bridge
parent ad3ceda791
commit 57b52dd315
2 changed files with 82 additions and 8 deletions

View File

@ -1,3 +1,17 @@
-------------------------------------------------------------------
Wed Feb 19 15:05:44 CET 2014 - jsmeix@suse.de
- Cautious clean up of systemd units via RPM scriptlets:
* When /usr/lib/systemd/system/cups.path and/or
/usr/lib/systemd/system/cups.socket are in use
stop and disable them because they are no longer provided
but keep manually set up cups.path and/or cups.socket units.
* Enforce systemd to use the cups.service file in this package
by "systemctl reenable cups.service" if it was enabled
(intentionally this does not restart a running cupsd).
For details see "rpm -q --scripts cups" and have a look at
http://lists.opensuse.org/opensuse-packaging/2014-02/msg00096.html
-------------------------------------------------------------------
Wed Feb 12 11:53:45 CET 2014 - jsmeix@suse.de

View File

@ -15,6 +15,7 @@
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: cups
BuildRequires: dbus-1-devel
BuildRequires: fdupes
@ -41,13 +42,6 @@ BuildRequires: openslp-devel
BuildRequires: openssl-devel
BuildRequires: pam-devel
BuildRequires: pkgconfig
%if 0%{?suse_version} > 1140
BuildRequires: pkgconfig(systemd)
%{?systemd_requires}
%define have_systemd 1
# may not be defined in older systemd macros..
%{!?_tmpfilesdir: %global _tmpfilesdir /usr/lib/tmpfiles.d }
%endif
# The "BuildRequires: poppler-tools" installs /usr/bin/pdftops for the
# check in config-scripts/cups-pdf.m4 regarding HAVE_PDFTOPS_WITH_ORIGPAGESIZE
# see https://www.cups.org/str.php?L3689
@ -61,8 +55,35 @@ BuildRequires: poppler-tools
BuildRequires: tcpd-devel
BuildRequires: update-desktop-files
BuildRequires: zlib-devel
# See http://en.opensuse.org/openSUSE:Systemd_packaging_guidelines
# that reads as of this writing (Thu Feb 13 12:20:32 CET 2014)
# where here the RPM macro percentage sign is replaced with '@' to be safe:
# Starting with openSUSE 12.1, several RPM macros
# must be used to package systemd services files
# Build Requirement
# You should add :
# @if 0@{?suse_version} >= 1210
# BuildRequires: systemd
# @endif
# as Build Requires.
# Requires
# Add
# @{?systemd_requires}
# to ensure the needed dependencies are added to your package
%if 0%{?suse_version} >= 1210
%define have_systemd 1
%endif
%if 0%{?have_systemd}
BuildRequires: pkgconfig(systemd)
%{?systemd_requires}
# _tmpfilesdir is not defined in systemd macros up to openSUSE 12.3 and
# in openSUSE 13.1 "rpm --eval @{_tmpfilesdir}" results /usr/lib/tmpfiles.d
# (above the RPM macro percentage sign is replaced with '@' to be safe):
%{!?_tmpfilesdir: %global _tmpfilesdir /usr/lib/tmpfiles.d }
%else
PreReq: %insserv_prereq
PreReq: %fillup_prereq
%endif
# sysvinit(syslog) is first provided in openSUSE:Factory (i.e. openSUSE 11.4):
%if 0%{?suse_version} > 1130
PreReq: sysvinit(syslog)
@ -514,6 +535,13 @@ ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rccups
%else
ln -s /sbin/service %{buildroot}%{_sbindir}/rccups
%endif
# For information only:
# When cupsd is launched via systemd there must no longer be any /etc/init.d/cups script
# (e.g. as an attempt to provide backward compatibility e.g. via "exec /usr/sbin/rccups $@")
# because systemd would recognize /etc/init.d/cups as another way to launch cupsd
# in addition to the actual unit file /usr/lib/systemd/system/cups.service
# which means calling "/etc/init.d/cups [start|stop|status]" does no longer work,
# see http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities/
# End launch cupsd via systemd
%else
# Begin launch cupsd via SysVinit:
@ -546,12 +574,36 @@ sed -i -e 's|/var/lock|/run/lock|g' %{buildroot}/etc/init.d/cups
# Use a real bash script with an explicit "exit 0" at the end to be by default fail safe
# an explicit "exit 1" must be use to enforce package install/upgrade/erase failure where needed
# see the "Shared_libraries" section in http://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets
/usr/sbin/groupadd -g 71 -o -r ntadmin 2>/dev/null || :
%if 0%{?have_systemd}
# Cleaning up obsolete systemd units cups.path and cups.socket is only needed up to openSUSE 13.1
# because cups.path and cups.socket are only provided from openSUSE 12.2 up to openSUSE 13.1
# see bnc#857372 starting at https://bugzilla.novell.com/show_bug.cgi?id=857372#c61
%if 0%{?suse_version} <= 1310
# Begin clean up obsolete systemd units cups.path and cups.socket
# Stop and disable systemd units that have been provided by a previous package version but are no longer provided by this package.
# Instead of relying on RPM package upgrade (i.e. when "$1" = "2") the actual files are tested:
for u in cups.path cups.socket
do for f in $( readlink /etc/systemd/system/*/$u )
do if test "$f" = "%{_unitdir}/$u"
then # When /etc/systemd/system/*/$u points into %{_unitdir}/ it means what the distributor (SUSE) provided was used
# (see https://bugzilla.novell.com/show_bug.cgi?id=857372#c26) and then the distributor can clean up his stuff:
echo "stopping and disabling systemd unit $u because %{_unitdir}/$u is longer provided by this cups package"
systemctl --quiet stop $u
systemctl --quiet disable $u
fi
done
done
# End clean up obsolete systemd units cups.path and cups.socket
%endif
# Begin service_add_pre cups.service
%service_add_pre cups.service
# End service_add_pre cups.service
%endif
# See https://bugzilla.novell.com/show_bug.cgi?id=suse45719
# and attr(0775,root,ntadmin) for /usr/share/cups/drivers/ in the files section below
# and the samba.spec file in openSUSE:13.1 for the used command there to be in sync with Samba
# (without "|| :" build fails on SLE_11 and SLE_11_SP1 with "build_patchrpmcheck_scr: line 7: groupadd: command not found"):
getent group ntadmin >/dev/null || groupadd -g 71 -o -r ntadmin || :
exit 0
%post
@ -562,6 +614,14 @@ exit 0
# Begin service_add_post cups.service
%service_add_post cups.service
# End service_add_post cups.service
# Begin refresh systemd unit cups.service
# Be on the safe side and enforce systemd to use the cups.service file in this package
# ("reenable" does not implicitly stop a running cupsd which is exactly correct here):
if systemctl --quiet is-enabled cups.service
then echo "refreshing (reenabling) systemd unit cups.service"
systemctl --quiet reenable cups.service
fi
# End refresh systemd unit cups.service
%else
# Begin fillup_and_insserv -ny cups cups
%{fillup_and_insserv -ny cups cups}