File sapconf.spec of Package sapconf.14472

#
# spec file for package sapconf
#
# Copyright (c) 2019-2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif

Name:           sapconf
Version:        4.2.3
Release:        0
Summary:        Kernel Parameter Initializiation for SAP Systems
License:        LGPL-2.1-or-later
Group:          Productivity/Other
Url:            https://www.suse.com/partners/alliance/sap/
PreReq:         %fillup_prereq
Source0:        %name-%version.tar.gz
BuildArch:      noarch
BuildRequires:  tuned
Requires:       bc
Requires:       systemd >= 234-24.42
Requires:       sysstat
Requires:       tuned
Requires:       uuidd
Suggests:       cron logrotate
%{?systemd_requires}

%description 
The utility adjusts operating system parameters, such as kernel 
tuning settings and resource limits, to allow running various
SAP solutions at satisfactory performance.

Authors:
--------
    Angela Briel, Howard Guo

%prep
%setup -q

%build

%install
mkdir -p %{buildroot}%{_libexecdir}/tuned/
cp -R profile/* %{buildroot}%{_libexecdir}/tuned/
mkdir -p %{buildroot}%{_libexecdir}/%{name}/
install -m 0644 lib/common.sh %{buildroot}%{_libexecdir}/%{name}/
install -m 0644 lib/util.sh %{buildroot}%{_libexecdir}/%{name}/
install -m 0755 lib/sccu.sh %{buildroot}%{_libexecdir}/%{name}/

mkdir -p %{buildroot}%{_unitdir}/systemd/system/ %{buildroot}%{_sbindir}/
install -m 0644 sapconf.service %{buildroot}%{_unitdir}/
ln -s /usr/sbin/service %{buildroot}%{_sbindir}/rcsapconf

mkdir -p %{buildroot}%{_mandir}/{man5,man7}/
install -m 0644 man/*.5 %{buildroot}%{_mandir}/man5/
install -m 0644 man/*.7 %{buildroot}%{_mandir}/man7/

mkdir -p %{buildroot}/%{_fillupdir}/
pushd sysconfig
for file in *; do
    cp "$file" "%{buildroot}/%{_fillupdir}/sysconfig.$file"
done
popd

%pre
%service_add_pre sapconf.service
if [ $1 -ne 1 ]; then
    # package update
    # fix a problem with former post install of version 4.2.0
    if [ -f %{_fillupdir}/sysconfig.sapconf ]; then
        if ! (grep "The following lines are only for documentation purpose" /etc/sysconfig/sapconf >/dev/null 2>&1); then
            echo -e "\n" >> /etc/sysconfig/sapconf
            sed -n "/^####.*##$/,/^#SAPCONF_END.*/p" %{_fillupdir}/sysconfig.sapconf >> /etc/sysconfig/sapconf
        fi
    fi
fi

%post
if [ $1 -eq 1 ]; then
    # package initial install
    # to preserve the trailing comments, use /bin/fillup -t instead of
    # macro fillup_only
    echo "Updating /etc/sysconfig/sapconf ..."
    touch /etc/sysconfig/sapconf || :
    /bin/fillup -q -t %{_fillupdir}/sysconfig.sapconf /etc/sysconfig/sapconf /etc/sysconfig/sapconf || :
    touch /tmp/initial_sapconf_inst || :
