git: 72d7dcd1e59c - main - databases/greptimedb: Add RC script, config files, DB and log directories

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Mon, 19 Feb 2024 10:09:42 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=72d7dcd1e59c4283ee0c33592da99d39df47c88b

commit 72d7dcd1e59c4283ee0c33592da99d39df47c88b
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2024-02-19 08:50:24 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2024-02-19 10:09:39 +0000

    databases/greptimedb: Add RC script, config files, DB and log directories
---
 databases/greptimedb/Makefile            |  26 +++++--
 databases/greptimedb/files/greptimedb.in | 126 +++++++++++++++++++++++++++++++
 databases/greptimedb/pkg-plist           |   9 +++
 3 files changed, 156 insertions(+), 5 deletions(-)

diff --git a/databases/greptimedb/Makefile b/databases/greptimedb/Makefile
index efe5ce2b3314..da4d89b98563 100644
--- a/databases/greptimedb/Makefile
+++ b/databases/greptimedb/Makefile
@@ -2,6 +2,7 @@ PORTNAME=	greptimedb
 DISTVERSIONPREFIX=	v
 DISTVERSION=	0.7.0-nightly-20240115-102
 DISTVERSIONSUFFIX=	-g29f11d7b7e
+PORTREVISION=	1
 CATEGORIES=	databases
 
 MAINTAINER=	yuri@FreeBSD.org
@@ -18,6 +19,7 @@ BUILD_DEPENDS=	gmake:devel/gmake \
 LIB_DEPENDS=	libzstd.so:archivers/zstd
 
 USES=		cargo
+USE_RC_SUBR=	greptimedb
 
 USE_GITHUB=	yes
 GH_ACCOUNT=	GreptimeTeam
@@ -950,20 +952,34 @@ CARGO_CRATES=	Inflector-0.11.4 \
 		unicode_names2@git+https://github.com/youknowone/unicode_names2.git?rev=4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde\#4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde \
 		opentelemetry,opentelemetry-proto,opentelemetry_sdk@git+https://github.com/waynexia/opentelemetry-rust.git?rev=33841b38dda79b15f2024952be5f32533325ca02\#33841b38dda79b15f2024952be5f32533325ca02
 
+USER=		nobody
+GROUP=		nobody
+
+SUB_LIST+=	USER=${USER} GROUP=${GROUP}
+PLIST_SUB+=	USER=${USER} GROUP=${GROUP}
+
 PROGS=		greptime \
 		nyc-taxi \
 		sqlness-runner
 
