#!/bin/sh

# PROVIDE: milter-manager
# REQUIRE: LOGIN
# BEFORE: mail
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable milter-manager:
#
#   milter_manager_enable=yes
#

. /etc/rc.subr

name="milter_manager"
rcvar=`set_rcvar`
extra_commands="reload"

load_rc_config $name
: ${milter_manager_enable="NO"}
: ${milter_manager_pid_file="/var/run/milter-manager/milter-manager.pid"}
if getent passwd milter-manager > /dev/null; then
    : ${milter_manager_user_name="milter-manager"}
else
    : ${milter_manager_user_name="mailnull"}
fi
: ${milter_manager_group_name="mail"}
: ${milter_manager_socket_group_name="mail"}
: ${milter_manager_connection_spec=""}
: ${milter_manager_debug="NO"}

command=/usr/local/sbin/milter-manager
pidfile="${milter_manager_pid_file}"
command_args="--pid-file ${milter_manager_pid_file}"
if test -n "${milter_manager_user_name}"; then
    command_args="${command_args} --user-name ${milter_manager_user_name}"
fi
if test -n "${milter_manager_group_name}"; then
    command_args="${command_args} --group-name ${milter_manager_group_name}"
fi
if test -n "${milter_manager_socket_group_name}"; then
    command_args="${command_args} --socket-group-name ${milter_manager_socket_group_name}"
fi
if test -n "${milter_manager_connection_spec}"; then
    command_args="${command_args} --spec ${milter_manager_connection_spec}"
fi
if test "$milter_manager_debug" = "YES"; then
    command_args="${command_args} --verbose"
else
    command_args="${command_args} --daemon"
fi

run_rc_command "$1"
