#!/bin/sh

# PROVIDE: qpsmtpd
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# qpsmtpd_enable (bool):	Set to NO by default
#		Set it to YES to enable qpsmtpd
# qpsmtpd_user (string):	Set to "nobody" by default
#		The user to run qpsmtpd-forkserver as
# qpsmtpd_group (string):	Set to "nogroup" by default
#		The group the pid dir will be chowned to
# qpsmtpd_port (int):		Set to 2525 by default
#		The port it should listen on
# qpsmtpd_max_per_ip (int):	Set to 3 by default
#		Max connections per IP
# qpsmtpd_max_connections (int): Set to 15 by default
#		Maximum total connections
# qpsmtpd_listen_on (address):	Set to 0.0.0.0 by default
# 		IP address to listen on

. /etc/rc.subr

name="qpsmtpd"
rcvar=qpsmtpd_enable

command="%%PREFIX%%/bin/qpsmtpd-forkserver"
command_interpreter=%%PERL%%
pidfile="/var/run/qpsmtpd/qpsmtpd.pid"

start_precmd=${name}_prestart

qpsmtpd_prestart()
{
	[ -d /var/run/qpsmtpd ] || mkdir /var/run/qpsmtpd
	chown $qpsmtpd_user:$qpsmtpd_group /var/run/qpsmtpd
}

load_rc_config $name

: ${qpsmtpd_enable="NO"}
: ${qpsmtpd_user="nobody"}
: ${qpsmtpd_group="nogroup"}
: ${qpsmtpd_port="2525"}
: ${qpsmtpd_max_per_ip="3"}
: ${qpsmtpd_max_connections="15"}
: ${qpsmtpd_listen_on="0.0.0.0"}

command_args="-d -p $qpsmtpd_port -c $qpsmtpd_max_connections -u $qpsmtpd_user -m $qpsmtpd_max_per_ip -l $qpsmtpd_listen_on --pid-file $pidfile"

run_rc_command "$1"
