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


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

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

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

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

Url:            http://www.graylog.org
Source0:        https://packages.graylog2.org/releases/%{name}/%{name}-%{version}.tgz
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
%{?systemd_requires}
%endif
%if 0%{?suse_version}
Requires(pre):  shadow
Requires(pre):  util-linux
%else
Requires(post): chkconfig
Requires(post): initscripts
Requires(pre):  chkconfig
Requires(pre):  initscripts
Requires(pre):  shadow-utils
%endif

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

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

%build
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

%install
# sles is a bit nagging about version of bytecode so lets make it quiet :)
export NO_BRP_CHECK_BYTECODE_VERSION=true

%{__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}
 %endif
%else
%{__install} -m 755 %{SOURCE1} %{buildroot}%{_initddir}/%{name}
%endif
%{__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})
%endif
%{__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

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

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

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

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

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

%files
%defattr(-,root,root,-)
%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
%{_initddir}/graylog
%endif
%if !0%{?suse_version}
%config(noreplace) %{gl_sysconfdir}graylog
%else
%{gl_sysconfdir}graylog
%endif
%config(noreplace) %{_sysconfdir}/graylog/server.conf
%config(noreplace) %{_sysconfdir}/graylog/server-log4j.xml
%config(noreplace) %{_sysconfdir}/logrotate.d/%name
%doc README.markdown
%{gl_home}/server/graylog.jar
%{gl_home}/server/bin/graylogctl
%{gl_home}/server/plugin/graylog-plugin-aws-%{version}.jar
%{gl_home}/server/plugin/graylog-plugin-collector-%{version}.jar
%{gl_home}/server/plugin/graylog-plugin-threatintel-%{version}.jar
#%%{gl_home}/server/plugin/graylog-plugin-beats-%%{version}.jar
#%%{gl_home}/server/plugin/graylog-plugin-cef-%%{version}.jar
#%%{gl_home}/server/plugin/graylog-plugin-enterprise-integration-%%{version}.jar
#%%{gl_home}/server/plugin/graylog-plugin-map-widget-%%{version}.jar
#%%{gl_home}/server/plugin/graylog-plugin-netflow-%%{version}.jar
#%%{gl_home}/server/plugin/graylog-plugin-pipeline-processor-%%{version}.jar
%ghost %attr(-,graylog,graylog) %{_rundir}/graylog
%ghost %config(noreplace) %{_sysconfdir}/graylog/server-node-id
%{_sbindir}/rc%{name}
%if 0%{?has_systemd}
%_unitdir/%{name}.service
%_tmpfilesdir/%{name}.conf
%endif

%changelog