#!/sbin/openrc-run

: ${command_user:="vector:vector"}
: ${logfile:="/var/log/$RC_SVCNAME.log"}

name=vector
description="Vector high-performance observability data pipeline"
command="/usr/bin/vector"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"
capabilities="^cap_net_bind_service"

extra_started_commands="reload"
description_reload="Reload vector daemon"

output_log="$logfile"
error_log="$logfile"

depend() {
	need net
	after firewall
}

start_pre() {
	checkpath -d -o $command_user /var/lib/vector
	$command validate
}

reload() {
	ebegin "Reloading $RC_SVCNAME"
	$command validate
	if [ -n "$supervisor" ]; then
		$supervisor "$RC_SVCNAME" --signal HUP
	else
		start-stop-daemon --signal HUP --pidfile "$pidfile"
	fi
	eend $?
}
