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) 2022 SUSE LLC
# Copyright (c) 2017 Silvio Moioli <>
# 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

%bcond_without  apparmor


Name:           golang-github-prometheus-node_exporter
Version:        1.5.0
Release:        0
Summary:        Prometheus exporter for machine metrics
License:        Apache-2.0
Group:          System/Management
Source:         node_exporter-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        prometheus-node_exporter.service
Source4:        prometheus-node_exporter.sysconfig
Source5:        apparmor-usr.bin.node_exporter
BuildRequires:  fdupes
BuildRequires:  golang-github-prometheus-promu >= 0.12.0
BuildRequires:  golang-packaging
BuildRequires:  golang(API) >= 1.18
Requires(post): %fillup_prereq
Requires(pre):  shadow
%if %{with apparmor}
BuildRequires:  apparmor-abstractions
BuildRequires:  apparmor-rpm-macros
Recommends:     apparmor-abstractions
Provides:       node_exporter
Provides:       prometheus(node_exporter)
ExcludeArch:    s390
#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates

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

%autosetup -a1 -p1 -n node_exporter-%{version}

export BUILDFLAGS="-v -p 4 -x -buildmode=pie -mod=vendor"
GOPATH=%{_builddir}/go promu build

install -D -m 0755 %{_builddir}/node_exporter-%{version}/node_exporter %{buildroot}/%{_bindir}/node_exporter
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/prometheus-node_exporter.service
install -D -m 0644 %{SOURCE4} %{buildroot}%{_fillupdir}/sysconfig.prometheus-node_exporter
mkdir -p %{buildroot}/var/spool/metrics
%if %{with apparmor}
# AppArmor profile
mkdir -p %{buildroot}%{_sysconfdir}/apparmor.d
install -m 0644 %{SOURCE5} %{buildroot}%{_sysconfdir}/apparmor.d/usr.bin.node_exporter
%fdupes %{buildroot}

%gotest -mod=vendor

%service_add_pre prometheus-node_exporter.service
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

%service_add_post prometheus-node_exporter.service
%fillup_only -n prometheus-node_exporter
%if %{with apparmor}
%apparmor_reload %{_sysconfdir}/apparmor.d/usr.bin.node_exporter

%service_del_preun prometheus-node_exporter.service

%service_del_postun prometheus-node_exporter.service

%license LICENSE
%if %{with apparmor}
%dir %{_sysconfdir}/apparmor.d
%config %{_sysconfdir}/apparmor.d/usr.bin.node_exporter
%dir %attr(0750, root, prometheus) /var/spool/metrics

openSUSE Build Service is sponsored by