#!/sbin/openrc-run
# managed by ovpmon deploy/native  (install.sh / update.sh replace this file only while this marker line is present)
#
# OpenVPN Monitor gatherer (reads the OpenVPN status log into the monitoring database, APP_CORE),
# OpenRC (Alpine). Install: see ovpmon-api. Settings come from /etc/ovpmon/env.
# The gatherer keeps running while OpenVPN is down (it waits for the status log).

name="ovpmon-gatherer"
description="OpenVPN Monitor Gatherer"

supervisor="supervise-daemon"
respawn_delay=3
respawn_max=0

command_user="ovpmon:ovpmon"
directory="/opt/OpenVPN-Monitoring-Simple/APP_CORE"
command="/opt/OpenVPN-Monitoring-Simple/APP_CORE/venv/bin/python"
command_args="openvpn_gatherer_v3.py"

output_log="/var/log/ovpmon/ovpmon-gatherer.log"
error_log="/var/log/ovpmon/ovpmon-gatherer.log"

depend() {
	need net
	after firewall
}

start_pre() {
	checkpath -f -m 0640 -o ovpmon:ovpmon "$output_log" || return 1
	[ -r /etc/ovpmon/env ] || { eerror "/etc/ovpmon/env is missing"; return 1; }
	set -a
	. /etc/ovpmon/env
	set +a
	# extend, never replace: OpenRC itself needs /lib/rc/bin (ebegin, eend) on the PATH
	export PATH="/usr/local/sbin:/usr/local/bin:$PATH"
}
