-
Notifications
You must be signed in to change notification settings - Fork 337
/
startup.sh
executable file
·89 lines (79 loc) · 1.93 KB
/
startup.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
86
87
88
89
#!/bin/bash
set -x
IP=$(ip route show |grep -o src.* |cut -f2 -d" ")
# kubernetes sets routes differently -- so we will discover our IP differently
if [[ ${IP} == "" ]]; then
IP=$(hostname -i)
fi
SUBNET=$(echo ${IP} | cut -f1 -d.)
NETWORK=$(echo ${IP} | cut -f3 -d.)
case "${SUBNET}" in
10)
orchestrator=ecs
;;
192)
orchestrator=kubernetes
;;
*)
orchestrator=unknown
;;
esac
if [[ "${orchestrator}" == 'ecs' ]]; then
case "${NETWORK}" in
100)
zone=a
color=Crimson
;;
101)
zone=b
color=CornflowerBlue
;;
102)
zone=c
color=LightGreen
;;
*)
zone=unknown
color=Yellow
;;
esac
fi
if [[ "${orchestrator}" == 'kubernetes' ]]; then
if ((0<=${NETWORK} && ${NETWORK}<32))
then
zone=a
elif ((32<=${NETWORK} && ${NETWORK}<64))
then
zone=b
elif ((64<=${NETWORK} && ${NETWORK}<96))
then
zone=c
elif ((96<=${NETWORK} && ${NETWORK}<128))
then
zone=a
elif ((128<=${NETWORK} && ${NETWORK}<160))
then
zone=b
elif ((160<=${NETWORK}))
then
zone=c
else
zone=unknown
fi
fi
if [[ ${orchestrator} == 'unknown' ]]; then
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
fi
# Am I on ec2 instances?
if [[ ${zone} == "unknown" ]]; then
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
fi
# Still no luck? Perhaps we're running fargate!
if [[ -z ${zone} ]]; then
zone=$(curl -s ${ECS_CONTAINER_METADATA_URI_V4}/task | jq -r '.AvailabilityZone' | grep -o .$)
fi
export CODE_HASH="$(cat code_hash.txt)"
export IP
export AZ="${IP} in AZ-${zone}"
# exec container command
exec node server.js