File logstash.spec of Package logstash

# spec file for package logstash
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2015 Thomas Neuburger,
# Copyright 2017 Fujitsu LIMITED
# 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

%define _binaries_in_noarch_packages_terminate_build 0
%global _binaries_in_noarch_packages_terminate_build 0

#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates

Name:           logstash
Version:        2.4.1
Release:        0
Summary:        A tool for managing events and logs
License:        Apache-2.0
Group:          System/Monitoring
Source1:        logstash.service
Source2:        logstash.logrotate
Source3:        logstash.sysconfig
Source4:        logstash.init
Source5:        logstash.conf
Source6:        logstash-rpmlintrc
Patch1:         cve-2018-3817.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Requires:       java >= 1.7.0
Requires:       logrotate
Requires(pre):  pwdutils
BuildRequires:  fdupes

# needed for brp-check-bytecode-version (jar, fastjar would do as well)
BuildRequires:  unzip

%if 0%{?suse_version} >= 1210
BuildRequires:  systemd-rpm-macros
%bcond_without  systemd
%bcond_with     systemd

logstash is a tool for managing events and logs. You can use it to collect logs,
parse them, and store them for later use (like, for searching).

%setup -q -n %{name}-%{version}
%patch1 -p 1



## usr
%{__install} -d -m 755 %{buildroot}/%{_sbindir}

## etc
%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/%{name}/conf.d/
%{__install} -D -m 644 %{S:5} %{buildroot}%{_sysconfdir}/%{name}/sample.conf
%{__install} -D -m 644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

## opt
%{__install} -d -m 755 %{buildroot}/opt/%{name}/
%{__install} -m 644 Gemfile %{buildroot}/opt/%{name}/
%{__install} -m 644 Gemfile.jruby-1.9.lock %{buildroot}/opt/%{name}/
%{__install} -m 644 LICENSE %{buildroot}/opt/%{name}/
%{__install} -m 644 %{buildroot}/opt/%{name}/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/bin
%{__install} -m 755 bin/logstash %{buildroot}/opt/%{name}/bin/
%{__install} -m 755 bin/ %{buildroot}/opt/%{name}/bin/
%{__install} -m 755 bin/plugin %{buildroot}/opt/%{name}/bin/
%{__install} -m 755 bin/logstash-plugin %{buildroot}/opt/%{name}/bin/
%{__install} -m 755 bin/rspec %{buildroot}/opt/%{name}/bin/
%ifarch x86_64
%{__install} -d -m 755 %{buildroot}/opt/%{name}/lib
cp -rp lib/* %{buildroot}/opt/%{name}/lib/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/vendor/jruby/bin
%{__install} -m 755 vendor/jruby/bin/jruby %{buildroot}/opt/%{name}/vendor/jruby/bin/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/vendor/jruby/lib
%{__install} -m 644 vendor/jruby/lib/jruby.jar %{buildroot}/opt/%{name}/vendor/jruby/lib/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/vendor/jruby/lib/jni
%ifarch x86_64
cp -rp vendor/jruby/lib/jni/x86_64-Linux %{buildroot}/opt/%{name}/vendor/jruby/lib/jni/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/vendor/jruby/lib/ruby
cp -rp vendor/jruby/lib/ruby/* %{buildroot}/opt/%{name}/vendor/jruby/lib/ruby/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/vendor/bundle/jruby/1.9/gems
cp -rp vendor/bundle/jruby/1.9/gems/* %{buildroot}/opt/%{name}/vendor/bundle/jruby/1.9/gems/
rm -rf %{buildroot}/opt/%{name}/vendor/bundle/jruby/1.9/gems/rack-1.6.4/test/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/vendor/bundle/jruby/1.9/specifications
cp -rp vendor/bundle/jruby/1.9/specifications/* %{buildroot}/opt/%{name}/vendor/bundle/jruby/1.9/specifications/

## var
%{__install} -d -m 755 %{buildroot}/var/log/%{name}/
%{__install} -d -m 755 %{buildroot}/var/lib/%{name}/

## sysconfig template
%{__mkdir} -p %{buildroot}%{_fillupdir}/
%{__install} -m 644 %{S:3} %{buildroot}%{_fillupdir}/sysconfig.%{name}

## service (systemd or sysVinit)
%if %{with systemd}
%{__mkdir} -p %{buildroot}%{_unitdir}
%{__install} -m 444 %{S:1} %{buildroot}%{_unitdir}/%{name}.service
ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}
%{__install} -D -m 755 %{S:4} %{buildroot}%{_initrddir}/%{name}
%{__mkdir} -p %{buildroot}%{_sbindir}
ln -sf %{_initrddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}

## delet zero files from logstash
find %{buildroot} -size 0 -delete

## finds duplicate files in a given set of directories

## Register service systemd
%if %{with systemd}
%service_add_pre %{name}.service

## create logstash group and user
getent group logstash >/dev/null || groupadd -r logstash
getent passwd logstash >/dev/null || useradd -r -g logstash -d /var/lib/empty -s /sbin/nologin -c "service user for logstash" logstash
exit 0

## fill up sysconfig file
%{fillup_and_insserv -n -y %{name}}

## Register service systemd
%if %{with systemd}
%service_add_post %{name}.service

cat <<EOF

Please create logstash pipeline config files in:
Here is a sample pipeline config file: /etc/logstash/sample.conf

Maybe you also have to adjust: /etc/sysconfig/logstash


## Stop service (systemd or sysVinit)
%if %{with systemd}
%service_del_preun %{name}.service

## no auto restart on update

## Unregister service (systemd or sysVinit)
%if %{with systemd}
%service_del_postun %{name}.service

# only execute in case of package removal, not on upgrade
if [ $1 -eq 0 ] ; then

    getent passwd logstash > /dev/null
    if [ "$?" == "0" ] ; then
        userdel logstash

    getent group logstash >/dev/null
    if [ "$?" == "0" ] ; then
        groupdel logstash


%if %{with systemd}

%dir /opt/%{name}
%dir /etc/%{name}/
%dir /etc/%{name}/conf.d
%doc /etc/%{name}/sample.conf
%config(noreplace) /etc/logrotate.d/%{name}
%config(noreplace) /opt/%{name}/Gemfile

%license /opt/%{name}/LICENSE
%doc /opt/%{name}/

%dir /var/log/%{name}
%dir /var/lib/%{name}