git: 849ebe16728a - main - devel/cirrus-cli: Add rc.d support

From: Danilo G. Baio <dbaio_at_FreeBSD.org>
Date: Tue, 10 Oct 2023 16:54:19 UTC
The branch main has been updated by dbaio:

URL: https://cgit.FreeBSD.org/ports/commit/?id=849ebe16728a9ccc3b2bf6334b7cd21827fb687b

commit 849ebe16728a9ccc3b2bf6334b7cd21827fb687b
Author:     Danilo G. Baio <dbaio@FreeBSD.org>
AuthorDate: 2023-10-09 20:52:11 +0000
Commit:     Danilo G. Baio <dbaio@FreeBSD.org>
CommitDate: 2023-10-10 16:52:02 +0000

    devel/cirrus-cli: Add rc.d support
    
    Approved by:    bofh (maintainer)
    Differential Revision: https://reviews.freebsd.org/D42140
---
 GIDs                                     |  2 +-
 UIDs                                     |  2 +-
 devel/cirrus-cli/Makefile                | 15 +++++++++++---
 devel/cirrus-cli/files/cirrus-cli.in     | 34 ++++++++++++++++++++++++++++++++
 devel/cirrus-cli/files/cirrus-worker.yml | 12 +++++++++++
 devel/cirrus-cli/files/pkg-message.in    | 11 +++++++++++
 devel/cirrus-cli/pkg-plist               |  8 ++++++++
 7 files changed, 79 insertions(+), 5 deletions(-)

diff --git a/GIDs b/GIDs
index 92053d2e8a01..fb89fc644b5f 100644
--- a/GIDs
+++ b/GIDs
@@ -769,7 +769,7 @@ selenium:*:824:
 polw:*:825:
 statsd:*:826:
 _tuptime:*:827:
-# free: 828
+cirrus:*:828:
 # free: 829
 # free: 830
 # free: 831
diff --git a/UIDs b/UIDs
index 37c8a75bed22..d3900898c438 100644
--- a/UIDs
+++ b/UIDs
@@ -775,7 +775,7 @@ selenium:*:824:824::0:0:Selenium Daemon User:/usr/local/selenium:/bin/sh
 polw:*:825:825::0:0:Policyd-weight Cache Owner:/nonexistent:/sbin/nologin
 statsd:*:826:826::0:0:Statsd Daemon:/nonexistent:/sbin/nologin
 _tuptime:*:827:827::0:0:Tuptime:/var/lib/tuptime:/usr/sbin/nologin
-# free: 828
+cirrus:*:828:828::0:0:Cirrus CI:/usr/local/cirrus:/bin/sh
 # free: 829
 # free: 830
 # free: 831
diff --git a/devel/cirrus-cli/Makefile b/devel/cirrus-cli/Makefile
index a60ac7079c85..43a98cca6460 100644
--- a/devel/cirrus-cli/Makefile
+++ b/devel/cirrus-cli/Makefile
@@ -1,9 +1,10 @@
 PORTNAME=	cirrus-cli
 PORTVERSION=	0.106.0
 DISTVERSIONPREFIX=	v
+PORTREVISION=	1
 CATEGORIES=	devel
-MASTER_SITES=   https://raw.githubusercontent.com/${GH_ACCOUNT}/${GH_PROJECT}/${DISTVERSIONFULL}/:gomod
-DISTFILES=      go.mod:gomod
+MASTER_SITES=	https://raw.githubusercontent.com/${GH_ACCOUNT}/${GH_PROJECT}/${DISTVERSIONFULL}/:gomod
+DISTFILES=	go.mod:gomod
 
 MAINTAINER=	bofh@FreeBSD.org
 COMMENT=	Command line interface for Cirrus CI
@@ -16,10 +17,18 @@ USES=		go:modules
 USE_GITHUB=	yes
 GH_ACCOUNT=	cirruslabs
 
