diff --git a/data/Dockerfiles/dovecot/Dockerfile b/data/Dockerfiles/dovecot/Dockerfile index f01e0572..d8a9d2e4 100644 --- a/data/Dockerfiles/dovecot/Dockerfile +++ b/data/Dockerfiles/dovecot/Dockerfile @@ -113,6 +113,7 @@ RUN apt-get update && apt-get -y --no-install-recommends install \ && rm -rf /tmp/* /var/tmp/* COPY trim_logs.sh /usr/local/bin/trim_logs.sh +COPY clean_q_aged.sh /usr/local/bin/clean_q_aged.sh COPY syslog-ng.conf /etc/syslog-ng/syslog-ng.conf COPY imapsync /usr/local/bin/imapsync COPY postlogin.sh /usr/local/bin/postlogin.sh diff --git a/data/Dockerfiles/dovecot/clean_q_aged.sh b/data/Dockerfiles/dovecot/clean_q_aged.sh new file mode 100755 index 00000000..0550dabb --- /dev/null +++ b/data/Dockerfiles/dovecot/clean_q_aged.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +MAX_AGE=$(redis-cli --raw -h redis-mailcow GET Q_MAX_AGE) + +if [[ -z ${MAX_AGE} ]]; then + echo "Max age for quarantine items not defined" + exit 1 +fi + +NUM_REGEXP='^[0-9]+$' +if ! [[ ${MAX_AGE} =~ ${NUM_REGEXP} ]] ; then + echo "Max age for quarantine items invalid" + exit 1 +fi + +TO_DELETE=$(mysql --socket=/var/run/mysqld/mysqld.sock -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT COUNT(id) FROM quarantine WHERE created < NOW() - INTERVAL ${MAX_AGE//[!0-9]/} DAY" -BN) +mysql --socket=/var/run/mysqld/mysqld.sock -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "DELETE FROM quarantine WHERE created < NOW() - INTERVAL ${MAX_AGE//[!0-9]/} DAY" +echo "Deleted ${TO_DELETE} items from quarantine table (max age is ${MAX_AGE//[!0-9]/} days)" diff --git a/data/Dockerfiles/dovecot/docker-entrypoint.sh b/data/Dockerfiles/dovecot/docker-entrypoint.sh index 5b91a665..c9f0ea30 100755 --- a/data/Dockerfiles/dovecot/docker-entrypoint.sh +++ b/data/Dockerfiles/dovecot/docker-entrypoint.sh @@ -16,6 +16,10 @@ sed -i "s/__DBUSER__/${DBUSER}/g" /usr/local/bin/quarantine_notify.py sed -i "s/__DBPASS__/${DBPASS}/g" /usr/local/bin/quarantine_notify.py sed -i "s/__DBNAME__/${DBNAME}/g" /usr/local/bin/quarantine_notify.py +sed -i "s/__DBUSER__/${DBUSER}/g" /usr/local/bin/clean_q_aged.sh +sed -i "s/__DBPASS__/${DBPASS}/g" /usr/local/bin/clean_q_aged.sh +sed -i "s/__DBNAME__/${DBNAME}/g" /usr/local/bin/clean_q_aged.sh + sed -i "s/__LOG_LINES__/${LOG_LINES}/g" /usr/local/bin/trim_logs.sh # Create missing directories @@ -205,6 +209,7 @@ chmod +x /usr/local/lib/dovecot/sieve/rspamd-pipe-ham \ /usr/local/bin/imapsync \ /usr/local/bin/trim_logs.sh \ /usr/local/bin/sa-rules.sh \ + /usr/local/bin/clean_q_aged.sh \ /usr/local/bin/maildir_gc.sh \ /usr/local/sbin/stop-supervisor.sh \ /usr/local/bin/quota_notify.py @@ -217,7 +222,7 @@ echo '25 * * * * vmail /usr/local/bin/maildir_gc.sh >> /dev/console 2>&1' > /e echo '30 1 * * * root /usr/local/bin/sa-rules.sh >> /dev/console 2>&1' > /etc/cron.d/sa-rules echo '0 2 * * * root /usr/bin/curl http://solr:8983/solr/dovecot-fts/update?optimize=true >> /dev/console 2>&1' > /etc/cron.d/solr-optimize echo '*/20 * * * * vmail /usr/local/bin/quarantine_notify.py >> /dev/console 2>&1' > /etc/cron.d/quarantine_notify - +echo '15 4 * * * vmail /usr/local/bin/clean_q_aged.sh >> /dev/console 2>&1' > /etc/cron.d/clean_q_aged # Fix more than 1 hardlink issue touch /etc/crontab /etc/cron.*/*