#!/bin/bash
set -e

NAME="RSPAMD"

function stop {
	echo "Stopping ${NAME}"
	kill $(cat /var/run/rspamd.pid)
	kill $(cat /var/run/rmilter.pid)
}

trap 'stop' SIGTERM

if [ "$1" == "start" ]; then
	[ -x /usr/bin/rspamd ] && /usr/bin/rspamd -u _rspamd -g _rspamd -c /etc/rspamd/rspamd.conf -f -p /var/run/rspamd.pid &
	[ -x /usr/sbin/rmilter ] && /usr/sbin/rmilter -n -c /etc/rmilter/rmilter.conf &

	wait
else
	exec $@
fi