File zookeeper.spec of Package zookeeper

# spec file for package zookeeper
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
# 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

Name:           zookeeper
Version:        3.4.13
Release:        0
License:        Apache-2.0
Summary:        A high-performance coordination service for distributed applications
Group:          Development/Libraries/Java
Vendor:         Apache Software Foundation
Source1:        %{name}.service
Source2:        zookeeper-wrapper
Source3:        zookeeper.logrotate
Source4:        README.SUSE
Patch0:         ftbfs-with-gcc-8.patch
Patch1:         0002-Apply-patch-to-resolve-CVE-2019-0201.patch
BuildRequires:  cppunit-devel
BuildRequires:  java-devel
BuildRequires:  %{name}-kit == %{version}
%if 0%{?suse_version} >= 1210
BuildRequires:  systemd-rpm-macros
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-build

ZooKeeper is a centralized service for maintaining configuration
information, naming, providing distributed synchronization, and
providing group services. All of these kinds of services are used in
some form or another by distributed applications. Each time they are
implemented there is a lot of work that goes into fixing the bugs and
race conditions that are inevitable. Because of the difficulty of
implementing these kinds of services, applications initially usually
skimp on them ,which make them brittle in the presence of change and
difficult to manage. Even when done correctly, different
implementations of these services lead to management complexity when
the applications are deployed. This package contains the server-side
components of ZooKeeper.

%package server
Summary: Zookeeper server
Requires: java-1_8_0-openjdk
Requires: logrotate
BuildArch: noarch

%description server
This package contains the ZooKeeper server.

%package client
Summary: Zookeeper CLI clients
Requires: libzookeeper2 = %{version}

%description client
This package contains the single-threaded (zkcli_st) and multi-threaded
(zkcli_mt) command line clients for Zookeeper.

%package -n libzookeeper2
Summary: Zookeeper C client library

%description -n libzookeeper2
This package contains C client libraries for ZooKeeper.

%package -n libzookeeper2-devel
Summary: Development files for the ZooKeeper C client library
Requires: libzookeeper2 = %{version}

%description -n libzookeeper2-devel
This package contains the ZooKeeper client library's C headers and objects for
static linking.

%setup -q
%patch0 -p1
%patch1 -p1
cp -Rf %{_datadir}/tetra ../kit
cp -f %{SOURCE5} ../

echo -e '\n' >> bin/

cat >> bin/ << 'EOF'

for i in $(find $ZKLIB -name '*.jar')

# Set log files
sed -i -e 's#^zookeeper.log.dir=.*#zookeeper.log.dir=%{_localstatedir}/log/%{name}#' \
       -e 's#^zookeeper.tracelog.dir=.*#zookeeper.tracelog.dir=%{_localstatedir}/log/%{name}#' \

# Switch logging to file
echo 'log4j.rootLogger=INFO, ROLLINGFILE' >> conf/

sed -i 's#^dataDir=.*#dataDir=%{_localstatedir}/lib/%{name}/data#' conf/zoo_sample.cfg
sed -i -e 's#__CONFDIR__#%{_sysconfdir}/%{name}#' \
       -e 's#__LOGDIR__#%{_localstatedir}/log/%{name}#' \
       -e 's#__BINDIR__#%{_libexecdir}/%{name}#' \
       -e 's#__ZKLIB__#%{_javadir}/%{name}#' \

sed -e 's#__CONFDIR__#%{_sysconfdir}/%{name}#g' \
    -e 's#__LIBEXECDIR__#%{_libexecdir}#g' \
    -e 's#__BINDIR__#%{_bindir}#g' \
    -e 's#__STATEDIR__#%{_localstatedir}/lib/%{name}#g' \
    -e 's#__LOGDIR__#%{_localstatedir}/log/%{name}#g' \


# Add some extra setting for Tumbleweed as it uses LTO and the
# compiler seems to be more strict

%if 0%{?suse_version} >= 1550
%define _lto_cflags %{nil}
export CFLAGS="%optflags -Wno-error=stringop-truncation"
export CXFLAGS="%optflags -Wno-error=stringop-truncation"
sh ../
pushd src/c

pushd src/c

# Rename clients

for i in cli_mt cli_st load_gen
  mv %{buildroot}%{_bindir}/$i %{buildroot}%{_bindir}/zk${i}

# Precompiled Java libraries and dependencies
mkdir -p %{buildroot}%{_javadir}
mkdir -p %{buildroot}%{_javadir}/%{name}
cp -p build/%{name}-%{version}.jar %{buildroot}%{_javadir}/%{name}/%{name}-%{version}.jar
cp -r lib/* %{buildroot}%{_javadir}/%{name}
mkdir -p %{buildroot}%{_libexecdir}/%{name}

# Scripts

# zookeeper-wrapper:
install -p -m 755 %{SOURCE2} %{buildroot}/%{_bindir}/

# NOTE(trebskit) copy to bin dir of zookeeper to allow loop below pick it up
install -p -m 755 %{SOURCE6} bin/

for script in
  # Run all executables through zookeeper-wrapper to supply SUSE specific
  # environment variables.
  ln -sr %{buildroot}%{_bindir}/%{name}-wrapper %{buildroot}%{_bindir}/$script
  install -p -m 755 bin/$script %{buildroot}%{_libexecdir}/%{name}/

mkdir -p %{buildroot}%{_sysconfdir}/zookeeper
install -p -m 0640 conf/ %{buildroot}%{_sysconfdir}/zookeeper
mkdir -p %{buildroot}%{_docdir}/zookeeper
install -p -m 0640 conf/zoo_sample.cfg %{buildroot}%{_sysconfdir}/zookeeper/zoo.cfg
touch %{buildroot}%{_sysconfdir}/zookeeper/zoo.cfg

mkdir -p %{buildroot}%{_localstatedir}/lib/zookeeper/data
echo 1 > %{buildroot}%{_localstatedir}/lib/zookeeper/data/myid

mkdir -p %{buildroot}%{_localstatedir}/log/zookeeper

install -D -m 644 %{S:1} %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}%{_sbindir}
ln -s /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}

install -p -D -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}-server

%pre server
groupadd --system zookeeper 2>/dev/null || :
useradd -g zookeeper -r -d %{_localstatedir}/lib/%{name} -s /bin/false \
	-c "ZooKeeper service account" %{name} 2>/dev/null || :
%service_add_pre %{name}.service

%post -n libzookeeper2
/sbin/ldconfig > /dev/null 2>&1

%postun -n libzookeeper2
/sbin/ldconfig > /dev/null 2>&1

%post server
%service_add_post %{name}.service

%preun server
%service_del_preun %{name}.service

%postun server
%service_del_postun %{name}.service

%files server
%license LICENSE.txt
%config %{_sysconfdir}/logrotate.d/%{name}-server
%attr(0750,zookeeper,zookeeper) %dir /var/lib/zookeeper
%attr(0750,zookeeper,zookeeper) %dir /var/lib/zookeeper/data
%attr(0640,zookeeper,zookeeper) %config(noreplace) /var/lib/zookeeper/data/myid
%attr(0755,zookeeper,zookeeper) %dir /var/log/zookeeper
%attr(0755,root,root) %dir %{_sysconfdir}/zookeeper
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/zookeeper/zoo.cfg
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/zookeeper/

%files client
%license LICENSE.txt

%files -n libzookeeper2
%license LICENSE.txt

%files -n libzookeeper2-devel
%license LICENSE.txt

openSUSE Build Service is sponsored by