-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·128 lines (116 loc) · 3.97 KB
/
start.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
#!/bin/bash
source ./init.sh
if [[ -z "${DOCKER_IMAGE_NAME}" ]]; then
echo "DOCKER_IMAGE_NAME must be provided in .env file."
exit 1
fi;
function usageAndExit() {
printf 'Usage:\n'
printf ' <service>\n Start an application.\n'
printf ' <service> <service>\n Start many applications\n'
exit 0
}
UI="${ENABLED_UI}"
REALTIME="${ENABLED_REALTIME}"
API="${ENABLED_API}"
TRAIN_MANAGER="${ENABLED_TRAIN_MANAGER}"
if [[ -n "$1" ]]; then
UI=false
REALTIME=false
API=false
TRAIN_MANAGER=false
while [ "$1" != '' ]; do
case "${1}" in
ui) UI=true && shift;;
realtime) REALTIME=true && shift;;
api) API=true && shift;;
train-manager) TRAIN_MANAGER=true && shift;;
*) echo "Unknown app: ${1}" && shift;;
esac
done
if [[ -z "${UI}" && -z "${API}" && -z "${REALTIME}" && -z "${TRAIN_MANAGER}" ]]; then
usageAndExit
fi
fi
if [[ "${UI}" == true ]]; then
DOCKER_ID_UI=$(docker ps -qf name=^"${DOCKER_NAME_UI}"$)
if [ -z "${DOCKER_ID_UI}" ]; then
echo "starting ui..."
docker run \
-d \
-p "${UI_PORT}":3000 \
--restart=always \
--network="${DOCKER_NETWORK_NAME}" \
--env-file ./config/ui/.env \
--name="${DOCKER_NAME_UI}" \
"${DOCKER_IMAGE_NAME}":"${DOCKER_IMAGE_TAG}" ui start
else
echo "ui is already running."
fi
fi
if [[ "${API}" == true ]]; then
if [[ "${DB_ENABLED}" == true ]]; then
DOCKER_DB_ID=$(docker ps -qf name=^"${DOCKER_NAME_DB}"$)
if [ -n "${DOCKER_DB_ID}" ]; then
while ! docker exec \
"${DOCKER_NAME_DB}" \
mysqladmin \
--user=root \
--password="${DB_USER_PASSWORD}" \
--host="${DOCKER_NAME_DB}" \
ping --silent &> /dev/null ; do
echo "Waiting for db connection..."
sleep 2
done
fi
fi
DOCKER_ID_API=$(docker ps -qf name=^"${DOCKER_NAME_API}"$)
if [ -z "${DOCKER_ID_API}" ]; then
echo "starting api-server..."
docker run \
-d \
-v "${DOCKER_VOLUME_NAME_API}":"${DOCKER_CONTAINER_PROJECT_PATH}"packages/api/writable \
-p "${PORT_API}":3000 \
--restart=always \
--network="${DOCKER_NETWORK_NAME}" \
--env-file ./config/api/.env \
--name="${DOCKER_NAME_API}" \
"${DOCKER_IMAGE_NAME}":"${DOCKER_IMAGE_TAG}" api start
else
echo "api-server is already running."
fi
fi
if [[ "${REALTIME}" == true ]]; then
DOCKER_ID_REALTIME=$(docker ps -qf name=^"${DOCKER_NAME_REALTIME}"$)
if [ -z "${DOCKER_ID_REALTIME}" ]; then
echo "starting realtime-server..."
docker run \
-d \
-p "${PORT_REALTIME}":3000 \
--restart=always \
--network="${DOCKER_NETWORK_NAME}" \
--env-file ./config/realtime/.env \
--name="${DOCKER_NAME_REALTIME}" \
"${DOCKER_IMAGE_NAME}":"${DOCKER_IMAGE_TAG}" realtime start
else
echo "realtime-server is already running."
fi
fi
if [[ "${TRAIN_MANAGER}" == true ]]; then
DOCKER_ID_TRAIN_MANAGER=$(docker ps -qf name=^"${DOCKER_NAME_TRAIN_MANAGER}"$)
if [ -z "${DOCKER_ID_TRAIN_MANAGER}" ]; then
echo "starting train-manager..."
docker run \
-d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "${DOCKER_VOLUME_NAME_TRAIN_MANAGER}":"${DOCKER_CONTAINER_PROJECT_PATH}"packages/train-manager/writable \
-p "${PORT_TRAIN_MANAGER}":3000 \
--restart=always \
--network="${DOCKER_NETWORK_NAME}" \
--env-file ./config/train-manager/.env \
--name="${DOCKER_NAME_TRAIN_MANAGER}" \
"${DOCKER_IMAGE_NAME}":"${DOCKER_IMAGE_TAG}" train-manager start
else
echo "train-manager is already running."
fi
fi