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

: ${INVIDIOUS_CONFIG_FILE:=/etc/invidious/config.yml}

name="Invidious"
description="An alternative YouTube front-end"
command="/usr/bin/invidious"
command_user="invidious:invidious"
command_background=1
pidfile="/run/invidious.pid"
output_log="/var/log/invidious.log"
error_log="${output_log}"

# Invidious hard depends on PostgreSQL, and fails to start if PostgreSQL hasn't already started.
# So it will fail to start if started at boot (rc-update add invidious default).
# See: https://bugs.gentoo.org/916051
# Using 'postgresql' as 'use' in the 'depend' function fixes this behaviour.
depend() {
	use logger net postgresql
}

start_pre() {
	checkpath -fo invidious:invidious /var/log/invidious.log
	export INVIDIOUS_CONFIG_FILE
}