else
    # package update
    if [ -f /etc/sysconfig/sapnote-1557506 ]; then
        # covers updates from SLE12 sapconf versions < 4.1.12
        mv /etc/sysconfig/sapconf /etc/sysconfig/sapconf.rpmsave || true
        # to preserve the trailing comments, use /bin/fillup -t instead of
        # macro fillup_only
        echo "Updating /etc/sysconfig/sapconf ..."
        touch /etc/sysconfig/sapconf || :
        /bin/fillup -q -t %{_fillupdir}/sysconfig.sapconf /etc/sysconfig/sapconf /etc/sysconfig/sapconf || :
        # remove no longer needed 'pagecache' sysconfig file
        rm -f /etc/sysconfig/sapnote-1557506 || true
        # remove no longer needed 'ase' sysconfig file
        rm -f /etc/sysconfig/sapnote-1680803 || true
    elif [ -f /etc/sysconfig/sapnote-1680803 ]; then
        # covers updates from SLE12 sapconf versions >= 4.1.12
        # adjust comments, not covered by fillup
        sed -n "/## Path:.*/,/##.*integration of sapconf./p" %{_fillupdir}/sysconfig.sapconf > /etc/sysconfig/sapconf.new.$$
        sed "/## Path:.*Other.*/,/## integration of sapconf./d" /etc/sysconfig/sapconf >> /etc/sysconfig/sapconf.new.$$
        mv /etc/sysconfig/sapconf.new.$$ /etc/sysconfig/sapconf || true
        # remove pagecache section from sapconf sysconfig file
        # no longer supported in SLE15
        sed -i '/## Path:           SAP\/Note\/1557506 - Linux paging improvements/,/.*PAGECACHE_LIMIT_IGNORE_DIRTY[[:blank:]]*=.*/d' /etc/sysconfig/sapconf
        sed -i '/.*PAGECACHE_LIMIT_IGNORE_DIRTY[[:blank:]]*=.*/d' /etc/sysconfig/sapconf

        # bsc#1096496/bsc#1096498
        # to update the comment sections in /etc/sysconfig/sapconf
        # does not work with /bin/fillup, but is mandatory for SAP
        %{_libexecdir}/%{name}/sccu.sh || :

        echo "Updating /etc/sysconfig/sapconf ..."
        /bin/fillup -q -t /etc/sysconfig/sapconf %{_fillupdir}/sysconfig.sapconf
        # remove no longer needed 'ase' sysconfig file
        rm -f /etc/sysconfig/sapnote-1680803 || true
    else
        # covers updates from SLE15
        # bsc#1096496/bsc#1096498
        # to update the comment sections in /etc/sysconfig/sapconf
        # does not work with /bin/fillup, but is mandatory for SAP
        %{_libexecdir}/%{name}/sccu.sh || :

        echo "Updating /etc/sysconfig/sapconf ..."
        /bin/fillup -q -t /etc/sysconfig/sapconf %{_fillupdir}/sysconfig.sapconf
    fi
    %{remove_and_set -n sapconf SEMMSL SEMMNS SEMOPM SEMMNI}

    # move old sapconf profiles sap-hana, sap-netweaver, sap-ase and sap-bobj to
    # the new sapconf profile 'sapconf'
    # works without problems as long as the tuned package does not ship the 
    # upstream sap- profiles.
    [[ $(cat /etc/tuned/active_profile) == sap-* ]] && echo sapconf > /etc/tuned/active_profile || true
fi
sed -i '/^[^#].*[[:blank:]][[:blank:]]*=[[:blank:]][[:blank:]]*.*/s;[[:blank:]];;g' /etc/sysconfig/sapconf >/dev/null 2>&1 || true
%service_add_post sapconf.service

# Amend logind's behaviour (bsc#1031355, bsc#1039309, bsc#1043844), there is no rollback.
# Not needed any longer as the limit is removed from logind (jsc#SLE-10123)
SAP_LOGIN_FILE=/etc/systemd/logind.conf.d/sap.conf
if [ -f $SAP_LOGIN_FILE ]; then
    echo "removing no longer needed file '$SAP_LOGIN_FILE'"
    rm -rf $SAP_LOGIN_FILE || :
fi
# remove UserTasksMax section from sapconf sysconfig file
# no longer needed in SLE15
sed -i '/# .*UserTasksMax setting$/,/# A message will indicate .*/d' /etc/sysconfig/sapconf || true


