sysutils/loki: add promtail rc.d script

Promtail is a log reader and it can be run as a service to gather the
logs to be sent to remote loki server. For nodes that need to send logs
only, promtail service and configuration file is needed

PR:		274194, 274473
Signed-off-by:	Christopher Beppler <freebsd@funzi.org>
Approved by:	Chirstopher Beppler <freebsd@funzi.org> (maintainer)
This commit is contained in:
Eren Türkay 2023-10-06 09:46:13 +00:00 committed by Robert Clausecker
parent ccbf8b7a16
commit b16c0ca7d0
5 changed files with 96 additions and 4 deletions

2
UIDs
View file

@ -763,7 +763,7 @@ foreman_proxy:*:812:812::0:0:Foreman Smart Proxy:/usr/local/share/foreman-proxy:
hitch:*:813:813::0:0:Hitch TLS Proxy:/nonexistent:/usr/sbin/nologin
puppet:*:814:814::0:0:Puppet Daemon:/nonexistent:/usr/sbin/nologin
uchiwa:*:815:815::0:0:Uchiwa Dashboard:/nonexistent:/usr/sbin/nologin
# free: 816
promtail:*:816:967::0:0:Promtail:/var/db/promtail:/usr/sbin/nologin
rslsync:*:817:817::0:0:Resilio Sync Daemon:/nonexistent:/usr/sbin/nologin
jenkins:*:818:818::0:0:Jenkins CI:/usr/local/jenkins:/bin/sh
rundeck:*:819:819::0:0:Rundeck:/usr/local/rundeck:/bin/sh

View file

@ -326,7 +326,7 @@ GH_TUPLE= \
xdg-go:stringprep:v1.0.4:xdg_go_stringprep/vendor/github.com/xdg-go/stringprep \
yuin:gopher-lua:v1.1.0:yuin_gopher_lua/vendor/github.com/yuin/gopher-lua
USE_RC_SUBR= loki
USE_RC_SUBR= loki promtail
GO_TARGET= ./cmd/loki ./cmd/loki-canary ./cmd/logcli ./clients/cmd/promtail
@ -334,12 +334,17 @@ LOKI_USER?= loki
LOKI_GROUP?= loki
LOKI_DATADIR?= /var/db/${PORTNAME}
USERS= ${LOKI_USER}
PROMTAIL_USER?= promtail
PROMTAIL_DATADIR?= /var/db/promtail
USERS= ${LOKI_USER} ${PROMTAIL_USER}
GROUPS= ${LOKI_GROUP}
SUB_LIST= LOKI_USER=${LOKI_USER} \
LOKI_GROUP=${LOKI_GROUP} \
LOKI_DATADIR=${LOKI_DATADIR}
LOKI_DATADIR=${LOKI_DATADIR} \
PROMTAIL_USER=${PROMTAIL_USER} \
PROMTAIL_DATADIR=${PROMTAIL_DATADIR}
PLIST_SUB= ${SUB_LIST}
@ -372,7 +377,9 @@ post-extract:
post-install:
@${CP} ${WRKSRC}/cmd/loki/loki-local-config.yaml ${STAGEDIR}${PREFIX}/etc/loki.yaml.sample
@${CP} ${WRKSRC}/clients/cmd/promtail/promtail-local-config.yaml ${STAGEDIR}${PREFIX}/etc/promtail.yaml.sample
@${MKDIR} ${STAGEDIR}${LOKI_DATADIR}
@${MKDIR} ${STAGEDIR}${LOKI_DATADIR}/rules-temp
@${MKDIR} ${STAGEDIR}${PROMTAIL_DATADIR}
.include <bsd.port.mk>

View file

@ -0,0 +1,11 @@
--- clients/cmd/promtail/promtail-local-config.yaml.orig 2023-10-05 01:40:22.549761000 +0000
+++ clients/cmd/promtail/promtail-local-config.yaml 2023-10-05 01:41:28.869261000 +0000
@@ -3,7 +3,7 @@
grpc_listen_port: 0
positions:
- filename: /tmp/positions.yaml
+ filename: /var/db/promtail/positions.yaml
clients:
- url: http://localhost:3100/loki/api/v1/push

View file

@ -0,0 +1,70 @@
#!/bin/sh
# PROVIDE: promtail
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable promtail
# promtail_enable="YES"
#
# promtail_enable (bool):
# Set it to YES to enable promtail
# Set to NO by default
# promtail_user (string):
# Set user that promtail will run under
# Default is "%%PROMTAIL_USER%%"
# promtail_group (string):
# Set group that own promtail files
# Default is "%%LOKI_GROUP%%"
# promtail_config (string)
# Set full path to config file
# Default is "%%PREFIX%%/etc/promtail.yaml"
# promtail_logfile (string)
# Set full path to log file
# Default is "/var/log/promtail/promtail.log"
# promtail_loglevel (string)
# Set log level. Only log messages with the given severity or above.
# Valid levels: [debug, info, warn, error]
# Default is "warn"
# promtail_args (string)
# Set additional command line arguments
# Default is ""
. /etc/rc.subr
name=promtail
rcvar=promtail_enable
load_rc_config $name
: ${promtail_enable:="NO"}
: ${promtail_user:="%%PROMTAIL_USER%%"}
: ${promtail_group:="%%LOKI_GROUP%%"}
: ${promtail_config:="%%PREFIX%%/etc/promtail.yaml"}
: ${promtail_logfile:="/var/log/promtail/promtail.log"}
: ${promtail_loglevel:="warn"}
pidfile="/var/run/${name}/${name}.pid"
required_files="${promtail_config}"
procname="%%PREFIX%%/bin/promtail"
command="/usr/sbin/daemon"
command_args="-p ${pidfile} -t ${name} -o ${promtail_logfile} \
${procname} \
--config.file=${promtail_config} \
--log.level=${promtail_loglevel} \
${promtail_args}"
start_precmd="promtail_start_precmd"
promtail_start_precmd() {
if [ ! -d "/var/run/${name}" ]; then
install -d -m 0750 -o ${promtail_user} -g ${promtail_group} "/var/run/${name}"
fi
if [ ! -d "/var/log/promtail" ]; then
install -d -m 0750 -o ${promtail_user} -g ${promtail_group} "/var/log/promtail"
fi
}
run_rc_command "$1"

View file

@ -3,11 +3,15 @@ bin/loki-canary
bin/logcli
bin/promtail
@sample etc/loki.yaml.sample
@sample etc/promtail.yaml.sample
@owner %%LOKI_USER%%
@group %%LOKI_GROUP%%
@mode 750
@dir %%LOKI_DATADIR%%
@dir %%LOKI_DATADIR%%/rules-temp
@owner %%PROMTAIL_USER%%
@mode 750
@dir %%PROMTAIL_DATADIR%%
@mode
@group
@owner