File elasticsearch.spec of Package elasticsearch

#
# spec file for package elasticsearch
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2016 kkaempf
#
# 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/
#


	#
# spec file for "elasticsearch"
#
#
# 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/
#

%if 0%{?suse_version} > 1140 || 0%{?fedora_version} > 14
%define has_systemd 1
%else
%define has_systemd 0
%endif

# "backport"
%{!?_initddir:    %{expand: %%global _initddir    %{_initrddir}}}
%{!?_rundir:      %{expand: %%global _rundir      %{_localstatedir}/run}}
# these two are broken on SLE 11... so just "correct" them enough to work...
%{!?_tmpfilesdir: %{expand: %%global _tmpfilesdir %{_prefix}/lib/tmpfiles.d}}
%{!?_sysctldir:   %{expand: %%global _sysctldir   %{_prefix}/lib/sysctl.d}}

Name:           elasticsearch
Version:        2.4.2
Release:        0
Summary:        Open Source, Distributed, RESTful Search Engine
License:        Apache-2.0
Group:          Productivity/Databases/Tools
Url:            https://github.com/elastic/elasticsearch

Source0:        https://github.com/elastic/elasticsearch/archive/v%{version}/elasticsearch-%{version}.tar.gz
Source1:        %{name}.service
Source2:        %{name}.logrotate
Source3:        %{name}.sysconfig
Source4:        %{name}.conf
Source5:        %{name}.tmpfiles.d
Source6:        %{name}.in.sh
Source7:        %{name}.SuSEfirewall2
Source8:        %{name}.init
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  elasticsearch-kit == %{version}
BuildRequires:  git
BuildRequires:  java-devel

%if 0%{?has_systemd}
BuildRequires:  systemd
%{?systemd_requires}
%endif

# SLE_12 and Leap 42 need this:
BuildRequires:  mozilla-nss

BuildArch:      noarch
Provides:       mvn(org.elasticsearch:core) == %{version}-SNAPSHOT
Provides:       mvn(org.elasticsearch:dev-tools) == %{version}-SNAPSHOT
Provides:       mvn(org.elasticsearch:distribution) == %{version}-SNAPSHOT
Provides:       mvn(org.elasticsearch:modules) == %{version}-SNAPSHOT
Provides:       mvn(org.elasticsearch:plugins) == %{version}-SNAPSHOT
Provides:       mvn(org.elasticsearch:qa) == %{version}-SNAPSHOT
Provides:       mvn(org.elasticsearch:rest-api-spec) == %{version}-SNAPSHOT
Provides:       mvn(org:elasticsearch) == %{version}
Requires:       java
Requires:       logrotate
Requires:       which
# mkdir, chown in %%pre
Requires(pre):  coreutils

%description
Elasticsearch is a distributed RESTful search engine built for the
cloud. Reference documentation can be found at
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
and the 'Elasticsearch: The Definitive Guide' book can be found at
https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html

%prep
%setup -q -c -n src
cp -Rf %{_datadir}/tetra ../kit
# Prepare wrapper script for correct version of built package
sed -i 's/@VERSION@/%{version}/g' %{S:6}
cd %{name}-%{version}

%build
#!/bin/bash
cd ..
PROJECT_PREFIX=`readlink -e .`
cd src/%{name}-%{version}
$PROJECT_PREFIX/kit/apache-maven-3.3.9/bin/mvn \
  -Dmaven.repo.local=$PROJECT_PREFIX/kit/m2 \
  -DskipTests \
  --settings $PROJECT_PREFIX/kit/m2/settings.xml \
  --strict-checksums \
  -e \
  --projects '!distribution/rpm,!distribution/deb' \
  -o \
  package

#%%check
#!/bin/bash
#cd ..
#PROJECT_PREFIX=`readlink -e .`
#cd src/%%{name}-%%{version}
#$PROJECT_PREFIX/kit/apache-maven-3.3.9/bin/mvn \
#  -Dmaven.repo.local=$PROJECT_PREFIX/kit/m2 \
#  --settings $PROJECT_PREFIX/kit/m2/settings.xml \
#  --strict-checksums \
#  --projects '!distribution/rpm' \
#  test

