#!/sbin/openrc-run

name="Victoria Metrics"
description="Fast, cost-effective and scalable time series database"

command="/usr/bin/victoria-metrics"
command_args="$victoriametrics_opts"
command_user=victoriametrics:victoriametrics
command_background=yes
pidfile="/run/$RC_SVCNAME.pid"
extra_started_commands="reload"

depend() {
	need net
	after firewall
}

start_pre() {
	if [ -n "$victoriametrics_home" ]; then
		checkpath -d -o $command_user -m755 "$victoriametrics_home"
	fi
	if [ -n "$error_log" ]; then
		checkpath -f -o $command_user "$error_log"
	fi
}

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