File ping_exporter.spec of Package ping_exporter

#
# spec file for package ping_exporter
#
# Copyright (c) 2023 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:           ping_exporter
Version:        1.1.3
Release:        0
Summary:        Prometheus exporter for ICMP echo requests
License:        MIT
URL:            https://github.com/czerwonk/ping_exporter
Group:          System/Management
Distribution:   %{_repository}
Source0:        %{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        %{name}.sysconfig
Source3:        %{name}.service
Source4:        %{name}-sysusers.conf
Source6:        %{name}.yaml
BuildRequires:  go >= 1.22
BuildRequires:  golang-packaging
BuildRequires:  sysuser-shadow
BuildRequires:	sysuser-tools
Requires(post): %fillup_prereq
Provides:       prometheus(%{name})
ExcludeArch:    s390
%{?systemd_ordering}
%sysusers_requires
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif

%description
This is a simple server that scrapes go-ping stats and exports them via HTTP
for Prometheus consumption.
It is intented to run as systemd service and restricted user (prometheus) with
cap_net_raw capability set.

%prep
%setup -q -n %{name}-%{version}
%setup -q -n %{name}-%{version} -T -D -a 1

%build
%{goprep} github.com/czerwonk/ping_exporter
go build \
  -mod=vendor \
  -buildmode=pie \
  -ldflags="-w -s" \
  -o bin/%{name} .

%install
# install config, service, user, files/dirs, binary
install -Dm 0644 %{SOURCE2} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -Dm 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service
install -Dm 0644 %{SOURCE4} %{buildroot}%{_sysusersdir}/%{name}.conf
install -Dm 0644 %{SOURCE6} %{buildroot}%{_sysconfdir}/%{name}.yaml
install -Dm 0755 bin/%{name} %{buildroot}%{_sbindir}/%{name}

# create rc-symlink
pushd %{buildroot}%{_sbindir}
ln -s service rc%{name}
popd

%pre
%sysusers_create_package %{name} %{SOURCE4}
%service_add_pre %{name}.service

%post
%service_add_post %{name}.service
%fillup_only -n  %{name}

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%files
%doc README.md
%license LICENSE
%{_sbindir}/%{name}
%{_sbindir}/rc%{name}
%attr(0640,root,prometheus) %config(noreplace) %{_sysconfdir}/%{name}.yaml
%{_fillupdir}/sysconfig.%{name}
%{_unitdir}/%{name}.service
%{_sysusersdir}/%{name}.conf

%changelog
openSUSE Build Service is sponsored by