diff --git a/Makefile b/Makefile index 0512f8d2..b5625348 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,13 @@ run: docker run -d --name mail \ -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test":/tmp/docker-mailserver-test \ + -v "`pwd`/test/onedir":/var/mail-state \ -e SA_TAG=1.0 \ -e SA_TAG2=2.0 \ -e SA_KILL=3.0 \ -e SASL_PASSWD=testing \ -e ENABLE_MANAGESIEVE=1 \ + -e ONE_DIR=1 \ -h mail.my-domain.com -t $(NAME) sleep 20 docker run -d --name mail_pop3 \ diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index ef045ca7..a7a85033 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -268,6 +268,29 @@ test -z "$ENABLE_FAIL2BAN" && rm -f /etc/logrotate.d/fail2ban # Fix cron.daily for spamassassin sed -i -e 's/invoke-rc.d spamassassin reload/\/etc\/init\.d\/spamassassin reload/g' /etc/cron.daily/spamassassin +# Consolidate all state that should be persisted across container restarts into one mounted +# directory +statedir=/var/mail-state +if [ "$ONE_DIR" = 1 -a -d $statedir ]; then + echo "Consolidating all state onto $statedir" + for d in /var/spool/postfix /var/lib/postfix /var/lib/amavis /var/lib/clamav /var/lib/spamassasin /var/lib/fail2ban; do + dest=$statedir/`echo $d | sed -e 's/.var.//; s/\//-/g'` + if [ -d $dest ]; then + echo " Destination $dest exists, linking $d to it" + rm -rf $d + ln -s $dest $d + elif [ -d $d ]; then + echo " Moving contents of $d to $dest:" `ls $d` + mv $d $dest + ln -s $dest $d + else + echo " Linking $d to $dest" + mkdir -p $dest + ln -s $dest $d + fi + done +fi + echo "Starting daemons" cron /etc/init.d/rsyslog start