git: 9ae1e22950e7 - main - net-mgmt/metronome: Add rc.d script

From: Kirill Ponomarev <krion_at_FreeBSD.org>
Date: Sat, 18 May 2024 05:18:23 UTC
The branch main has been updated by krion:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9ae1e22950e7c9114e6d0946855de4f6992ac3b4

commit 9ae1e22950e7c9114e6d0946855de4f6992ac3b4
Author:     Kirill Ponomarev <krion@FreeBSD.org>
AuthorDate: 2024-05-18 05:15:28 +0000
Commit:     Kirill Ponomarev <krion@FreeBSD.org>
CommitDate: 2024-05-18 05:17:59 +0000

    net-mgmt/metronome: Add rc.d script
    
    PR:             239819
    Reported by:    freebsd_at_dns_d_company, tremere_at_cainites_d_net
---
 GIDs                                  |  2 +-
 UIDs                                  |  2 +-
 net-mgmt/metronome/Makefile           | 18 ++++++++++++++++--
 net-mgmt/metronome/files/metronome.in | 35 +++++++++++++++++++++++++++++++++++
 net-mgmt/metronome/pkg-plist          |  1 +
 5 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/GIDs b/GIDs
index ea5e397c234b..a68dfd3cc521 100644
--- a/GIDs
+++ b/GIDs
@@ -285,7 +285,7 @@ stunnel:*:341:
 openfire:*:342:
 gunicorn:*:343:
 snmpd:*:344:
-# free: 345
+_metronome:*:345:
 # free: 346
 eturnal:*:347:
 # free: 348
diff --git a/UIDs b/UIDs
index ceba79b7c0fc..7c31a52724e7 100644
--- a/UIDs
+++ b/UIDs
@@ -290,7 +290,7 @@ stunnel:*:341:341::0:0:Stunnel Daemon:/nonexistent:/usr/sbin/nologin
 openfire:*:342:342::0:0:Openfire IM Daemon:/nonexistent:/usr/sbin/nologin
 gunicorn:*:343:343::0:0:Gunicorn Daemon:/nonexistent:/usr/sbin/nologin
 snmpd:*:344:344::0:0:Net-SNMP Daemon:/nonexistent:/usr/sbin/nologin
-# free: 345
+_metronome:*:345:345::0:0:Metronome Daemon:/nonexistent:/usr/sbin/nologin
 # free: 346
 eturnal:*:347:347::0:0:eturnal User:/var/spool/eturnal:/bin/sh
 # free: 348
diff --git a/net-mgmt/metronome/Makefile b/net-mgmt/metronome/Makefile
index 0d4370239897..f42f4d0bfad8 100644
--- a/net-mgmt/metronome/Makefile
+++ b/net-mgmt/metronome/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	metronome
 DISTVERSION=	0.9.0
-PORTREVISION=	20
+PORTREVISION=	21
 CATEGORIES=	net-mgmt dns
 
 MAINTAINER=	krion@FreeBSD.org
@@ -13,21 +13,35 @@ LICENSE_FILE=	${WRKSRC}/LICENSE
 LIB_DEPENDS=	libboost_thread.so:devel/boost-libs
 
 USES=		autoreconf:build compiler:c++11-lang eigen:3 libtool:build \
-	localbase:ldflags pathfix pkgconfig
+		localbase:ldflags pathfix pkgconfig
 USE_CXXSTD=	c++14
 USE_GITHUB=	yes
 GH_ACCOUNT=	ahupowerdns
 USE_LDCONFIG=	yes
+USE_RC_SUBR=	metronome
 
 GNU_CONFIGURE=	yes
 
 INSTALL_TARGET=	install-strip
 
 SUB_FILES=	pkg-message
+SUB_LIST+=	METRONOME_DBDIR=${METRONOME_DBDIR} \
+		METRONOME_USER=${METRONOME_USER}
 
+METRONOME_USER?=	_metronome
+USERS=			${METRONOME_USER}
+GROUPS=			${METRONOME_USER}
+
+PLIST_SUB+=	METRONOME_DBDIR=${METRONOME_DBDIR} \
+		METRONOME_USER=${METRONOME_USER}
 OPTIONS_DEFINE=	DOCS
 
+METRONOME_DBDIR?=	/var/db/metronome
+
 pre-configure:
 	(cd ${WRKSRC}; ./bootstrap )
 
+post-install:
+	${MKDIR} ${STAGEDIR}${METRONOME_DBDIR}
+
 .include <bsd.port.mk>
diff --git a/net-mgmt/metronome/files/metronome.in b/net-mgmt/metronome/files/metronome.in
new file mode 100644
index 000000000000..d402442033a7
--- /dev/null
+++ b/net-mgmt/metronome/files/metronome.in
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+# PROVIDE: metronome
+# REQUIRE: DAEMON SERVERS
+# KEYWORD: shutdown
+
+#
+# Add the following line to /etc/rc.conf to enable metronome:
+#
+# metronome_enable="YES"
+#
+# The next lines are optional since they have defaults
+#
+# metronome_carbonaddress="<set as needed>"
+# metronome_wsaddress="<set as needed>"
+# metronome_statsdir="<set as needed>"
+#
+
+. /etc/rc.subr
+
+name=metronome
+rcvar=${name}_enable
+
+load_rc_config ${name}
+: ${metronome_enable:=NO}
+: ${metronome_carbonaddress:=127.0.0.1:2003}
+: ${metronome_wsaddress:=127.0.0.1:8000}
+: ${metronome_statsdir:=%%METRONOME_DBDIR%%}
+
+pidfile=/var/run/${name}.pid
+actual_command="%%PREFIX%%/bin/${name} --daemon 0 --carbon-address ${metronome_carbonaddress} --webserver-address ${metronome_wsaddress} --stats-directory ${metronome_statsdir}"
+command=/usr/sbin/daemon
+command_args="-c -f -r -u %%METRONOME_USER%% -P ${pidfile} -- ${actual_command}"
+
+run_rc_command "$1"
diff --git a/net-mgmt/metronome/pkg-plist b/net-mgmt/metronome/pkg-plist
index 23b0c9115efc..b854edfbdb9b 100644
--- a/net-mgmt/metronome/pkg-plist
+++ b/net-mgmt/metronome/pkg-plist
@@ -18,3 +18,4 @@ bin/msubmit
 %%DATADIR%%/html/legend.css
 %%DATADIR%%/html/lines.css
 %%DATADIR%%/html/local.js
+@dir(%%METRONOME_USER%%, %%METRONOME_USER%%, ) %%METRONOME_DBDIR%%