File opensearch.spec of Package opensearch
#
# spec file for package opensearch
#
# Copyright (c) 2021 SUSE LLC
# Copyright (c) 2018 Samu Voutilainen
# Copyright (c) 2017 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/
#
%if 0%{?suse_version} > 1140 || 0%{?fedora_version} > 14
%define has_systemd 1
%else
%define has_systemd 0
%endif
%if 0%{?suse_version} > 1500
%define javaversion 15
%else
%define javaversion 11
%endif
%if ! %{defined _fillupdir}
%define _fillupdir /var/adm/fillup-templates
%endif
# "backport"
%{!?_initddir: %{expand: %%global _initddir %{_initrddir}}}
%{!?_rundir: %{expand: %%global _rundir /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: opensearch
# tarball dir is camel case
%define srcname OpenSearch
Version: 1.2.4
%define srcversion %{version}
Release: 0
Summary: Open Source distributed and RESTful search engine
License: Apache-2.0
Group: Productivity/Databases/Tools
Url: https://github.com/opensearch-project/OpenSearch
Source0: https://github.com/opensearch-project/OpenSearch/archive/v%{version}/%{name}-%{srcversion}.tar.gz
Source2: %{name}.logrotate
Source7: %{name}.SuSEfirewall2
Patch1: 0001-var-run-run.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: git
# >= 6.2.1 and < 7
BuildRequires: gradle6
%ifarch x86_64
BuildRequires: libjnidispatch
%endif
%if 0%{?suse_version} > 1010
BuildRequires: fdupes
%endif
BuildRequires: java-devel = %{javaversion}
BuildRequires: java = %{javaversion}
BuildRequires: %{name}-kit = %{version}
%if 0%{?has_systemd}
BuildRequires: systemd
%{?systemd_requires}
%endif
# SLE_12 and Leap 42 need this:
BuildRequires: mozilla-nss
BuildArch: noarch
Provides: mvn(org.opensearch:core) == %{version}
Provides: mvn(org.opensearch:dev-tools) == %{version}
Provides: mvn(org.opensearch:distribution) == %{version}
Provides: mvn(org.opensearch:modules) == %{version}
Provides: mvn(org.opensearch:plugins) == %{version}
Provides: mvn(org.opensearch:qa) == %{version}
Provides: mvn(org.opensearch:rest-api-spec) == %{version}
Provides: mvn(org:opensearch) == %{version}
%if 0%{?has_systemd}
Requires(post): %fillup_prereq
%else
Requires(post): %insserv_prereq %fillup_prereq
%endif
Requires: java-headless = %{javaversion}
Requires: logrotate
# for sysctl:
Requires: procps
# for opensearch-plugin:
Requires: hostname
Requires: which
# mkdir, chown in %%pre
Requires(pre): coreutils
%description
opensearch is an open source search and analytics engine derived from Elasticsearch 7.10.2, and is currently in an alpha state.
%prep
%setup -q -c -n src
cd %{srcname}-%{srcversion}
%patch1 -p1
if [ -d %{_datadir}/tetra/gradle ]; then
rm -rf /tmp/gradle*
cp -Rf %{_datadir}/tetra/gradle* /tmp
else
cp -Rf %{_datadir}/tetra kit
fi
%build
cd %{srcname}-%{srcversion}
export LANG=en_US.UTF-8
export GRADLE_OPTS="-Xmx1024m"
export GRADLE_USER_HOME=/tmp/gradle
export JAVA_HOME=%{_libdir}/jvm/java-%{javaversion}-openjdk-%{javaversion}
gradle \
--gradle-user-home $GRADLE_USER_HOME \
--project-cache-dir /tmp/gradle-cache \
--continue \
-Dbuild.snapshot=false \
-Dfile.encoding=UTF-8 \
--offline \
--no-daemon \
:distribution:archives:buildNoJdkLinuxTar
%clean
rm -rf ~/.gradle
%install
export BUILD_VCS_NUMBER=%{version}
export NO_BRP_CHECK_BYTECODE_VERSION=true
cd %{srcname}-%{srcversion}
#
# bin
install -d %{buildroot}%{_datadir}
tar -C %{buildroot}%{_datadir} -xf distribution/archives/no-jdk-linux-tar/build/distributions/%{name}-min-%{version}-no-jdk-linux-x64.tar.gz
mv %{buildroot}%{_datadir}/%{name}-%{version} %{buildroot}%{_datadir}/%{name}
# 'bundle' JDK - choose via update-alternatives
ln -sf %{_libdir}/jvm/jre %{buildroot}%{_datadir}/%{name}/jdk
# handled as %%doc
rm -f %{buildroot}%{_datadir}/%{name}/README.textile
rm -f %{buildroot}%{_datadir}/%{name}/LICENSE.txt
rm -f %{buildroot}%{_datadir}/%{name}/NOTICE.txt
rm -f %{buildroot}%{_datadir}/%{name}/bin/*.exe
rm -f %{buildroot}%{_datadir}/%{name}/bin/*.bat
#
# var
%{__install} -d -m 755 %{buildroot}%{_localstatedir}/log/%{name}
rmdir %{buildroot}%{_datadir}/%{name}/logs
# ln -sf %{_localstatedir}/log/%{name} %{buildroot}%{_datadir}/%{name}/logs
%{__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}
#
# tmpfiles.d
%{__install} -d -m 755 %{buildroot}%{_tmpfilesdir}
%{__install} -m 644 distribution/packages/src/common/systemd/%{name}.conf %{buildroot}%{_tmpfilesdir}
#
# sbin
%{__install} -d %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name} %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-cli %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-env %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-env-from-file %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-keystore %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-node %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-plugin %{buildroot}%{_sbindir}
ln -sf %{_datadir}/%{name}/bin/%{name}-shard %{buildroot}%{_sbindir}
#
# init scripts / systemd
%if 0%{?has_systemd}
sed -i 's/${path.conf}/\%{_sysconfdir}\/%{name}/g' distribution/packages/src/common/systemd/%{name}.service
sed -i 's/${path.env}/\%{_sysconfdir}\/sysconfig\/%{name}/g' distribution/packages/src/common/systemd/%{name}.service
%{__install} -D -m 644 distribution/packages/src/common/systemd/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
%{__install} -D -m 644 distribution/packages/src/common/systemd/sysctl/%{name}.conf %{buildroot}%{_sysconfdir}/sysctl.d/%{name}.conf
%{__install} -D -m 755 distribution/packages/src/common/systemd/systemd-entrypoint %{buildroot}%{_datadir}/%{name}/bin
# rc%%{name}
ln -sf %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%else
mkdir -p %{buildroot}%{_initddir}
%{__install} -m 755 distribution/packages/src/rpm/init.d/%{name} %{buildroot}%{_initddir}
ln -sf %{_initddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif
#
# logrotate
%{__install} -D -m 644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%if 0%{suse_version} < 1500
# only for pre-firewalld distributions
#
# SuSEfirewall2
%{__install} -D -m 644 %{S:7} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
#
# /etc/opensearch
%{__install} -d -m 775 %{buildroot}%{_sysconfdir}/%{name}
sed -i 's/\#path.data: \/path\/to\/data/path.data: \%{_localstatedir}\/lib\/%{name}\/data/g' %{buildroot}%{_datadir}/%{name}/config/%{name}.yml
sed -i 's/\#path.logs: \/path\/to\/logs/path.logs: \%{_localstatedir}\/log\/%{name}/g' %{buildroot}%{_datadir}/%{name}/config/%{name}.yml
%{__install} -m 644 %{buildroot}%{_datadir}/%{name}/config/%{name}.yml %{buildroot}%{_sysconfdir}/%{name}
sed -i 's/logs\/gc.log/\%{_localstatedir}\/log\/%{name}\/gc.log/g' %{buildroot}%{_datadir}/%{name}/config/jvm.options
%{__install} -m 644 %{buildroot}%{_datadir}/%{name}/config/jvm.options %{buildroot}%{_sysconfdir}/%{name}
%{__install} -m 644 %{buildroot}%{_datadir}/%{name}/config/log4j2.properties %{buildroot}%{_sysconfdir}/%{name}
rm -rf %{buildroot}%{_datadir}/%{name}/config
%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/%{name}/scripts
# ln -sf %{_sysconfdir}/%{name} %{buildroot}%{_datadir}/%{name}/config
#
# sysconfig template
%{__install} -d -m 755 %{buildroot}%{_fillupdir}
sed -i 's/${path.conf}/\%{_sysconfdir}\/%{name}/g' distribution/packages/src/common/env/%{name}
%{__install} -m 644 distribution/packages/src/common/env/%{name} %{buildroot}%{_fillupdir}/sysconfig.%{name}
%if 0%{?suse_version} > 1010
%fdupes %{buildroot}%{_datadir}/%{name}
%endif
%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 opensearch" %{name}
exit 0
%post
%{fillup_and_insserv -n -y %{name}}
%service_add_post %{name}.service
# 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 %{srcname}-%{srcversion}/LICENSE.txt
%doc %{srcname}-%{srcversion}/NOTICE.txt
%dir %{_datadir}/%{name}
%attr(775,root,opensearch) %dir %{_sysconfdir}/%{name}
%dir %{_sysconfdir}/%{name}/scripts
%config(noreplace) %attr(644,root,%{name}) %{_sysconfdir}/%{name}/*
%dir %{_fillupdir}
%{_fillupdir}/sysconfig.%{name}
%config %{_sysconfdir}/sysctl.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%if 0%{suse_version} < 1500
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%endif
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*
%if 0%{?has_systemd}
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/%{name}.conf
%else
%attr(755,root,root) %{_initddir}/%{name}
%exclude %{_tmpfilesdir}/%{name}.conf
%dir %{_sysctldir}
%{_sysctldir}/%{name}.conf
%endif
%{_sbindir}/rc%{name}
%{_sbindir}/%{name}*
%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