File golang-github-wrouesnel-postgres_exporter.spec of Package golang-github-wrouesnel-postgres_exporter

#
# spec file for package golang-github-wrouesnel-postgres_exporter
#
# Copyright (c) 2020 SUSE LLC
#
# 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/
#

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

%undefine _missing_build_ids_terminate_build

Name:           golang-github-wrouesnel-postgres_exporter
Version:        0.4.7
Release:        0
License:        Apache-2.0
Summary:        Prometheus exporter for PostgreSQL
Url:            https://prometheus.io/
Group:          System/Management
Source:         postgres_exporter-%{version}.tar.xz
Source1:        prometheus-postgres_exporter.service
Source2:        prometheus-postgres_exporter.sysconfig
Source3:        prometheus-postgres_exporter.initd
Patch0:         architectures.patch
%if 0%{?rhel} >= 8
BuildRequires:  golang
%else
BuildRequires:  go1.11
%endif
BuildRequires:  xz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
ExclusiveArch:  %ix86 x86_64 %arm

%if 0%{?suse_version}
Requires(post): %fillup_prereq
%endif

%description
Prometheus exporter for PostgreSQL server metrics. Supported PostgreSQL versions: 9.1 and up.

# For some reason Fedora and CentOS8 do not build correctly debuginfo packages on OBS
%if 0%{?fedora} || 0%{?rhel} >= 8
%define debug_package %{nil}
%endif

%prep
%setup -q -n postgres_exporter-%{version}
%patch0 -p1

%build
mkdir -pv $HOME/go/src && cp -avr vendor/* $HOME/go/src/
go run -ldflags "-v -buildmode=pie -compressdwarf=false" mage.go binary

%install
install -D -m 0755 postgres_exporter %{buildroot}/%{_bindir}/postgres_exporter

%if 0%{?suse_version}
  install -m755 -d %buildroot%{_fillupdir}
  install -m644 %{SOURCE2} %buildroot%{_fillupdir}/sysconfig.prometheus-postgres_exporter
%else
  install -m755 -d %{buildroot}/etc/sysconfig
  install -m644 %{SOURCE2} %{buildroot}/etc/sysconfig/prometheus-postgres_exporter
%endif

%if 0%{?rhel} >= 7
  install -D -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/prometheus-postgres_exporter.service
%else
  install -D -m 0755 %{SOURCE3} %{buildroot}%{_initddir}/prometheus-postgres_exporter
%endif

%pre
getent group prometheus >/dev/null || %{_sbindir}/groupadd -r prometheus
getent passwd prometheus >/dev/null || %{_sbindir}/useradd -r -g prometheus -d %{_localstatedir}/lib/prometheus -M -s /sbin/nologin prometheus

%post
%if 0%{?suse_version}
%fillup_only -n prometheus-postgres_exporter
%endif
%if 0%{?rhel} >= 7
%systemd_post prometheus-postgres_exporter.service
%else
/sbin/chkconfig --add prometheus-postgres_exporter
%endif

%preun
%if 0%{?rhel} >= 7
%systemd_preun prometheus-postgres_exporter.service
%else
if [ $1 -eq 0 ] ; then
  /sbin/service prometheus-postgres_exporter stop >/dev/null 2>&1
  /sbin/chkconfig --del prometheus-postgres_exporter
fi
%endif

%postun
%if 0%{?rhel} >= 7
%systemd_postun prometheus-postgres_exporter.service
%else
if [ "$1" -ge "1" ] ; then
  /sbin/service prometheus-postgres_exporter condrestart >/dev/null 2>&1 || :
fi
%endif

%files
%defattr(-,root,root,-)
%doc README.md
# RHEL 6 license macro patch
%{!?_licensedir:%global license %%doc}
%license LICENSE
%{_bindir}/postgres_exporter
%if 0%{?suse_version}
%{_fillupdir}/sysconfig.prometheus-postgres_exporter
%else
/etc/sysconfig/prometheus-postgres_exporter
%endif
%if 0%{?rhel} >= 7
%{_unitdir}/prometheus-postgres_exporter.service
%else
%{_initddir}/prometheus-postgres_exporter
%endif
# For some reason Fedora and CentOS8 do not correctly handle debuginfo files on OBS
%if 0%{?fedora} || 0%{?rhel} >= 8
%ghost /usr/lib/debug/usr/bin/postgres_exporter-*.debug
%endif

%changelog
openSUSE Build Service is sponsored by