2021-02-23 19:03:01 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
function start_daemons
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'info' 'Starting daemons & mail server'
|
2021-02-23 19:03:01 +00:00
|
|
|
for FUNC in "${DAEMONS_START[@]}"
|
|
|
|
do
|
2021-09-23 17:49:07 +00:00
|
|
|
${FUNC}
|
2021-02-23 19:03:01 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_cron
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting cron'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start cron || dms_panic__fail_init 'cron'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_rsyslog
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting rsyslog'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start rsyslog || dms_panic__fail_init 'rsyslog'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_saslauthd
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting saslauthd'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start "saslauthd_${SASLAUTHD_MECHANISMS}" || dms_panic__fail_init 'saslauthd'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_fail2ban
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting Fail2ban'
|
2021-02-23 19:03:01 +00:00
|
|
|
touch /var/log/auth.log
|
|
|
|
|
|
|
|
# delete fail2ban.sock that probably was left here after container restart
|
|
|
|
if [[ -e /var/run/fail2ban/fail2ban.sock ]]
|
|
|
|
then
|
|
|
|
rm /var/run/fail2ban/fail2ban.sock
|
|
|
|
fi
|
|
|
|
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start fail2ban || dms_panic__fail_init 'Fail2ban'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_opendkim
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting opendkim'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start opendkim || dms_panic__fail_init 'opendkim'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_opendmarc
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting opendmarc'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start opendmarc || dms_panic__fail_init 'opendmarc'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_postsrsd
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting postsrsd'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start postsrsd || dms_panic__fail_init 'postsrsd'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_postfix
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting postfix'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start postfix || dms_panic__fail_init 'postfix'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_dovecot
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting dovecot services'
|
2021-02-23 19:03:01 +00:00
|
|
|
|
|
|
|
if [[ ${ENABLE_POP3} -eq 1 ]]
|
|
|
|
then
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting pop3 services'
|
2021-02-23 19:03:01 +00:00
|
|
|
mv /etc/dovecot/protocols.d/pop3d.protocol.disab \
|
|
|
|
/etc/dovecot/protocols.d/pop3d.protocol
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f /tmp/docker-mailserver/dovecot.cf ]]
|
|
|
|
then
|
|
|
|
cp /tmp/docker-mailserver/dovecot.cf /etc/dovecot/local.conf
|
|
|
|
fi
|
|
|
|
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start dovecot || dms_panic__fail_init 'dovecot'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_fetchmail
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Preparing fetchmail config'
|
2021-02-23 19:03:01 +00:00
|
|
|
/usr/local/bin/setup-fetchmail
|
|
|
|
|
|
|
|
if [[ ${FETCHMAIL_PARALLEL} -eq 1 ]]
|
|
|
|
then
|
|
|
|
mkdir /etc/fetchmailrc.d/
|
|
|
|
/usr/local/bin/fetchmailrc_split
|
|
|
|
|
|
|
|
local COUNTER=0
|
|
|
|
for RC in /etc/fetchmailrc.d/fetchmail-*.rc
|
|
|
|
do
|
|
|
|
COUNTER=$(( COUNTER + 1 ))
|
|
|
|
cat >"/etc/supervisor/conf.d/fetchmail-${COUNTER}.conf" << EOF
|
|
|
|
[program:fetchmail-${COUNTER}]
|
|
|
|
startsecs=0
|
|
|
|
autostart=false
|
|
|
|
autorestart=true
|
|
|
|
stdout_logfile=/var/log/supervisor/%(program_name)s.log
|
|
|
|
stderr_logfile=/var/log/supervisor/%(program_name)s.log
|
|
|
|
user=fetchmail
|
|
|
|
command=/usr/bin/fetchmail -f ${RC} -v --nodetach --daemon %(ENV_FETCHMAIL_POLL)s -i /var/lib/fetchmail/.fetchmail-UIDL-cache --pidfile /var/run/fetchmail/%(program_name)s.pid
|
|
|
|
EOF
|
|
|
|
chmod 700 "${RC}"
|
|
|
|
chown fetchmail:root "${RC}"
|
|
|
|
done
|
|
|
|
|
|
|
|
supervisorctl reread
|
|
|
|
supervisorctl update
|
|
|
|
|
|
|
|
COUNTER=0
|
|
|
|
for _ in /etc/fetchmailrc.d/fetchmail-*.rc
|
|
|
|
do
|
|
|
|
COUNTER=$(( COUNTER + 1 ))
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' "Starting fetchmail instance ${COUNTER}"
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start "fetchmail-${COUNTER}" || _panic__fail_init "fetchmail-${COUNTER}"
|
2021-02-23 19:03:01 +00:00
|
|
|
done
|
|
|
|
else
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting fetchmail'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start fetchmail || dms_panic__fail_init 'fetchmail'
|
2021-02-23 19:03:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_clamav
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting ClamAV'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start clamav || dms_panic__fail_init 'ClamAV'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_postgrey
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting postgrey'
|
2021-02-23 19:03:01 +00:00
|
|
|
rm -f /var/run/postgrey/postgrey.pid
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start postgrey || dms_panic__fail_init 'postgrey'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_daemons_amavis
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting amavis'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start amavis || dms_panic__fail_init 'amavis'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _start_changedetector
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting changedetector'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start changedetector || dms_panic__fail_init 'changedetector'
|
2021-02-23 19:03:01 +00:00
|
|
|
}
|
2021-05-19 19:18:06 +00:00
|
|
|
|
|
|
|
function _start_daemons_update_check
|
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' 'Starting update-check'
|
2021-09-23 17:49:07 +00:00
|
|
|
supervisorctl start update-check || dms_panic__fail_init 'update-check'
|
2021-05-19 19:18:06 +00:00
|
|
|
}
|