From b8feb77ef4d504f9cefb04bb5c57b821012b8194 Mon Sep 17 00:00:00 2001 From: jvolkenant Date: Sat, 24 Sep 2022 10:17:55 -0700 Subject: [PATCH] Move postgrey database under $STORAGE_ROOT (#2077) --- CHANGELOG.md | 1 + management/backup.py | 2 ++ setup/mail-postfix.sh | 25 +++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72a2608a..cad3dd21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ No features of Mail-in-a-Box have changed in this release, but with the newer ve Also: * Roundcube's login session cookie was tightened. Existing sessions may require a manual logout. +* Move Postgrey's database under $STORAGE_ROOT Version 57a (June 19, 2022) --------------------------- diff --git a/management/backup.py b/management/backup.py index 012ccccb..8a82c4ad 100755 --- a/management/backup.py +++ b/management/backup.py @@ -281,6 +281,7 @@ def perform_backup(full_backup): service_command("php8.0-fpm", "stop", quit=True) service_command("postfix", "stop", quit=True) service_command("dovecot", "stop", quit=True) + service_command("postgrey", "stop", quit=True) # Execute a pre-backup script that copies files outside the homedir. # Run as the STORAGE_USER user, not as root. Pass our settings in @@ -310,6 +311,7 @@ def perform_backup(full_backup): get_duplicity_env_vars(env)) finally: # Start services again. + service_command("postgrey", "start", quit=False) service_command("dovecot", "start", quit=False) service_command("postfix", "start", quit=False) service_command("php8.0-fpm", "start", quit=False) diff --git a/setup/mail-postfix.sh b/setup/mail-postfix.sh index 196d371d..5787e8c9 100755 --- a/setup/mail-postfix.sh +++ b/setup/mail-postfix.sh @@ -233,11 +233,32 @@ tools/editconf.py /etc/postfix/main.cf \ # As a matter of fact RFC is not strict about retry timer so postfix and # other MTA have their own intervals. To fix the problem of receiving # e-mails really latter, delay of greylisting has been set to -# 180 seconds (default is 300 seconds). +# 180 seconds (default is 300 seconds). We will move the postgrey database +# under $STORAGE_ROOT. This prevents a "warming up" that would have occured +# previously with a migrated or reinstalled OS. We will specify this new path +# with the --dbdir=... option. Arguments within POSTGREY_OPTS can not have spaces, +# including dbdir. This is due to the way the init script sources the +# /etc/default/postgrey file. --dbdir=... either needs to be a path without spaces +# (luckily $STORAGE_ROOT does not currently work with spaces), or it needs to be a +# symlink without spaces that can point to a folder with spaces). We'll just assume +# $STORAGE_ROOT won't have spaces to simplify things. tools/editconf.py /etc/default/postgrey \ - POSTGREY_OPTS=\"'--inet=127.0.0.1:10023 --delay=180'\" + POSTGREY_OPTS=\""--inet=127.0.0.1:10023 --delay=180 --dbdir=$STORAGE_ROOT/mail/postgrey/db"\" +# If the $STORAGE_ROOT/mail/postgrey is empty, copy the postgrey database over from the old location +if [ ! -d $STORAGE_ROOT/mail/postgrey/db ]; then + # Stop the service + service postgrey stop + # Ensure the new paths for postgrey db exists + mkdir -p $STORAGE_ROOT/mail/postgrey/db + # Move over database files + mv /var/lib/postgrey/* $STORAGE_ROOT/mail/postgrey/db/ || true +fi +# Ensure permissions are set +chown -R postgrey:postgrey $STORAGE_ROOT/mail/postgrey/ +chmod 700 $STORAGE_ROOT/mail/postgrey/{,db} + # We are going to setup a newer whitelist for postgrey, the version included in the distribution is old cat > /etc/cron.daily/mailinabox-postgrey-whitelist << EOF; #!/bin/bash