-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·184 lines (171 loc) · 5.1 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
help () {
echo "Available daemons are: "
echo " accesshttp"
echo " accessws"
echo " alertcenter"
echo " marketprice"
echo " matchengine"
echo " readhistory"
}
echo "@=$@"
if [ $# -lt 1 ];then
help
exit 0
fi
SERVICE=$1
case $SERVICE in
alertcenter)
DAEMON=alertcenter
;;
matchengine)
DAEMON=matchengine
;;
marketprice)
DAEMON=marketprice
;;
readhistory)
DAEMON=readhistory
;;
accesshttp)
DAEMON=accesshttp
;;
accessws)
DAEMON=accessws
;;
--help)
help
;;
-h)
help
;;
*)
exec $@
;;
esac
if [ $DAEMON ]; then
cd /exchange_server
echo "=== $DAEMON is starting"
redis=`jq .redis.addr[0] < ${DAEMON}.json 2>/dev/null`
test -z $redis || test $redis = 'null' && redis=''
if [ -z $redis ];then
redis=`jq .redis.addr < ${DAEMON}.json 2>/dev/null`
fi
test -z $redis || test $redis = 'null' && redis=''
if [ $redis ];then
echo "=== $DAEMON contains redis config: $redis"
redis=`echo $redis|sed -e 's/"//g'`
echo "=== $DAEMON: sentinel addr found: $redis"
host=`echo $redis | cut -f1 -d':'`
port=`echo $redis | cut -f2 -d':'`
nc -z $host $port
result=$?
while [ $result -ne 0 ]; do
echo "=== $DAEMON: is waiting for sentinel on host=$host, port=$port ..."
sleep 10
nc -z $host $port
result=$?
done
echo "=== $DAEMON: sentinel is up"
fi
kafka=`jq .brokers[0] < ${DAEMON}.json 2>/dev/null`
test -z $kafka || test $kafka = 'null' && kafka=''
if [ -z $kafka ];then
kafka=`jq .brokers < ${DAEMON}.json 2>/dev/null`
fi
test -z $kafka || test $kafka = 'null' && kafka=''
if [ -z $kafka ];then
kafka=`jq .deals.brokers[0] < ${DAEMON}.json 2>/dev/null`
fi
test -z $kafka || test $kafka = 'null' && kafka=''
if [ -z $kafka ];then
kafka=`jq .deals.brokers < ${DAEMON}.json 2>/dev/null`
fi
test -z $kafka || test $kafka = 'null' && kafka=''
if [ $kafka ];then
echo "=== $DAEMON contains kafka config: $kafka"
kafka=`echo $kafka|sed -e 's/"//g'`
echo "=== $DAEMON: kafka addr found: $kafka"
host=`echo $kafka | cut -f1 -d':'`
port=`echo $kafka | cut -f2 -d':'`
nc -z $host $port
result=$?
while [ $result -ne 0 ]; do
echo "=== $DAEMON: is waiting for kafka on host=$host, port=$port ..."
sleep 10
nc -z $host $port
result=$?
done
echo "=== $DAEMON: kafka is up"
fi
host=`jq .db_history.host < ${DAEMON}.json 2>/dev/null`
test -z $host || test "$host" = 'null' && host=''
if [ "$host" ];then
port=`jq .db_history.port < ${DAEMON}.json 2>/dev/null`
test -z $port || test $port = 'null' && port=''
test $port || port=3306
echo "=== $DAEMON contains db_history mysql host: $host and port: $port"
host=`echo $host|sed -e 's/"//g'`
port=`echo $port|sed -e 's/"//g'`
nc -z $host $port
result=$?
while [ $result -ne 0 ]; do
echo "=== $DAEMON: is waiting for db_history on host=$host, port=$port ..."
sleep 10
nc -z $host $port
result=$?
done
echo "=== $DAEMON: db_history is up"
fi
host=`jq .db_log.host < ${DAEMON}.json 2>/dev/null`
test -z $host || test "$host" = 'null' && host=''
if [ "$host" ];then
port=`jq .db_log.port < ${DAEMON}.json 2>/dev/null`
test -z $port || test $port = 'null' && port=''
test $port || port=3306
echo "=== $DAEMON contains db_log mysql host: $host and port: $port"
host=`echo $host|sed -e 's/"//g'`
port=`echo $port|sed -e 's/"//g'`
nc -z $host $port
result=$?
while [ $result -ne 0 ]; do
echo "=== $DAEMON: is waiting for db_log on host=$host, port=$port ..."
sleep 10
nc -z $host $port
result=$?
done
echo "=== $DAEMON: db_log is up"
fi
echo "=== $DAEMON: ready to exec"
./$DAEMON.exe ${DAEMON}.json
NEW=1
while true; do
sleep 5
ps aux|grep ${DAEMON}.exe|grep -v grep > /dev/null
RESULT=$?
if [ $RESULT -ne 0 ];then
# some of services forks with _worker suffix
ps aux|grep ${DAEMON}_worker |grep -v grep > /dev/null
RESULT=$?
if [ $RESULT -ne 0 ];then
echo "=== $DAEMON has died, exitting docker...";
break;
else
if [ $NEW -eq 1 ]; then
echo "Microservice $DAEMON(worker) has started";
NEW=0
fi
fi
else
if [ $NEW -eq 1 ]; then
echo "=== $DAEMON(exe) has started";
NEW=0
fi
fi
done
exit 100
elif [ $BASH ]; then
while true;do sleep 3600;done
else
exit 101
fi