#!/sbin/openrc-run

name=lemmy
description="Lemmy Backend"

: ${cfgfile:="/etc/lemmy/lemmy.hjson"}
export LEMMY_CONFIG_LOCATION="${cfgfile}"

command="/usr/bin/lemmy_server"
command_background=true
command_user="lemmy:lemmy"
pidfile="/run/${RC_SVCNAME}.pid"
output_log="/var/log/lemmy.log"
error_log="/var/log/lemmy.err"

required_files="$cfgfile"

depend() {
	need localmount net
	after firewall postgresql
}

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