DOMAINNAME can fail to be set in postsrsd-wrapper.sh (#989)

* DOMAINNAME can fail to be set in postsrsd-wrapper.sh

if the container doesn’t have a proper hostname, postsrsd will fail to start
because SRS_DOMAIN is empty. Make a best effort to figure out the domain name
and provide a way to set one if needed.
This commit is contained in:
James 2018-06-19 01:17:32 -05:00 committed by Johan Smits
parent 261a78c036
commit d518a9fc1d
4 changed files with 60 additions and 3 deletions

View file

@ -96,10 +96,32 @@ run:
-v "`pwd`/test":/tmp/docker-mailserver-test \
-e PERMIT_DOCKER=network \
-e DMS_DEBUG=0 \
-e ENABLE_SRS=1 \
-e OVERRIDE_HOSTNAME=mail.my-domain.com \
-h unknown.domain.tld \
-t $(NAME)
sleep 15
docker run -d --name mail_domainname \
-v "`pwd`/test/config":/tmp/docker-mailserver \
-v "`pwd`/test":/tmp/docker-mailserver-test \
-e PERMIT_DOCKER=network \
-e DMS_DEBUG=0 \
-e ENABLE_SRS=1 \
-e DOMAINNAME=my-domain.com \
-h unknown.domain.tld \
-t $(NAME)
sleep 15
docker run -d --name mail_srs_domainname \
-v "`pwd`/test/config":/tmp/docker-mailserver \
-v "`pwd`/test":/tmp/docker-mailserver-test \
-e PERMIT_DOCKER=network \
-e DMS_DEBUG=0 \
-e ENABLE_SRS=1 \
-e SRS_DOMAINNAME=srs.my-domain.com \
-e DOMAINNAME=my-domain.com \
-h unknown.domain.tld \
-t $(NAME)
sleep 15
docker run -d --name mail_fail2ban \
-v "`pwd`/test/config":/tmp/docker-mailserver \
-v "`pwd`/test":/tmp/docker-mailserver-test \
@ -284,6 +306,8 @@ clean:
mail_undef_spam_subject \
mail_postscreen \
mail_override_hostname \
mail_domainname \
mail_srs_domainname \
mail_with_relays
@if [ -d config.bak ]; then\

View file

@ -548,6 +548,11 @@ Note: This postgrey setting needs `ENABLE_POSTGREY=1`
- if you have a cluster/swarm make sure the same keys are on all nodes
- example command to generate a key: `dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64`
##### SRS_DOMAINNAME
- **empty** => Derived from OVERRIDE_HOSTNAME, DOMAINNAME, or the container's hostname
- Set this if auto-detection fails, isn't what you want, or you wish to have a separate container handle DSNs
## Multi-domain Relay Hosts
#### RELAY_HOST

View file

@ -1,8 +1,17 @@
#!/usr/bin/env bash
# postsrsd-wrapper.sh, version 0.2.1
# postsrsd-wrapper.sh, version 0.2.2
DOMAINNAME="$(hostname -d)"
sed -i -e "s/localdomain/$DOMAINNAME/g" /etc/default/postsrsd
if [ -n "$SRS_DOMAINNAME" ]; then
domain_name="$SRS_DOMAINNAME"
elif [ -n "$OVERRIDE_HOSTNAME" ]; then
domain_name="${OVERRIDE_HOSTNAME#*.}"
elif [ -n "$DOMAINNAME" ]; then
domain_name="$DOMAINNAME"
else
domain_name=$(hostname -d)
fi
sed -i -e "s/localdomain/${domain_name}/g" /etc/default/postsrsd
postsrsd_secret_file='/etc/postsrsd.secret'
postsrsd_state_dir='/var/mail-state/etc-postsrsd'

View file

@ -810,6 +810,25 @@ load 'test_helper/bats-assert/load'
assert_success
}
@test "checking SRS: SRS_DOMAINNAME is used correctly" {
run docker exec mail_srs_domainname grep "SRS_DOMAIN=srs.my-domain.com" /etc/default/postsrsd
assert_success
}
@test "checking SRS: OVERRIDE_HOSTNAME is handled correctly" {
run docker exec mail_override_hostname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd
assert_success
}
@test "checking SRS: DOMAINNAME is handled correctly" {
run docker exec mail_domainname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd
assert_success
}
@test "checking SRS: fallback to hostname is handled correctly" {
run docker exec mail grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd
assert_success
}
#
# fail2ban
#