File golang-github-prometheus-node_exporter.spec of Package golang-github-prometheus-node_exporter

#
# spec file for package golang-github-prometheus-node_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/
#

Name:           golang-github-prometheus-node_exporter
Version:        0.18.1
Release:        0
Summary:        Prometheus exporter for machine metrics
License:        Apache-2.0
Group:          System/Management
Url:            https://prometheus.io/
Source:         node_exporter-v%{version}.tar.xz
Source1:        prometheus-node_exporter.service
Source2:        prometheus-node_exporter.initd
%if 0%{?rhel} >= 8
BuildRequires:  golang
%else
BuildRequires:  go1.11
%endif
BuildRequires:  xz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Provides:       node_exporter
Provides:       prometheus(node_exporter)
ExclusiveArch:  %ix86 x86_64 %arm

%description
Prometheus exporter for hardware and OS metrics exposed by *NIX kernels, written in Go with pluggable metric collectors.

%prep
%setup -q -n node_exporter

%build
go build -mod=vendor -ldflags "-v -buildmode=pie -compressdwarf=false"

%install
install -D -m0755 node_exporter %{buildroot}/%{_bindir}/node_exporter
install -Dd -m 0755 %{buildroot}%{_sbindir}
%if 0%{?rhel} >= 7
  install -D -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/prometheus-node_exporter.service
%else
  install -D -m 0755 %{SOURCE2} %{buildroot}%{_initddir}/prometheus-node_exporter
%endif

%check
go test github.com/prometheus/node_exporter -mod=vendor

%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

%if 0%{?rhel} >= 7
%post
%systemd_post prometheus-node_exporter.service
%preun
%systemd_preun prometheus-node_exporter.service
%postun
%systemd_postun prometheus-node_exporter.service
%else
%post
/sbin/chkconfig --add prometheus-node_exporter
%preun
if [ $1 -eq 0 ] ; then
  /sbin/service prometheus-node_exporter stop >/dev/null 2>&1
  /sbin/chkconfig --del prometheus-node_exporter
fi
%postun
if [ "$1" -ge "1" ] ; then
  /sbin/service prometheus-node_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}/node_exporter

%if 0%{?rhel} >= 7
%{_unitdir}/prometheus-node_exporter.service
%else
%{_initddir}/prometheus-node_exporter
%endif

%changelog
openSUSE Build Service is sponsored by