#!/sbin/openrc-run
supervisor=supervise-daemon

name="maddy"
description="Composable all-in-one mail server"
description_log_reopen="Reopen log files"
description_reload="Reload some files from disk (but without main configuration)"

command=/usr/bin/maddy
command_args="run $maddy_opts"
command_user=maddy:maddy
capabilities="^cap_net_bind_service"

# make relative paths in config relative to the state directory
directory="/var/lib/$RC_SVCNAME"
extra_started_commands="log_reopen reload"

depend() {
	need net localmount
	after firewall
}

log_reopen() {
	ebegin "Reopening log files of $name"
	supervise-daemon $RC_SVCNAME --signal USR1
	eend $?
}

reload() {
	ebegin "Reloading $name"
	supervise-daemon $RC_SVCNAME --signal USR2
	eend $?
}

start_pre() {
	checkpath -d -o maddy:maddy /run/maddy
}