-PLIST_FILES=	${PROGS:S/^/bin\//}
-
-BINARY_ALIAS=	git=false
-
 do-install:
-	# workaround for error: found a virtual manifest at `xx` instead of a package manifest
+	# binaries (workaround for error: found a virtual manifest at `xx` instead of a package manifest)
 .for p in ${PROGS}
 	${INSTALL_PROGRAM} \
 		${WRKDIR}/target/*/release/${p} \
 		${STAGEDIR}${PREFIX}/bin
 .endfor
+	# config files
+	${MKDIR} ${STAGEDIR}${ETCDIR}
+.for name in datanode frontend metasrv standalone
+	${INSTALL_DATA} ${WRKSRC}/config/${name}.example.toml ${STAGEDIR}${ETCDIR}/${name}.toml.sample
+.endfor
+	${REINPLACE_CMD} -i '' -e 's|data_home = "/tmp/greptimedb/"|data_home = "/var/db/greptimedb/"|' ${STAGEDIR}${ETCDIR}/*.toml.sample
+	# RC script
+	${INSTALL_DATA} ${WRKDIR}/greptimedb ${STAGEDIR}/${PREFIX}/etc/rc.d
+	# create dirs
+	${MKDIR} \
+		${STAGEDIR}/var/db/greptimedb \
+		${STAGEDIR}/var/log/greptimedb
 
 .include <bsd.port.mk>
diff --git a/databases/greptimedb/files/greptimedb.in b/databases/greptimedb/files/greptimedb.in
new file mode 100644
index 000000000000..5fe613368e2d
--- /dev/null
+++ b/databases/greptimedb/files/greptimedb.in
@@ -0,0 +1,126 @@
+#!/bin/sh
+
+# PROVIDE: greptimedb
+# REQUIRE: LOGIN
+# KEYWORD: shutdown
+#
+# Add the following lines to /etc/rc.conf to run greptimedb:
+#
+# greptimedb_profiles (str):     Set to "" by default.
+#                               Define your profiles here.
+# greptimedb(_profile)?_enable (bool):	Set it to "YES" to enable greptimedb.
+#				Default is "NO".
+# greptimedb(_profile)?_args (flags):	Set extra args here. More options in greptimedb(1)
+#				Default is "--log-dir=/var/log/greptimedb --log-level=info \
+#				standalone start -c %%ETCDIR%%/standalone.toml"
+#				for the 'standalone' mode.
+# greptimedb(_profile)?_user (user):	Set user to run greptimedb.
+#				Default is "nobody".
+# greptimedb(_profile)?_group (group):	Set group to run greptimedb.
+#				Default is "nobody".
+# greptimedb(_profile)?_post_start (str):   Set extra commands that should be executed after greptimedb was successfully
+#                               started here.
+#                               Default is empty "".
+
+. /etc/rc.subr
+
+name="greptimedb"
+rcvar=greptimedb_enable
+
+_piddir="/var/run/greptimedb"
+pidfile="${_piddir}/greptimedb.pid"
+
+: ${greptimedb_enable="NO"}
+: ${greptimedb_user="%%USER%%"}
+: ${greptimedb_group="%%GROUP%%"}
+: ${greptimedb_args="--log-dir=/var/log/greptimedb --log-level=info standalone start -c %%ETCDIR%%/standalone.toml"} # standalone mode
+
+load_rc_config ${name}
+
+if [ -n "$2" ]; then # profile is provided
+	profile="$2"
+	if [ -n "${greptimedb_profiles}" ]; then
+		pidfile="${_piddir}/greptimedb.${profile}.pid"
+		eval greptimedb_enable="\${greptimedb_${profile}_enable:-${greptimedb_enable}}"
+                eval greptimedb_user="\${greptimedb_${profile}_user:-${greptimedb_user}}"
+                eval greptimedb_group="\${greptimedb_${profile}_group:-${greptimedb_group}}"
+		eval greptimedb_args="\${greptimedb_${profile}_args:-${greptimedb_args}}"
+		eval greptimedb_post_start="\${greptimedb_${profile}_post_start:-${greptimedb_post_start}}"
+	else
+		echo "%%PREFIX%%/etc/rc.d/greptimedb: extra argument ignored"
+	fi
+else # profile is not provided
+	if [ -n "${greptimedb_profiles}" -a -n "$1" ]; then
+		for profile in ${greptimedb_profiles}; do
+			eval _enable="\${greptimedb_${profile}_enable}"
+			case "${_enable:-${greptimedb_enable}}" in
+			[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+				continue
+				;;
+			[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+				;;
+			*)
+				if test -z "$_enable"; then
+					_var=greptimedb_enable
+				else
+					_var=greptimedb_"${profile}"_enable
+				fi
+				warn "Bad value" \
+				    "'${_enable:-${greptimedb_enable}}'" \
+				    "for ${_var}. " \
+				    "Profile ${profile} skipped."
+				continue
+				;;
+			esac
+			echo "===> greptimedb profile: ${profile}"
+			if %%PREFIX%%/etc/rc.d/greptimedb $1 ${profile} ; then
+				success="${profile} ${success:-}"
+			else
+				failed="${profile} (${retcode}) ${failed:-}"
+			fi
+		done
+		exit 0
+	fi
+fi
+
+greptimedb_poststart()
+{
+    if [ -n "$greptimedb_post_start" ]; then
+        eval $greptimedb_post_start
+    fi
+}
+
+greptimedb_poststop()
+{
+	if [ -n "${profile}" ]; then
+		[ -e "$pidfile" ] && unlink $pidfile
+	else
+		local file
+
+		for file in ${_piddir}/* ; do
+			case "$file" in
+			*\*)
+				continue ;;
+			esac
+			unlink $file
+		done
+	fi
+}
+
+_profsuffx=""
+if [ -n "${profile}" ]; then
+	_profsuffx="-${profile}"
+fi
+
+procname=%%PREFIX%%/bin/greptime
+command="/usr/sbin/daemon"
+command_args="-f -S -p ${pidfile} \
+	-t greptimedb${_profsuffx} \
+	%%PREFIX%%/bin/greptime $greptimedb_args"
+
+
+start_precmd="install -d -o $greptimedb_user -g $greptimedb_group -m 755 $_piddir"
+start_postcmd="${name}_poststart"
+stop_postcmd="${name}_poststop"
+
+run_rc_command "$1"
diff --git a/databases/greptimedb/pkg-plist b/databases/greptimedb/pkg-plist
new file mode 100644
index 000000000000..1f2e39d2b8b0
--- /dev/null
+++ b/databases/greptimedb/pkg-plist
@@ -0,0 +1,9 @@
+bin/greptime
+bin/nyc-taxi
+bin/sqlness-runner
+@sample %%ETCDIR%%/datanode.toml.sample
+@sample %%ETCDIR%%/frontend.toml.sample
+@sample %%ETCDIR%%/metasrv.toml.sample
+@sample %%ETCDIR%%/standalone.toml.sample
+@dir(%%USER%%,%%GROUP%%,) /var/db/greptimedb
+@dir(%%USER%%,%%GROUP%%,) /var/log/greptimedb