#!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

: ${NITTER_CONF_FILE:="/etc/nitter/${RC_SVCNAME}.conf"}
export NITTER_CONF_FILE

command="/usr/bin/nitter"
command_background=yes
command_user="nitter:nitter"
pidfile="/run/${RC_SVCNAME}.pid"

logpath="/var/log/nitter"
output_log="${logpath}/${RC_SVCNAME}.log"
error_log="${output_log}"

depend() {
	need redis
	use net
}

start_pre() {
	checkpath -do "${command_user}" "${logpath}"
	checkpath -fo "${command_user}" "${output_log}"

	if [ ! -f "${NITTER_CONF_FILE}" ]; then
		eerror "Configuration file '${NITTER_CONF_FILE}' not found"
		return 1
	fi
}
