#!/bin/sh
#
# $NetBSD: innd.sh,v 1.19 2025/10/10 16:02:16 hauke Exp $
#
# PROVIDE: inn
# REQUIRE: DAEMON
# KEYWORD: shutdown

if [ -f /etc/rc.subr ]
then
  . /etc/rc.subr
fi

name="inn"
rcvar=${name}
command="/usr/pkg/libexec/inn/rc.news"
procname="/usr/pkg/libexec/inn/innwatch"
command_interpreter="/bin/sh"
inn_user="news"
required_files="/usr/pkg/libexec/inn/rc.news /var/news/db/active"
pidfile="/var/news/run/innwatch.pid"

start_precmd="inn_precmd"
start_cmd="inn_start"
stop_cmd="inn_stop"


if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]
then
        load_rc_config ${name}
elif [ -f /etc/rc.conf ]
then
        . /etc/rc.conf
fi

inn_precmd()
{
	if [ -f /var/news/db/history -a \
		! -s /var/news/db/history ]
	then
		/usr/pkg/libexec/inn/makedbz -i -o -s 10000
	fi
}

inn_start()
{
        echo "Starting ${name}."
        doit="/usr/bin/su -m ${inn_user} -c '${command} start ${command_args} >/dev/null'"
        eval $doit
}

inn_stop()
{
        echo "Stopping ${name}."
        doit="/usr/bin/su -m ${inn_user} -c '${command} stop ${command_args} >/dev/null'"
        eval $doit
}

run_rc_command "$1"
