File graylog.spec of Package graylog

# spec file for package graylog
# Copyright (c) 2018 SUSE LINUX 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

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

%{!?_initddir: %{expand: %%global _initddir %{_initrddir}}}
%{!?_rundir: %{expand: %%global _rundir %{_localstatedir}/run}}
%if ! %{defined _fillupdir}
 %define _fillupdir %{_localstatedir}/adm/fillup-templates

%define gl_home %{_prefix}/lib/graylog
%if 0%{?suse_version}
%define gl_sysconfdir %{_fillupdir}/sysconfig.
%define gl_sysconfdir %{_sysconfdir}/graylog/

Name:           graylog
Version:        3.1.0
Release:        0

Summary:        Field-tested open source data analytics system for logs
License:        GPL-3.0+
Group:          Productivity/Networking/Security

Source1:        init.d-%{name}
Source2:        sysconfig-%{name}
Source3:        log4j.xml
Source4:        service.graylog
Source5:        tmpfiles.conf-graylog
Source6:        init.d-graylog-suse
Source7:        graylog.logrotate
NoSource:       0
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

Requires:       elasticsearch < 7
Requires:       elasticsearch >= 6
Requires:       java-openjdk >= 1.8.0
Requires:       jpackage-utils
Requires:       logrotate
Requires:       mongodb-org >= 3.6
PreReq:         /bin/echo /bin/mkdir /usr/bin/touch
PreReq:         %fillup_prereq
PreReq:         fillup
Provides:       graylog2-server

# so we do not need to own tmpfiles.d...
%if 0%{?has_systemd}
BuildRequires:  systemd
%if 0%{?suse_version}
Requires(pre):  shadow
Requires(pre):  util-linux
Requires(post): chkconfig
Requires(post): initscripts
Requires(pre):  chkconfig
Requires(pre):  initscripts
Requires(pre):  shadow-utils

Manage billions of events and process hundreds of thousands of new events every second.
All of the infrastructure runs in your own data center: No need to worry about
sensitive data leaving your company or shipping your logs away over the internet.
Graylog is leveraging proven technologies e.g. Java, Scala and ElasticSearch.
All communication is done via REST APIs so you can even build your
own tools on top of it. The graylog package ships with an interactive API browser.

%setup -q
sed -ri s@/var/run@%_rundir@ %{S:5}

sed -ri 's@^(node_id_file.=).*@\1 %{_sysconfdir}/graylog/server-node-id@g' graylog.conf.example
sed -ri 's@(rules_file.=).*@\1 %{_sysconfdir}/graylog/server.drl@g' graylog.conf.example
sed -ri 's@(message_journal_dir.=).*@\1 %{_localstatedir}/spool/graylog@g' graylog.conf.example

# sles is a bit nagging about version of bytecode so lets make it quiet :)

%{__mkdir} -p %{buildroot}%{gl_home}/server/bin
%{__install} -p -m 755 graylog.jar %{buildroot}%{gl_home}/server/
%{__install} -p -m 755 bin/graylogctl %{buildroot}%{gl_home}/server/bin/
# config
%{__mkdir} -p %{buildroot}%{_sysconfdir}/graylog
# create file for ghosting...
touch %{buildroot}%{_sysconfdir}/graylog/server-node-id
%{__install} -m 644 graylog.conf.example %{buildroot}%{_sysconfdir}/graylog/server.conf
%{__install} -p -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/graylog/server-log4j.xml

# logs
%{__mkdir} -p %{buildroot}%{_localstatedir}/log/graylog

# sysconfig and init
%{__mkdir} -p %{buildroot}%{_sysconfdir}/sysconfig
%{__mkdir} -p %{buildroot}%{_initddir}
%if 0%{?suse_version}
 %if 0%{?suse_version} <= 1210
 %{__install} -m 755 %{SOURCE6} %{buildroot}%{_initddir}/%{name}
%{__install} -m 755 %{SOURCE1} %{buildroot}%{_initddir}/%{name}
%{__install} -Dm 644 %{SOURCE2} %{buildroot}%{gl_sysconfdir}%{name}
%{__mkdir} -p %{buildroot}%_sbindir
(cd %{buildroot}%_sbindir ; ln -s %{_initddir}/%{name} rc%{name})
%if 0%{?has_systemd}
%{__mkdir} -p %{buildroot}%_unitdir
%{__install} -Dm 644 %{SOURCE4} %{buildroot}%_unitdir/%{name}.service
%{__install} -Dm 644 %{SOURCE5} %{buildroot}%_tmpfilesdir/%{name}.conf
(cd %{buildroot}%_sbindir && ln -sf /usr/sbin/service rc%{name})
%{__install} -Dm 644 %{SOURCE7}  %{buildroot}%{_sysconfdir}/logrotate.d/%name

# Install all plugins
%{__mkdir} -p %{buildroot}%{gl_home}/server/plugin
cp -r plugin/*.jar %{buildroot}%{gl_home}/server/plugin

%{__mkdir} -p %{buildroot}%{_rundir}/graylog
%{__mkdir} -p %{buildroot}%{_localstatedir}/spool/graylog

# create graylog group
if ! getent group graylog >/dev/null; then
        groupadd -r graylog

# create graylog user
if ! getent passwd graylog >/dev/null; then
        useradd -r -g graylog -d %{gl_home} \
            -s /sbin/nologin -c "Party Gorilla" graylog
%if 0%{?has_systemd}
%service_add_pre %{name}.service

if [ ! -s %{_sysconfdir}/graylog/server-node-id ]; then
        uuidgen > %{_sysconfdir}/graylog/server-node-id
%if 0%{?has_systemd}
systemd-tmpfiles --create %{_tmpfilesdir}/%{name}.conf
%service_add_post %{name}.service

%if 0%{?has_systemd}
%service_del_preun %{name}.service

%if 0%{?has_systemd}
%service_del_postun %{name}.service

%doc COPYING README.markdown
%dir %{gl_home}
%dir %{gl_home}/server
%dir %{gl_home}/server/bin
%dir %{gl_home}/server/plugin
%dir %{_sysconfdir}/graylog
%dir %attr(-,graylog,graylog) %{_localstatedir}/spool/graylog
%dir %attr(-,graylog,graylog) %{_localstatedir}/log/graylog
%if 0%{?suse_version} <= 1210
%if !0%{?suse_version}
%config(noreplace) %{gl_sysconfdir}graylog
%config(noreplace) %{_sysconfdir}/graylog/server.conf
%config(noreplace) %{_sysconfdir}/graylog/server-log4j.xml
%config(noreplace) %{_sysconfdir}/logrotate.d/%name
%doc README.markdown
%ghost %attr(-,graylog,graylog) %{_rundir}/graylog
%ghost %config(noreplace) %{_sysconfdir}/graylog/server-node-id
%if 0%{?has_systemd}