#!/bin/sh
#
# $NetBSD: router.sh,v 1.3 2017/01/06 01:52:20 gdt Exp $
#
# PROVIDE: router
# REQUIRE: DAEMON

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

name="router"
rcvar=$name
command="/usr/pkg/bin/${name}"
required_files="/usr/pkg/etc/jabberd/${name}.xml"
extra_commands="reload"
command_args="2>&1 > /dev/null &"
router_user="jabberd"
pidfile="/var/run/jabberd/${name}.pid"
stop_postcmd="remove_pidfile"
start_precmd="ensure_piddir"

ensure_piddir()
{
	mkdir -p /var/run/jabberd
	chown jabberd /var/run/jabberd
}

remove_pidfile()
{
        if [ -f /var/run/jabberd/${name}.pid ]; then
            rm -f /var/run/jabberd/${name}.pid
        fi
}

if [ -f /etc/rc.subr ]; then
	load_rc_config $name
	run_rc_command "$1"
else
	echo -n " ${name}"
	${command} ${router_flags} ${command_args}
fi
