#!/sbin/openrc-run

owner=opendkim
pidfile=/run/opendkim/opendkim.pid
cfgfile=/etc/opendkim/opendkim.conf
command=/usr/sbin/opendkim
command_args="$command_args -u $owner -f"
command_background=yes
required_files="$cfgfile"

depend() {
	need net
	before mta
}

start_pre() {
	local socket=$(grep ^Socket.*local: $cfgfile | cut -d: -f2)
	local basedir=$(grep ^BaseDirectory $cfgfile | awk '{print $2}')
	[ "${socket:0:1}" = "/" ] && checkpath -d -o $owner ${socket%/*}
	[ "$basedir" ] && checkpath -d -o $owner $basedir
	checkpath -d -o $owner ${pidfile%/*}
}