+USE_RC_SUBR=	${PORTNAME}
+
 GO_MODULE=	github.com/cirruslabs/cirrus-cli
 GO_TARGET=	./cmd/cirrus
 GO_BUILDFLAGS=	-ldflags="-X github.com/cirruslabs/cirrus-cli/internal/version.Version=${PORTVERSION}"
 
-PLIST_FILES=	bin/cirrus
+SUB_FILES=	pkg-message
+
+USERS=		cirrus
+GROUPS=		cirrus
+
+post-install:
+	${INSTALL_DATA} ${FILESDIR}/cirrus-worker.yml ${STAGEDIR}${PREFIX}/etc/cirrus-worker.yml.sample
 
 .include <bsd.port.mk>
diff --git a/devel/cirrus-cli/files/cirrus-cli.in b/devel/cirrus-cli/files/cirrus-cli.in
new file mode 100644
index 000000000000..cb531a48f7cc
--- /dev/null
+++ b/devel/cirrus-cli/files/cirrus-cli.in
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# PROVIDE: cirrus_cli
+# REQUIRE: LOGIN
+# KEYWORD: shutdown
+#
+# Options to configure cirrus-cli via /etc/rc.conf:
+#
+# cirrus_cli_enable (bool)	Enable service on boot
+#				Default: NO
+#
+# cirrus_cli_conf (str)	Config file to use
+#				Default: %%ETCDIR%%/cirrus-worker.yml
+#
+# cirrus_cli_uid (str)	User to run cirrus_cli as
+#				Default: cirrus
+
+. /etc/rc.subr
+
+name="cirrus"
+rcvar="cirrus_cli_enable"
+pidfile="/var/run/cirrus-cli.pid"
+procname="%%PREFIX%%/bin/cirrus"
+
+load_rc_config $name
+
+: ${cirrus_cli_enable:="NO"}
+: ${cirrus_cli_conf:="%%PREFIX%%/etc/cirrus-worker.yml"}
+: ${cirrus_cli_uid:="cirrus"}
+
+command="/usr/sbin/daemon"
+command_args="-p ${pidfile} -u ${cirrus_cli_uid} ${procname} worker run -f ${cirrus_cli_conf}"
+
+run_rc_command "$1"
diff --git a/devel/cirrus-cli/files/cirrus-worker.yml b/devel/cirrus-cli/files/cirrus-worker.yml
new file mode 100644
index 000000000000..26d893e9d85f
--- /dev/null
+++ b/devel/cirrus-cli/files/cirrus-worker.yml
@@ -0,0 +1,12 @@
+token: CHANGEME
+
+name: cirrus1-on-premises-change-me
+
+labels:
+  jail: FreeBSD
+
+log:
+  level: info
+  file: /usr/local/cirrus/cirrus-worker.log
+  rotate-size: 100 MB
+  max-rotations: 10
diff --git a/devel/cirrus-cli/files/pkg-message.in b/devel/cirrus-cli/files/pkg-message.in
new file mode 100644
index 000000000000..72efed9b5a12
--- /dev/null
+++ b/devel/cirrus-cli/files/pkg-message.in
@@ -0,0 +1,11 @@
+[
+{ type: install
+  message: <<EOM
+A sample configuration file is installed at %%PREFIX%%/etc/cirrus-worker.yml,
+requiring a few modifications to work correctly.
+
+For more details about the configuration file, please refer to:
+https://github.com/cirruslabs/cirrus-cli/blob/master/PERSISTENT-WORKERS.md#configuration
+EOM
+}
+]
diff --git a/devel/cirrus-cli/pkg-plist b/devel/cirrus-cli/pkg-plist
new file mode 100644
index 000000000000..a4eebe651ac2
--- /dev/null
+++ b/devel/cirrus-cli/pkg-plist
@@ -0,0 +1,8 @@
+bin/cirrus
+@owner root
+@group cirrus
+@mode 0640
+@sample etc/cirrus-worker.yml.sample
+@mode
+@group
+@owner