-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathboot
More file actions
executable file
·52 lines (41 loc) · 1.3 KB
/
boot
File metadata and controls
executable file
·52 lines (41 loc) · 1.3 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
#!/bin/bash
#
# This script is designed to be run inside the container
#
# set debug based on envvar
[[ $DEBUG ]] && set -x
# configure etcd
export ETCD=${ETCD:-172.17.42.1:4001}
export ETCD_PATH=${ETCD_PATH:-/deis/router}
export ETCD_TTL=${ETCD_TTL:-10}
# configure service discovery
export HOST=${HOST:-localhost}
export PORT=${PORT:-80}
export PROTO=${PROTO:-tcp}
# wait for etcd to be available
until etcdctl -C $ETCD ls >/dev/null; do
echo "waiting for etcd at $ETCD..."
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# wait until etcd has discarded potentially stale values
sleep $(($ETCD_TTL+1))
# seed initial service configuration if necessary
$(dirname ${BASH_SOURCE[0]})/seed >/dev/null 2>&1
# wait for confd to run once and install initial templates
until confd -onetime -node $ETCD -config-file /app/confd.toml; do
echo "waiting for confd to write initial templates..."
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# spawn the service in the background
/usr/sbin/nginx &
SERVICE_PID=$!
# smart shutdown on SIGINT and SIGTERM
function on_exit() {
kill -TERM $SERVICE_PID
wait $SERVICE_PID 2>/dev/null
}
trap on_exit INT TERM
# spawn confd in the background to update services based on etcd changes
confd -node $ETCD -config-file /app/confd.toml &
CONFD_PID=$!
wait