2010-11-27 05:53:35 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# PROVIDE: dovecot
|
|
|
|
# REQUIRE: %%REQUIRE%%
|
2018-06-13 20:59:52 +00:00
|
|
|
# BEFORE: mail
|
2010-11-27 05:53:35 +00:00
|
|
|
# KEYWORD: shutdown
|
|
|
|
|
2016-06-09 16:00:11 +00:00
|
|
|
# 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
|
|
|
|
|
2010-11-27 05:53:35 +00:00
|
|
|
# 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
|
2012-01-14 08:57:23 +00:00
|
|
|
rcvar=dovecot_enable
|
2010-11-27 05:53:35 +00:00
|
|
|
|
|
|
|
# read configuration and set defaults
|
|
|
|
load_rc_config ${name}
|
|
|
|
: ${dovecot_enable:="NO"}
|
2011-02-05 16:51:50 +00:00
|
|
|
: ${dovecot_config:="%%ETCDIR%%/${name}.conf"}
|
2010-11-27 05:53:35 +00:00
|
|
|
|
|
|
|
command="%%PREFIX%%/sbin/${name}"
|
|
|
|
start_precmd="start_precmd"
|
|
|
|
stop_postcmd="stop_postcmd"
|
|
|
|
restart_cmd="restart_cmd"
|
2014-12-12 15:21:11 +00:00
|
|
|
extra_commands="reload"
|
2010-11-27 05:53:35 +00:00
|
|
|
|
|
|
|
start_precmd()
|
2018-04-01 17:10:31 +00:00
|
|
|
{ # Ensure runtime directory exists with correct permissions
|
2010-11-27 05:53:35 +00:00
|
|
|
/usr/bin/install -o root -g wheel -m 0755 -d ${base_dir}
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_postcmd()
|
2018-04-01 17:10:31 +00:00
|
|
|
{ # Cleanup runtime directory. The dovecot.conf link has to stay.
|
|
|
|
/usr/bin/find ${base_dir} ! -type l -delete
|
2010-11-27 05:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-06-09 16:00:11 +00:00
|
|
|
# a space separated list of configuration files.
|
2014-10-27 15:45:19 +00:00
|
|
|
for config in ${dovecot_config}; do
|
|
|
|
required_files="${config}"
|
|
|
|
command_args="-c ${config}"
|
2016-09-18 16:38:28 +00:00
|
|
|
if [ -s ${config} ]; then
|
2018-10-30 14:04:21 +00:00
|
|
|
${command} ${command_args} -a 2>&1 >/dev/null
|
2018-10-29 23:28:26 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "==Error=="
|
|
|
|
echo "Configuration file check failed."
|
|
|
|
# Use dovecot to print the config error.
|
|
|
|
${command} ${command_args} -a
|
|
|
|
exit $?
|
|
|
|
fi
|
2018-08-19 21:00:17 +00:00
|
|
|
base_dir=$(${command} ${command_args} -a 2>/dev/null | /usr/bin/awk -F '= ' '/^base_dir =/ { print $2 }')
|
2015-02-02 17:16:12 +00:00
|
|
|
pidfile="${base_dir}/master.pid"
|
2016-01-05 20:59:02 +00:00
|
|
|
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"
|
2018-04-01 17:10:31 +00:00
|
|
|
echo " # pkg info -D dovecot"
|
2015-02-02 17:16:12 +00:00
|
|
|
fi
|
2016-01-05 20:59:02 +00:00
|
|
|
run_rc_command "$1"
|
2014-10-27 15:45:19 +00:00
|
|
|
done
|