#!/sbin/openrc-run

name="${RC_SVCNAME}"
description="N2N Supernode Daemon"

[ ${RC_SVCNAME##*.} = $RC_SVCNAME ] || instance=${RC_SVCNAME##*.}
[ -n "$instance" ] && : ${cfgfile:=/etc/n2n/supernode-$instance.conf}
: ${cfgfile:=/etc/n2n/supernode.conf}

command="/usr/sbin/supernode"
command_args="$cfgfile ${command_opts}"
command_args_foreground="-f"
supervisor="supervise-daemon"

pidfile="/run/${RC_SVCNAME}.pid"
output_log="/var/log/${RC_SVCNAME}.log"
error_log="/var/log/${RC_SVCNAME}.log"

retry="${SUPERNODE_RETRY:-TERM/60/KILL/10}"

depend() {
	need net
	after firewall
}

start_pre() {
	checkpath -f -m 0644 -o "$command_user" "$output_log" "$error_log"
	checkpath -f -m 0640 -o "$command_user" "$cfgfile"
}
