Subject: [PATCH] testing/openrc-exporter: new aport

From: Tom Lebreux <[email-masked]>
Date: Sat, 17 Apr 2021 23:45:47 -0400

https://sr.ht/~tomleb/openrc-exporter
Prometheus exporter for OpenRC
---
First package here so hopefully I got everything correct.

I doubt creating the user openrc-exporter is required, but I didn't want
to run the exporter as root. Maybe `nobody` should be used instead?

The port number has been allocated officially with Prometheus through
this page: https://github.com/prometheus/prometheus/wiki/Default-port-allocations
 testing/openrc-exporter/APKBUILD              | 44 +++++++++++++++++++
 testing/openrc-exporter/openrc-exporter.confd |  3 ++
 testing/openrc-exporter/openrc-exporter.initd | 13 ++++++
 .../openrc-exporter.pre-install               |  6 +++
 4 files changed, 66 insertions(+)
 create mode 100644 testing/openrc-exporter/APKBUILD
 create mode 100644 testing/openrc-exporter/openrc-exporter.confd
 create mode 100644 testing/openrc-exporter/openrc-exporter.initd
 create mode 100644 testing/openrc-exporter/openrc-exporter.pre-install

diff --git a/testing/openrc-exporter/APKBUILD b/testing/openrc-exporter/APKBUILD
new file mode 100644
index 000000000000..db4fb5b3b6a2
--- /dev/null
+++ b/testing/openrc-exporter/APKBUILD
@@ -0,0 +1,44 @@
+# Contributor: Tom Lebreux <[email-masked]>
+# Maintainer: Tom Lebreux <[email-masked]>
+pkgname=openrc-exporter
+pkgver=0.0.1
+pkgrel=0
+pkgdesc="Prometheus exporter for OpenRC"
+url="https://sr.ht/~tomleb/openrc-exporter"
+arch="all !mips !mips64" # Limited by go
+license="AGPL-3.0-only"
+makedepends="go openrc-dev"
+install="$pkgname.pre-install"
+subpackages="$pkgname-doc $pkgname-openrc"
+pkgusers="openrc-exporter"
+pkggroups="openrc-exporter"
+source="
+	$pkgname-$pkgver.tar.gz::https://git.sr.ht/~tomleb/openrc-exporter/archive/$pkgver.tar.gz
+	openrc-exporter.initd
+	openrc-exporter.confd
+	"
+options="!check" # No tests yet
+
+build() {
+	CGO_ENABLED=1 go build -v -ldflags "-X main.version=$pkgver" \
+		-trimpath ./cmd/openrc-exporter
+}
+
+check() {
+	go test ./...
+}
+
+package() {
+	install -Dm755 openrc-exporter "$pkgdir"/usr/bin/openrc-exporter
+
+	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
+
+	install -Dm755 "$srcdir"/$pkgname.initd \
+		"$pkgdir"/etc/init.d/$pkgname
+	install -Dm644 "$srcdir"/$pkgname.confd \
+		"$pkgdir"/etc/conf.d/$pkgname
+}
+
+sha512sums="53d1dd7135dc91521ef99f6687bdf3ff703fc8e5963e8abb68a2be6ab5b55e7a08b4290e915468adc05b835b567e4251b1e0f84e17e17d52b7bcb92ea71c3f6f  openrc-exporter-0.0.1.tar.gz
+6558c54c5375d09fc9c3c9634168a9ba430c473bd095476bcab022cba3af827a670c0a07b40fbb3ed2d4f698a12a69e5797039d80c6667fab33727fd05d574ae  openrc-exporter.initd
+53fe95875b1f91acb91afa6e878885c2716d5b356ba535c20fc5ad4d8bf37ff4807c14b6379e82387348dde81dc3c0c421598736b48b0d3ddf337c69de2aa0a5  openrc-exporter.confd"
diff --git a/testing/openrc-exporter/openrc-exporter.confd b/testing/openrc-exporter/openrc-exporter.confd
new file mode 100644
index 000000000000..f607091e475c
--- /dev/null
+++ b/testing/openrc-exporter/openrc-exporter.confd
@@ -0,0 +1,3 @@
+# Configuration for /etc/init.d/openrc-exporter
+
+openrc_exporter_opts="-listen-address 0.0.0.0:9816"
diff --git a/testing/openrc-exporter/openrc-exporter.initd b/testing/openrc-exporter/openrc-exporter.initd
new file mode 100644
index 000000000000..2704bf59f917
--- /dev/null
+++ b/testing/openrc-exporter/openrc-exporter.initd
@@ -0,0 +1,13 @@
+#!/sbin/openrc-run
+supervisor=supervise-daemon
+
+name="openrc-exporter"
+description="Prometheus exporter which exposes metrics on services managed by OpenRC"
+
+command="/usr/bin/$name"
+command_args="$openrc_exporter_opts"
+command_user="openrc-exporter:openrc-exporter"
+
+depend() {
+	need net
+}
diff --git a/testing/openrc-exporter/openrc-exporter.pre-install b/testing/openrc-exporter/openrc-exporter.pre-install
new file mode 100644
index 000000000000..6ff2e15769d2
--- /dev/null
+++ b/testing/openrc-exporter/openrc-exporter.pre-install
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+addgroup -S openrc-exporter 2>/dev/null
+adduser -H -S -D -s /sbin/nologin -G openrc-exporter -g openrc-exporter openrc-exporter 2>/dev/null
+
+exit 0
-- 
2.30.2