#!/bin/sh
#
# $NetBSD: opendkim.sh,v 1.3 2011/06/17 13:49:35 pettai Exp $
#
# PROVIDE: opendkim
# REQUIRE: DAEMON
# BEFORE: mail

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

name="opendkim"
rcvar=$name
command="/usr/pkg/sbin/opendkim"
pidfile="/var/run/opendkim/${name}.pid"
command_args="-P ${pidfile} -l -x /usr/pkg/etc/opendkim.conf -u opendkim:opendkim"
required_files="/usr/pkg/etc/opendkim.conf"
start_precmd="opendkim_precmd"

opendkim_precmd()
{
	if [ ! -d /var/run/opendkim ]; then
		/bin/mkdir -p /var/run/opendkim
		/bin/chmod 0750 /var/run/opendkim
		/usr/sbin/chown opendkim:opendkim /var/run/opendkim
	fi

	if [ -f /var/run/opendkim/${name}.sock ]; then
		/bin/rm -f /var/run/opendkim/${name}.sock
	fi
}

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