forked from nicholasjackson/docker-consul-envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·85 lines (72 loc) · 2.04 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# Wait until Consul can be contacted
until curl -s -k ${CONSUL_HTTP_ADDR}/v1/status/leader | grep 8300; do
echo "Waiting for Consul to start"
sleep 1
done
# If we do not need to register a service just run the command
if [ ! -z "$SERVICE_CONFIG" ]; then
# register the service with consul
echo "Registering service with consul $SERVICE_CONFIG"
consul services register ${SERVICE_CONFIG}
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "### Error writing service config: $file ###"
cat $file
echo ""
exit 1
fi
# make sure the service deregisters when exit
trap "consul services deregister ${SERVICE_CONFIG}" SIGINT SIGTERM EXIT
fi
# register any central config from individual files
if [ ! -z "$CENTRAL_CONFIG" ]; then
IFS=';' read -r -a configs <<< ${CENTRAL_CONFIG}
for file in "${configs[@]}"; do
echo "Writing central config $file"
consul config write $file
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "### Error writing central config: $file ###"
cat $file
echo ""
exit 1
fi
done
fi
# register any central config from a folder
if [ ! -z "$CENTRAL_CONFIG_DIR" ]; then
for file in `ls -v $CENTRAL_CONFIG_DIR/*`; do
echo "Writing central config $file"
consul config write $file
echo ""
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "### Error writing central config: $file ###"
cat $file
echo ""
exit 1
fi
done
fi
# haiut: begin
# dirty hack - for Docker-Compose & Consul demo
RINETD_BIN=/usr/sbin/rinetd
RINETD_CNF=/etc/rinetd.conf
if [ -f ${RINETD_BIN} -a -f ${RINETD_CNF} ]; then
CNF=`cat ${RINETD_CNF}`
echo "Running admin port forwarding as: ${CNF}"
${RINETD_BIN}
else
echo "Cannot find ${RINETD_BIN} or ${RINETD_CNF} - skipping admin port forwarding it"
fi
# haiut: end
# Run the command if specified
if [ "$#" -ne 0 ]; then
echo "Running command: $@"
exec "$@" &
# Block using tail so the trap will fire
tail -f /dev/null &
PID=$!
wait $PID
fi