Browse Source

Refactored alpine-postfix to include monit

master 3.1.3-r0
Fábio Kaiser Rauber 8 years ago
parent
commit
215ecc40bd
  1. 7
      Dockerfile
  2. 75
      conf/postfix-service.sh
  3. 4
      monit-service.conf
  4. 33
      start.sh

7
Dockerfile

@ -1,10 +1,9 @@
FROM alpine FROM rawmind/alpine-monit:0.5.20-2
MAINTAINER Fabio Rauber <fabiorauber@gmail.com>
RUN apk add --no-cache bash postfix postfix-pcre rsyslog RUN apk add --no-cache bash postfix postfix-pcre rsyslog
COPY conf /etc/postfix COPY conf /etc/postfix
COPY rsyslog.conf /etc/rsyslog.conf COPY rsyslog.conf /etc/rsyslog.conf
COPY start.sh /start.sh COPY monit-service.conf /opt/monit/etc/conf.d
CMD ["/start.sh"]

75
conf/postfix-service.sh

@ -0,0 +1,75 @@
#!/bin/bash
function log {
echo `date` $ME - $@
}
function serviceConf {
# Substitute configuration
for VARIABLE in `env | cut -f1 -d=`; do
sed -i "s={{ $VARIABLE }}=${!VARIABLE}=g" /etc/postfix/*.cf
done
# Override Postfix configuration
if [ -f /overrides/postfix.cf ]; then
while read line; do
postconf -e "$line"
done < /overrides/postfix.cf
echo "Loaded '/overrides/postfix.cf'"
else
echo "No extra postfix settings loaded because optional '/overrides/postfix.cf' not provided."
fi
# Include table-map files
if ls -A /overrides/*.map 1> /dev/null 2>&1; then
cp /overrides/*.map /etc/postfix/
postmap /etc/postfix/*.map
rm /etc/postfix/*.map
chown root:root /etc/postfix/*.db
chmod 0600 /etc/postfix/*.db
echo "Loaded 'map files'"
else
echo "No extra map files loaded because optional '/overrides/*.map' not provided."
fi
}
function serviceStart {
serviceConf
# Actually run Postfix
log "[ Starting Postfix... ]"
rm -f /var/run/rsyslogd.pid
nohup /usr/lib/postfix/master &
echo $! > /var/run/postfix.pid
nohup rsyslogd -n &
}
function serviceStop {
log "[ Stopping Postfix... ]"
kill `cat /var/run/postfix.pid`
}
function serviceRestart {
log "[ Restarting Postfix... ]"
serviceStop
serviceStart
/opt/monit/bin/monit reload
}
export DOMAIN=${DOMAIN:-"localhost"}
export MESSAGE_SIZE_LIMIT=${MESSAGE_SIZE_LIMIT:-"50000000"}
export RELAYNETS=${RELAYNETS:-""}
export RELAYHOST=${RELAYHOST:-""}
case "$1" in
"start")
serviceStart &>> /proc/1/fd/1
;;
"stop")
serviceStop &>> /proc/1/fd/1
;;
"restart")
serviceRestart &>> /proc/1/fd/1
;;
*) echo "Usage: $0 restart|start|stop"
;;
esac

4
monit-service.conf

@ -0,0 +1,4 @@
check process master with pidfile /var/run/postfix.pid
start program = "/etc/postfix/postfix-service.sh start"
stop program = "/etc/postfix/postfix-service.sh stop"
if failed port 25 type tcp for 5 cycles then exec "/opt/monit/bin/monit quit"

33
start.sh

@ -1,33 +0,0 @@
#!/bin/bash
# Substitute configuration
for VARIABLE in `env | cut -f1 -d=`; do
sed -i "s={{ $VARIABLE }}=${!VARIABLE}=g" /etc/postfix/*.cf
done
# Override Postfix configuration
if [ -f /overrides/postfix.cf ]; then
while read line; do
postconf -e "$line"
done < /overrides/postfix.cf
echo "Loaded '/overrides/postfix.cf'"
else
echo "No extra postfix settings loaded because optional '/overrides/postfix.cf' not provided."
fi
# Include table-map files
if ls -A /overrides/*.map 1> /dev/null 2>&1; then
cp /overrides/*.map /etc/postfix/
postmap /etc/postfix/*.map
rm /etc/postfix/*.map
chown root:root /etc/postfix/*.db
chmod 0600 /etc/postfix/*.db
echo "Loaded 'map files'"
else
echo "No extra map files loaded because optional '/overrides/*.map' not provided."
fi
# Actually run Postfix
rm -f /var/run/rsyslogd.pid
/usr/lib/postfix/master &
rsyslogd -n
Loading…
Cancel
Save