forked from mesosphere/marathon-lb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·100 lines (87 loc) · 2.43 KB
/
run
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -euo pipefail
SYSLOG_SOCKET=${SYSLOG_SOCKET:-/dev/null}
HAPROXY_SERVICE="/marathon-lb/service/haproxy"
mkdir -p $HAPROXY_SERVICE/env
if [ -n "${PORTS-}" ]; then
echo $PORTS > $HAPROXY_SERVICE/env/PORTS
else
echo "Define $PORTS with a comma-separated list of ports to which HAProxy binds" >&2
exit 1
fi
# Iterate through the arguments to see if any SSL certificate is provided.
for key in "$@"
do
case $key in
--ssl-certs)
SSL_CERTS="yes"
;;
*)
# unknown option
;;
esac
done
if [ -n "${HAPROXY_SSL_CERT-}" ]; then
# if provided via environment variable, use it.
echo -e "$HAPROXY_SSL_CERT" > /etc/ssl/mesosphere.com.pem
elif ! [ -n "${SSL_CERTS-}" ]; then
# if no environment variable or command line argument is provided,
# create self-signed ssl certificate
openssl genrsa -out /tmp/server-key.pem 2048
openssl req -new -key /tmp/server-key.pem -out /tmp/server-csr.pem -subj /CN=*/
openssl x509 -req -in /tmp/server-csr.pem -out /tmp/server-cert.pem -signkey /tmp/server-key.pem -days 3650
cat /tmp/server-cert.pem /tmp/server-key.pem > /etc/ssl/mesosphere.com.pem
rm /tmp/server-*.pem
fi
if [ -n "${MESOS_SANDBOX-}" ] && [ -d "$MESOS_SANDBOX/templates" ]; then
mkdir -p templates
cp -v "$MESOS_SANDBOX/templates/"* templates/
fi
if [ -n "${HAPROXY_SYSCTL_PARAMS-}" ]; then
echo "setting sysctl params to: ${HAPROXY_SYSCTL_PARAMS}"
if [ -n "${HAPROXY_SYSCTL_NONSTRICT-}" ]; then
# ignore errors
sysctl -w $HAPROXY_SYSCTL_PARAMS || true
else
sysctl -w $HAPROXY_SYSCTL_PARAMS
fi
fi
/usr/bin/runsv "$HAPROXY_SERVICE" &
RUNSV=$!
ARGS=""
trap "kill $RUNSV; wait $RUNSV; exit 0" TERM INT
MODE=$1; shift
case "$MODE" in
poll)
POLL_INTERVAL="${POLL_INTERVAL:-60}"
;;
sse)
ARGS="--sse"
;;
event)
URL=$1; shift
if [ -z "$URL" ] || echo "$URL" | grep -q '^-'; then
echo "$0 event callback-url [marathon_lb.py args]" >&2
exit 1
fi
echo "Using $URL as event callback-url"
ARGS="-u $URL"
;;
*)
echo "Unknown mode $MODE. Synopsis: $0 poll|sse|event [marathon_lb.py args]" >&2
exit 1
;;
esac
while true; do
/marathon-lb/marathon_lb.py \
--syslog-socket $SYSLOG_SOCKET \
--haproxy-config /marathon-lb/haproxy.cfg \
-c "sv reload $HAPROXY_SERVICE" \
$ARGS "$@" &
wait $! || exit $? # Needed for the traps to work
if [ "$MODE" != "poll" ]; then
exit 0
fi
sleep "$POLL_INTERVAL" &
wait $!
done