Skip to content

Commit

Permalink
Merge pull request #4 from Dalee/replace-nullmailer
Browse files Browse the repository at this point in the history
replace nullmailer with msmtp
  • Loading branch information
arkady-emelyanov authored Aug 21, 2017
2 parents 213a0f6 + 4d90c1d commit 6d99f07
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.baseimage
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ RUN apt-get -qq install -y \
psmisc \
nginx \
bcron \
nullmailer \
gettext-base \
msmtp \
ansible \
net-tools \
curl \
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ It uses same directory layout for defining services, patched versions of `my_ini
* [my_wait](sbin/my_wait) - dependency manager, a-la [wait-for-it](https://github.com/vishnubob/wait-for-it)
* [runit](http://smarden.org/runit/) - process supervisor
* [nginx](https://nginx.org/) - reverse proxy service, disabled by default
* [nullmailer](https://github.com/bruceg/nullmailer) - smtp relay/sendmail service, disabled by default
* [msmtp](http://msmtp.sourceforge.net/doc/msmtp.html) - smtp relay/sendmail service, disabled by default
* [bcron](https://github.com/bruceg/bcron) - cron service, disabled by default

### Container control
Expand Down Expand Up @@ -137,19 +137,18 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * root /app/system_cleanup.sh
```

#### Sendmail / Nullmailer
#### Sendmail / msmtp

* Repository: [official](https://packages.ubuntu.com/xenial/nullmailer)
* Repository: [official](https://packages.ubuntu.com/xenial/msmtp)
* Dockerfile: `RUN /sbin/enable_service sendmail`
* Configure: provide environment variables on container start:
* `NULLMAILER_REMOTES` - see section `remotes` from [man page](http://manpages.ubuntu.com/manpages/xenial/man8/nullmailer-send.8.html)
* `NULLMAILER_HOSTNAME` - hostname (default is "docker")
* `SENDMAIL_HOST` - ip address or domain name of SMTP server
* `SENDMAIL_PORT` - override smtp port, default is `25`

Sample `docker run` command:
```
docker run --rm \
-e NULLMAILER_HOSTNAME="example.com" \
-e NULLMAILER_REMOTES="smtp.example.com smtp --port=25" \
-e SENDMAIL_HOST="mail.example.com" \
...
```

Expand Down
2 changes: 1 addition & 1 deletion build_scripts/test.image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Building ${IMAGE_VERSION}"
IMAGE_ID=$(docker build --quiet -t "${IMAGE_VERSION}" . -f "./Dockerfile.${IMAGE}_test")

echo "==> Starting container: ${IMAGE_VERSION}..."
CONTAINER_ID=$(docker run -d -v ${PWD}/build_scripts:/build_scripts ${IMAGE_ID})
CONTAINER_ID=$(docker run -d -e SENDMAIL_HOST="mail.example.com" -v ${PWD}/build_scripts:/build_scripts ${IMAGE_ID})
sleep 5

echo "==> Starting testcase: ${TESTCASE}..."
Expand Down
16 changes: 10 additions & 6 deletions build_scripts/testcase.baseimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ if [ "$?" != 0 ]; then
echo "==> FAIL: cron-start failed"
exit 1
fi

service=$(/usr/bin/sv -w 0 check /etc/service/cron-update | grep -q '^ok:')
if [ "$?" != 0 ]; then
echo "==> FAIL: cron-update failed"
exit 1
fi

# sendmail
echo "==> Checking sendmail..."
service=$(/usr/bin/sv -w 0 check /etc/service/nullmailer-send | grep -q '^ok:')
if [ "$?" != 0 ]; then
echo "==> FAIL: nullmailer-send failed"
# smtp
echo "==> Checking presence of msmtp configuration file..."
if [ ! -f "/etc/msmtprc" ]; then
echo "==> FAIL: no msmtp configuration installed"
exit 1
fi
echo "==> Checking presence of sendmail wrapper..."
if [ ! -f "/usr/sbin/sendmail" ]; then
echo "==> FAIL: no sendmail wrapper installed"
exit 1
fi


# nginx
echo "==> Checking nginx..."
Expand Down
9 changes: 3 additions & 6 deletions system/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ set -eo pipefail
cp /build/sbin/* /sbin/ && chmod +x /sbin/*
cp -r /build/system/service.available /etc/service.available

# .bashrc
cp -f /build/system/bash.rc /root/.bashrc

#
# my_init environment
# @see https://github.com/phusion/baseimage-docker/tree/master/image
Expand All @@ -26,11 +29,5 @@ ln -s /usr/bin/pstree /usr/bin/ps
ln -s /usr/bin/htop /usr/bin/top
ln -s /usr/bin/vim.tiny /usr/bin/vim

# .bashrc
cp -f /build/system/bash.rc /root/.bashrc


# some mandatory fixes for services
mkdir -p /etc/nginx/virtuals
chown mail:root /usr/sbin/nullmailer-queue
chmod u+s /usr/sbin/nullmailer-queue
38 changes: 25 additions & 13 deletions system/service.available/sendmail/init
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
set -eo pipefail

#
# fetching current options
# if SENDMAIL_HOST is set, forward mail to that host.
# if SENDMAIL_PORT is set, use port from environment.
#
RELAY=""
HOST="docker"
if [ ! -z "${NULLMAILER_REMOTES}" ]; then RELAY="${NULLMAILER_REMOTES}"; fi
if [ ! -z "${NULLMAILER_HOSTNAME}" ]; then HOST="${NULLMAILER_HOSTNAME}"; fi
if [ -z "${SENDMAIL_HOST}" ]; then
echo "==> Environment variable SENDMAIL_HOST is not set, skipping configuration..."
exit 0
fi
if [ -z "${SENDMAIL_PORT}" ]; then
SENDMAIL_PORT="25"
fi

mkdir -p /etc/nullmailer
echo "${RELAY}" > "/etc/nullmailer/remotes"
echo "${HOST}" > "/etc/nullmailer/me"
chmod 0600 /etc/nullmailer/remotes /etc/nullmailer/me
chown mail:root /etc/nullmailer/remotes /etc/nullmailer/me
#
# create system-wide configuration file.
#
SENDMAIL_HOST=${SENDMAIL_HOST} \
SENDMAIL_PORT=${SENDMAIL_PORT} \
envsubst <<"EOF" > /etc/msmtprc
defaults
account default
auto_from on
host $SENDMAIL_HOST
port $SENDMAIL_PORT
EOF

mkdir -p /var/spool/nullmailer/queue /var/spool/nullmailer/tmp
mkfifo /var/spool/nullmailer/trigger
chown mail:root -R /var/spool/nullmailer
#
# symlink /usr/sbin/sendmail => /usr/bin/msmtp
#
ln -s /usr/bin/msmtp /usr/sbin/sendmail
7 changes: 0 additions & 7 deletions system/service.available/sendmail/nullmailer-send/run

This file was deleted.

0 comments on commit 6d99f07

Please sign in to comment.