%install
export NO_BRP_CHECK_BYTECODE_VERSION=true

#!/bin/bash
cd ..
PROJECT_PREFIX=`readlink -e .`
cd src/%{name}-%{version}
$PROJECT_PREFIX/kit/apache-maven-3.3.9/bin/mvn \
  -Dmaven.repo.local=$PROJECT_PREFIX/kit/m2 \
  -DskipTests \
  -Dpath.home=%{buildroot}%{_datadir}/%{name} \
  --settings $PROJECT_PREFIX/kit/m2/settings.xml \
  --strict-checksums \
  --projects '!distribution/rpm,!distribution/deb' \
  -o \
  install

#
#  -Dpath.conf=%%{_sysconfdir}/%%{name} \
#  -Dpath.data=%%{_localstatedir}/lib/%%{name} \
#  -Dpath.repo=%%{_datadir}/%%{name} \
#

#
# /etc/sysconfig

install -d %{buildroot}%{_sysconfdir}
install -d %{buildroot}%{_sysconfdir}/%{name}
install -d %{buildroot}%{_sysconfdir}/%{name}/scripts
install distribution/src/main/resources/config/elasticsearch.yml %{buildroot}%{_sysconfdir}/%{name}
install distribution/src/main/resources/config/logging.yml %{buildroot}%{_sysconfdir}/%{name}

#
# bin

install -d %{buildroot}%{_datadir}/%{name}/bin
install -m 755 distribution/tar/target/bin/%{name} %{buildroot}%{_datadir}/%{name}/bin
install -m 755 distribution/tar/target/bin/plugin %{buildroot}%{_datadir}/%{name}/bin
install -m 755 %{S:6} %{buildroot}%{_datadir}/%{name}/bin

#
# lib