%preun
%service_del_preun sapconf.service
test -n "$FIRST_ARG" || FIRST_ARG=$1
if [ $FIRST_ARG -eq 0 ]; then
    # Package removal, not upgrade
    # to suppress error messags from tuned, if the current active profile is
    # a removed sapconf profile
    (systemctl -q is-active tuned && [[ $(cat /etc/tuned/active_profile) == sapconf ]] ) && (/usr/bin/systemctl stop tuned.service >/dev/null 2>&1;  > /etc/tuned/active_profile) || true
fi

%postun
%service_del_postun sapconf.service

%posttrans -p /bin/bash
# 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
# Begin refresh systemd units and clean up possibly obsolete systemd units
# The following is a generic way how to refresh and/or clean up systemd units.
# A systemd unit may need a refresh after updating a package when the new package
# had installed a changed systemd unit file for an enabled systemd unit.
# A systemd unit may become obsolete by updating a package (see bnc#904215).
# A systemd unit is considered to have become obsolete when the systemd
# symlink /etc/systemd/system/.../unit_name -> /path/to/unit_file is broken.
# When during package update the new package does no longer provide a unit file
# then the systemd symlink becomes broken after the files of the old package
# had been actually removed by RPM.
# According to /usr/share/doc/packages/rpm/manual/triggers and according
# to https://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets#Scriptlet_Ordering
# and http://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Scriptlet_Ordering
# from the new package only "posttrans of new package" is run after "removal of old package"
# so that the new package must do the clean up as RPM posttrans scriptlet.
if systemctl --quiet is-enabled sapconf.service 2>/dev/null; then
    # Refresh still valid enabled systemd units and clean up possibly obsoleted systemd units:
    # Enforce systemd to use the current unit file which is usually the unit file of the new package
    # but also in case of custom units (that use other unit files) a "reenable" won't hurt because
    # "reenable" does not implicitly stop a running service which is "the right thing" because
    # a RPM package installation must not automatically disrupt (restart) a running service.
    # Using "--force reenable" is essential to clean up possibly conflicting/broken symlinks.
    # (without "|| :" build fails with "Failed to get D-Bus connection: No connection to service manager. posttrans script ... failed"):
    systemctl --quiet --force reenable sapconf.service 2>/dev/null || :
else
    # Refresh still valid disabled systemd units and clean up possibly obsoleted systemd units:
    # First using "--force reenable" is essential to clean up possibly conflicting/broken symlinks
    # because there is no "--force disable" that would clean up possibly conflicting/broken symlinks
    # see https://bugzilla.opensuse.org/show_bug.cgi?id=904215#c34
    # so that first the unit has a clean state and then it is set back to disabled (as it was before).
    # If a disabled systemd unit has become obsoleted, "systemctl --force reenable" will clean it up
    # which means the unit gets removed and the subsequent "systemctl disable" will do nothing.
    # (without "|| :" build fails with "Failed to get D-Bus connection: No connection to service manager. posttrans script ... failed"):
    systemctl --quiet --force reenable sapconf.service 2>/dev/null || :
    systemctl --quiet disable sapconf.service 2>/dev/null || :
fi
if [ -f /tmp/initial_sapconf_inst ]; then
    # package initial install
    rm -f /tmp/initial_sapconf_inst || :
    [[ $(cat /etc/tuned/active_profile) == "" ]] && systemctl start sapconf.service || :
else
    # package update
    (systemctl -q is-active sapconf && [[ $(cat /etc/tuned/active_profile) == sapconf ]] ) && systemctl reload sapconf.service || :
fi
exit 0

%files 
%defattr(-,root,root)
%{_sbindir}/rcsapconf
%{_unitdir}/sapconf.service
%{_libexecdir}/tuned/sap*
%dir %{_libexecdir}/%{name}
%{_libexecdir}/%{name}/*
%{_mandir}/man*/*
%{_fillupdir}/*

%changelog
openSUSE Build Service is sponsored by