#!/bin/sh

# PROVIDE: pwhoisd
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line(s) to /etc/rc.conf to enable pwhoisd:
#
#  pwhoisd_enable="YES"
#

. /etc/rc.subr

name=pwhoisd
rcvar=pwhoisd_enable
load_rc_config $name

# Set defaults
pwhoisd_enable=${pwhoisd_enable:-"NO"}

_logdir=/var/log/pwhois
_dbdir=/var/db/pwhois
pidfile=/var/run/pwhoisd.pid
command=/usr/local/sbin/pwhoisd
command_args="-d -u 512 -g 512"
required_files=/usr/local/etc/pwhois/pwhoisd.conf

start_precmd=pwhoisd_precmd
stop_postcmd=pwhoisd_cleanup

pwhoisd_precmd()
{
    [ ! -f $pidfile ] && /usr/bin/touch $pidfile && /usr/sbin/chown pwhois:pwhois $pidfile
    install -d -o pwhois -g pwhois $_dbdir
    install -d -o pwhois -g pwhois $_logdir
    return 0
}

pwhoisd_cleanup() {
    [ -f ${pidfile} ] && /bin/rm -f ${pidfile}
}

run_rc_command "$1"
