ports/mail/dovecot22/files/dovecot.in
Larry Rosenman 07090b75cb mail/dovecot, mail/dovecot22: suppress harmless error message when the symlink in /var/run/dovecot
to the config file doesn't exist.

PR:		225078
Reported by:	pkubaj@anongoth.pl
Reviewed by:	adamw
MFH:		2018Q3
2018-08-19 21:00:17 +00:00

75 lines
2 KiB
Bash

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: dovecot
# REQUIRE: %%REQUIRE%%
# BEFORE: mail
# KEYWORD: shutdown
# dovecot_enable (bool): Set it to YES to enable dovecot
# Default: NO
# dovecot_config (str): Path to dovecot.conf
# Default: %%ETCDIR%%/dovecot.conf
# Set it to a space-separated list to start
# multiple dovecot instances
# dovecot_flags (str): Extra flags to pass to dovecot
# Default: empty
# Define dovecot_* variables in one of these files:
# /etc/rc.conf
# /etc/rc.conf.local
# /etc/rc.conf.d/dovecot
. /etc/rc.subr
name=dovecot
rcvar=dovecot_enable
# read configuration and set defaults
load_rc_config ${name}
: ${dovecot_enable:="NO"}
: ${dovecot_config:="%%ETCDIR%%/${name}.conf"}
command="%%PREFIX%%/sbin/${name}"
start_precmd="start_precmd"
stop_postcmd="stop_postcmd"
restart_cmd="restart_cmd"
extra_commands="reload"
start_precmd()
{ # Ensure runtime directories exist with correct permissions
local login_user login_gid
login_user=$(${command} ${command_args} -a | /usr/bin/awk -F '= ' '/^default_login_user =/ { print $2 }')
login_gid=$(/usr/sbin/pw usershow -n "${login_user}" 2>/dev/null | /usr/bin/cut -d: -f4)
/usr/bin/install -o root -g wheel -m 0755 -d ${base_dir}
}
stop_postcmd()
{ # Cleanup runtime directories
rm -rf ${base_dir} 2>/dev/null
}
restart_cmd()
{ # Overriding makes rc.subr run this once for each instance
run_rc_command stop
run_rc_command start
}
# To start multiple instances of dovecot set dovecot_config to
# a space separated list of configuration files.
for config in ${dovecot_config}; do
required_files="${config}"
command_args="-c ${config}"
if [ -s ${config} ]; then
base_dir=$(${command} ${command_args} -a 2>/dev/null | /usr/bin/awk -F '= ' '/^base_dir =/ { print $2 }')
pidfile="${base_dir}/master.pid"
else
echo "==Error=="
echo "Config file ${config} does not exist. If this is"
echo "a new installation, please create the config files as outlined in"
echo " # pkg info -D dovecot2"
fi
run_rc_command "$1"
done