#!/bin/sh
#
# $NetBSD: soju.sh,v 1.1 2024/09/16 12:55:51 wiz Exp $
#
# PROVIDE: soju
# REQUIRE: DAEMON

$_rc_subr_loaded . /etc/rc.subr

name="soju"
rcvar=${name}
pidfile="/var/run/${name}.pid"
procname="/usr/pkg/bin/soju"
command="/usr/pkg/sbin/daemonize"
command_args="${command_args} -a"
command_args="${command_args} -o /var/log/soju/stdout.log"
command_args="${command_args} -e /var/log/soju/stderr.log"
command_args="${command_args} -p ${pidfile}"
command_args="${command_args} -u soju"
command_args="${command_args} ${procname}"
required_files="/usr/pkg/etc/soju/config"
extra_commands="reload"
start_precmd=soju_prestart

soju_prestart() {
	dir="/var/run/soju"
	if test ! -d $dir; then
		/bin/mkdir -p $dir
		/bin/chmod 0700 $dir
		/usr/sbin/chown soju:soju $dir
	fi
}

load_rc_config $name
run_rc_command "$1"
