This repository was archived by the owner on Jun 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
77 lines (57 loc) · 1.86 KB
/
start.sh
File metadata and controls
77 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
if [ -z "$MAILNAME" ]; then
echo "MAILNAME environment variable is required"
exit 1
fi
echo $MAILNAME > /etc/mailname
postconf -e "myhostname=$MAILNAME"
if [ -n "$MILTER_PORT" ]; then
MILTER="$(echo ${MILTER_PORT} | sed 's/^tcp:\/\///i')"
postconf -e "smtpd_milters=inet:${MILTER}"
fi
# Utilize the init script to configure the chroot (if needed)
/etc/init.d/postfix start > /dev/null
/etc/init.d/postfix stop > /dev/null
# The init script doesn't always stop
# Ask postfix to stop itself as well, in case there's an issue
postfix stop > /dev/null 2>/dev/null
export ETCD_PORT=${ETCD_PORT:-4001}
export HOST_IP=${HOST_IP:-172.17.42.1}
export ETCD=$HOST_IP:$ETCD_PORT
echo "waiting for confd to create primary configuration files"
until /opt/confd -onetime -node $ETCD; do
sleep 1s
done
/opt/confd -watch -node $ETCD &
echo "confd is now monitoring for changes in primary configuration files..."
echo "waiting for confd to create initial SSL certificate"
until /opt/confd -onetime -node $ETCD -prefix "/services/ssl/$MAILNAME" -confdir /opt/confd-ssl; do
sleep 1s
done
/opt/confd -watch -node $ETCD -prefix "/services/ssl/$MAILNAME" -confdir /opt/confd-ssl &
echo "confd is now monitoring SSL certificate for changes..."
postmap /etc/postfix/virtual_aliases
postmap /etc/postfix/virtual_domains
trap_hup_signal() {
echo "Reloading (from SIGHUP)"
postfix reload
}
trap_term_signal() {
echo "Stopping (from SIGTERM)"
postfix stop
exit 0
}
# Postfix conveniently, doesn't handle TERM (sent by docker stop)
# Trap that signal and stop postfix if we recieve it
trap "trap_hup_signal" HUP
trap "trap_term_signal" TERM
/usr/lib/postfix/master -c /etc/postfix -d &
pid=$!
# Loop "wait" until the postfix master exits
while true; do
wait $pid
exitcode=$?
test $? -gt 128 || break;
kill -0 $pid 2> /dev/null || break;
done
exit $exitcode