-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
executable file
·65 lines (54 loc) · 1.88 KB
/
docker-entrypoint.sh
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
#!/bin/sh
set -e
echo "[$(date)] [INFO] Running entrypoint.sh"
echo "[$(date)] [INFO] Command line arguments: [$@]"
# Ignore environment variables if user is using custom parameters
if [[ ! -z "$@" ]]; then
echo "[$(date)] [INFO] Startup with command line arguments: /poolmon --foreground $@"
exec /poolmon --foreground --logfile=/dev/stdout $@
return $?
fi
options=""
if [[ -n "$DEBUG" ]]; then
echo "[$(date)] [INFO] Debug: YES"
options="$options --debug"
fi
if [[ -n "$INTERVAL" ]]; then
echo "[$(date)] [INFO] Interval: $INTERVAL"
options="$options --interval=$INTERVAL"
fi
if [[ -n "$TIMEOUT" ]]; then
echo "[$(date)] [INFO] Timeout: $TIMEOUT"
options="$options --timeout=$TIMEOUT"
fi
if [[ -n "$PORTS" ]]; then
echo "[$(date)] [INFO] Ports: $PORTS"
options="$options $PORTS"
fi
if [[ -n "$ADDITIONAL_OPTIONS" ]]; then
echo "[$(date)] [INFO] Additional options: $ADDITIONAL_OPTIONS"
options="$options $ADDITIONAL_OPTIONS"
fi
# Warn if director socket is emtpy
if [ -z "$DIRECTOR_SOCKET" ]; then
echo "[$(date)] [INFO] Using default director socket."
DIRECTOR_SOCKET=/var/run/dovecot/director-admin
fi
options="$options --socket=$DIRECTOR_SOCKET"
echo "[$(date)] [INFO] Director socket: $DIRECTOR_SOCKET"
# Wait for director socket to become available
retries=16 # retries=16 => 175 seconds
try=0
while [ ! -S "$DIRECTOR_SOCKET" ]; do
if [ $try == $retries ]; then
echo "[$(date)] [FATAL] Director socket is not available. Giving up."
exit 2
fi
# Timeout: sum 2*1.2^k, k=0 to $try.
sleeptime=`perl -e "printf '%.1f', 2*(1.2**$try)"`
try=$(($try + 1))
echo "[$(date)] [WARNING] Director socket is not available. Try $try of $retries. Sleeping ${sleeptime}s ..."
sleep $sleeptime
done
echo "[$(date)] [INFO] Startup. /poolmon --foreground $options"
exec /poolmon --foreground --logfile=/dev/stdout $options