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 http://bugs.opensuse.org/
#

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
Url:            http://zookeeper.apache.org/
Vendor:         Apache Software Foundation
Source0:        http://www-eu.apache.org/dist/zookeeper/zookeeper-%{version}/zookeeper-%{version}.tar.gz
Source1:        %{name}.service
Source2:        zookeeper-wrapper
Source3:        zookeeper.logrotate
Source4:        README.SUSE
Source5:        build.sh
Source6:        zkCleanTRX.sh
Patch0:         ftbfs-with-gcc-8.patch
BuildRequires:  cppunit-devel
BuildRequires:  java-devel
BuildRequires:  %{name}-kit == %{version}
%if 0%{?suse_version} >= 1210
BuildRequires:  systemd-rpm-macros
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-build
%{?systemd_requires}

%description
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.


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

echo -e '\n' >> bin/zkEnv.sh

cat >> bin/zkEnv.sh << 'EOF'

for i in $(find $ZKLIB -name '*.jar')
  do
  CLASSPATH=$CLASSPATH:$i
  done
EOF

# 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}#' \
           conf/log4j.properties

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

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}#' \
       %{SOURCE2}

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' \
    %{SOURCE4} > README.SUSE

%build
sh ../build.sh
pushd src/c
%configure
make
popd

%install
pushd src/c
%make_install
popd

# Rename clients

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

# 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 zkCleanTRX.sh to bin dir of zookeeper to allow loop below pick it up
install -p -m 755 %{SOURCE6} bin/zkCleanTRX.sh

for script in zkCleanup.sh zkCli.sh zkEnv.sh zkServer.sh zkCleanTRX.sh
  do
  # 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}/
  done

mkdir -p %{buildroot}%{_sysconfdir}/zookeeper
install -p -m 0640 conf/log4j.properties %{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
%defattr(-,root,root,-)
%license LICENSE.txt
%doc README.SUSE
%config %{_sysconfdir}/logrotate.d/%{name}-server
%{_bindir}/zkCleanup.sh
%{_bindir}/zkCli.sh
%{_bindir}/zkEnv.sh
%{_bindir}/zkServer.sh
%{_bindir}/zookeeper-wrapper
%{_bindir}/zkCleanTRX.sh
%{_libexecdir}/%{name}
%{_javadir}/%{name}/
%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/log4j.properties
%{_unitdir}/%{name}.service
%{_sbindir}/rc%{name}

%files client
%defattr(-,root,root,-)
%license LICENSE.txt
%doc README.SUSE
%{_bindir}/zkcli_mt
%{_bindir}/zkcli_st
%{_bindir}/zkload_gen

%files -n libzookeeper2
%defattr(-,root,root,-)
%license LICENSE.txt
%doc README.SUSE
%{_libdir}/libzookeeper_mt.so.2
%{_libdir}/libzookeeper_mt.so.2.0.0
%{_libdir}/libzookeeper_st.so.2
%{_libdir}/libzookeeper_st.so.2.0.0

%files -n libzookeeper2-devel
%defattr(-,root,root,-)
%license LICENSE.txt
%doc README.SUSE
%{_includedir}/zookeeper
%{_libdir}/libzookeeper_mt.a
%{_libdir}/libzookeeper_mt.la
%{_libdir}/libzookeeper_mt.so
%{_libdir}/libzookeeper_st.a
%{_libdir}/libzookeeper_st.la
%{_libdir}/libzookeeper_st.so

%changelog