#!/bin/sh
#
# $NetBSD: anubis.sh,v 1.2 2025/05/24 14:41:18 ryoon Exp $
#
# PROVIDE: anubis
# REQUIRE: DAEMON
#
# anubis=YES

$_rc_subr_loaded . /etc/rc.subr

name="anubis"
rcvar=${name}
command="/usr/pkg/bin/${name}"
pidfile="/var/run/${name}/${name}.pid"
anubis_user="www"
anubis_group="www"
start_precmd="anubis_precmd"
start_cmd="anubis_start"
start_postcmd="anubis_poststart"
anubis_environment_file="/usr/pkg/etc/anubis/default.env"

anubis_precmd()
{
	export $(/usr/bin/xargs < ${anubis_environment_file})

	if [ ! -d /var/run/${name} ]; then
		/bin/mkdir -p /var/run/${name}
		/usr/sbin/chown ${anubis_user}:${anubis_group} /var/run/${name}
	fi
}

anubis_start()
{
	/usr/bin/su -m ${anubis_user} -c "${command}" >> /var/log/anubis.log 2>&1 &
}

anubis_poststart() {
	echo $! > ${pidfile}
}

anubis_stop()
{
	kill -HUP $(check_pidfile $pidfile $name)
}

load_rc_config $name
run_rc_command "$1"
