build: Initial mail server docker image #6

Merged
jon_nfc merged 19 commits from 1-initial-container into development 2022-02-14 06:10:14 +00:00
44 changed files with 1925 additions and 0 deletions
Showing only changes of commit a7c1ae052c - Show all commits

View File

@ -55,8 +55,14 @@ RUN chmod +x /docker-entrypoint.sh \
# Create vmail user for system
&& groupadd -g 5000 vmail \
&& useradd -g vmail -u 5000 vmail -d /var/vmail \
# Ensure Backup directory is created
&& mkdir /backup \
&& chown root:root /backup \
&& chmod 700 /backup \
# create SSL directory for ssl certificates
&& mkdir -p /ssl \
# Ensure scripts are executable
&& chmod +x /bin/backup.sh \
# Dovecot related commands
&& mkdir -p /srv/mail \
&& chown vmail:vmail /srv/mail \
@ -83,8 +89,9 @@ RUN chmod +x /docker-entrypoint.sh \
&& mkdir -p /var/spool/spamassassin \
&& chmod 777 /var/spool/spamassassin \
# Setup data volumes
VOLUME /srv/mail /ssl /var/spool/spamassassin /var/log
VOLUME /srv/mail /ssl /var/spool/spamassassin /backup /var/log
# Configure postfix
RUN postconf -e "maillog_file=/var/log/postfix.log" \

53
include/bin/backup.sh Normal file
View File

@ -0,0 +1,53 @@
#!/bin/bash
set -e
backup_version=1.0
back_file_name="mail_server-$backup_version-$(date +%Y-%m-%d-%H%M-%Z).tar.gz"
start=$(date '+%s')
includes=(/srv/mail)
includes+=(/ssl)
includes+=(/var/spool/spamassassin)
includes+=(/var/log)
includes+=(/var/lib/amavis)
backup_command="tar -czpvf $back_file_name ${includes[@]}"
cd /tmp
echo "$backup_command"
if ! $backup_command; then
status="tar failed"
elif ! mv "/tmp/$back_file_name" /backup/ ; then
status="mv failed"
else
status="success: version=$backup_version size=$(stat -c%s /backup/$back_file_name) duration=$((`date '+%s'` - $start)) command='$backup_command'"
fi
logger -t backup "$status"
if [ "0$POST_MASTER_EMAIL" != "0" ]; then
cat << EOF | /usr/lib/dovecot/dovecot-lda -d "${POST_MASTER_EMAIL}" -o "plugin/quota=maildir:User quota:noenforcing"
Auto-Submitted: auto-generated
Date: $(date +'%a, %-d %b %Y %H:%M:%S %z')
To: ${POST_MASTER_EMAIL}
From: Mail Server <NO-REPLY@$(hostname -f)>
Subject: Backup $(date +%Y-%m-%d-%H:%M-%Z)
Server backups have occured on $(hostname -f)
Summary:
$status
EOF
fi

View File

@ -0,0 +1,6 @@
#
# Backup the docker container
#
# m h dom mon dow user command
01 0,3,6,9,12,15,18,21 * * * root /bin/backup.sh 2>&1