install -d %{buildroot}%{_datadir}/%{name}/lib
install distribution/target/lib/*.jar %{buildroot}%{_datadir}/%{name}/lib

#
# modules

install -d %{buildroot}%{_datadir}/%{name}/modules
install -d %{buildroot}%{_datadir}/%{name}/modules/lang-expression
install -m 644 distribution/tar/target/modules/lang-expression/* %{buildroot}%{_datadir}/%{name}/modules/lang-expression
install -d %{buildroot}%{_datadir}/%{name}/modules/lang-groovy
install -m 644 distribution/tar/target/modules/lang-groovy/* %{buildroot}%{_datadir}/%{name}/modules/lang-groovy

#
# plugins

install -d %{buildroot}%{_datadir}/%{name}/plugins

#
# var

%{__install} -d -m 755 %{buildroot}%{_localstatedir}/log/%{name}
%{__install} -d -m 755 %{buildroot}%{_localstatedir}/lib/%{name}
%{__install} -d -m 755 %{buildroot}%{_localstatedir}/lib/%{name}/data
%{__install} -d -m 755 %{buildroot}%{_localstatedir}/lib/%{name}/work
%{__install} -d -m 755 %{buildroot}%{_rundir}/%{name}

#
# /usr/share
%{__install} -d %{buildroot}%{_datadir}/%{name}

#
# sysconfig template
%{__mkdir} -p %{buildroot}%{_localstatedir}/adm/fillup-templates/
%{__install} -m 644 %{S:3} %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}

#
# sysctl.d
%{__install} -d -m 755 %{buildroot}%{_sysctldir}
%{__install} -m 644 %{S:4} %{buildroot}%{_sysctldir}/%{name}.conf

#
# tmpfiles.d
%{__install} -d -m 755 %{buildroot}%{_tmpfilesdir}
%{__install} -m 644 %{S:5} %{buildroot}%{_tmpfilesdir}/%{name}.conf

#
# sbin
install -d %{buildroot}%{_sbindir}

#
# init scripts / systemd

%if 0%{?has_systemd}
install -D -m 644 %{S:1} $RPM_BUILD_ROOT%{_unitdir}/%{name}.service
# rc%%{name}
ln -sf %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rc%{name}
%else
mkdir -p $RPM_BUILD_ROOT%{_initddir}
install -m 755 %{S:8} $RPM_BUILD_ROOT%{_initddir}/%{name}
ln -sf %{_initddir}/%{name} $RPM_BUILD_ROOT%{_sbindir}/rc%{name}
%endif

#
# logrotate

%{__install} -D -m 644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

#
# SuSEfirewall2
%{__install} -D -m 644 %{S:7} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}

%pre
%if 0%{?has_systemd}
%service_add_pre %{name}.service
%endif

## create %%{name} group and user
getent group %{name} >/dev/null || groupadd -r %{name}
getent passwd %{name} >/dev/null || useradd -r -g %{name} -d %{_localstatedir}/lib/%{name} -s /sbin/nologin -c "service user for elasticsearch" %{name}
exit 0

%post
%if 0%{?has_systemd}
%service_add_post %{name}.service
%else
%{fillup_and_insserv -n -y %{name}}
%endif

# rpm is kinda stupid ...
# Create our dirs immediatly, after a manual package install.
# After a reboot systemd/aaa_base will take care.
%if 0%{?has_systemd}
systemd-tmpfiles --create %{_tmpfilesdir}/%{name}.conf
%else
test -d %{_rundir}/%{name} || mkdir -m 755 %{_rundir}/%{name} && chown %{name}.%{name} %{_rundir}/%{name}
%endif

%preun
%if 0%{?has_systemd}
%service_del_preun %{name}.service
%else
%stop_on_removal
%endif

%postun
## no auto restart on update
export DISABLE_RESTART_ON_UPDATE=1

%if 0%{?has_systemd}
%service_del_postun %{name}.service
%else
%insserv_cleanup
%endif

# only execute in case of package removal, not on upgrade
if [ $1 -eq 0 ] ; then
  getent passwd %{name} > /dev/null
  if [ "$?" == "0" ] ; then
    userdel %{name}
  fi

  getent group %{name} >/dev/null
  if [ "$?" == "0" ] ; then
    groupdel %{name}
  fi
fi

%files
%defattr(-,root,root)

%doc %{name}-%{version}/README.textile
%doc %{name}-%{version}/LICENSE.txt
%doc %{name}-%{version}/NOTICE.txt

%config(noreplace) %dir %attr(755,root,%{name}) %{_sysconfdir}/%{name}
%config(noreplace) %attr(644,root,%{name}) %{_sysconfdir}/%{name}/%{name}.yml
%config(noreplace) %attr(644,root,%{name}) %{_sysconfdir}/%{name}/logging.yml
%config(noreplace) %dir %attr(750,root,%{name}) %{_sysconfdir}/%{name}/scripts

%dir %{_datadir}/%{name}

%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}

%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*

#%%attr(755,root,root) "%%{_datadir}/%%{name}/bin/"
# "%%{_datadir}/%%{name}/lib"
# "%%{_datadir}/%%{name}/modules"

%if 0%{?has_systemd}
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/%{name}.conf
%else
%attr(755,root,root) %{_initddir}/%{name}
%exclude %{_tmpfilesdir}/%{name}.conf
%dir %{_sysctldir}
%endif

%{_sbindir}/rc%{name}

%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}

%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}

%{_sysctldir}/%{name}.conf

%dir %attr(755,%{name},%{name}) %{_localstatedir}/lib/%{name}
%dir %attr(755,%{name},%{name}) %{_localstatedir}/log/%{name}
%dir %attr(755,%{name},%{name}) %{_datadir}/%{name}/plugins
%ghost %dir %attr(755,%{name},%{name}) %{_rundir}/%{name}

%changelog
openSUSE Build Service is sponsored by