Skip to content

Commit d3e8051

Browse files
committed
add service pre condition
1 parent 9d26597 commit d3e8051

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

airflow/entrypoint.sh

+35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,41 @@ function bootstrap {
66
done
77
}
88

9+
function wait_for_it()
10+
{
11+
local serviceport=$1
12+
local service=${serviceport%%:*}
13+
local port=${serviceport#*:}
14+
local retry_seconds=5
15+
local max_try=100
16+
let i=1
17+
18+
nc -z $service $port
19+
result=$?
20+
21+
until [ $result -eq 0 ]; do
22+
echo "[$i/$max_try] check for ${service}:${port}..."
23+
echo "[$i/$max_try] ${service}:${port} is not available yet"
24+
if (( $i == $max_try )); then
25+
echo "[$i/$max_try] ${service}:${port} is still not available; giving up after ${max_try} tries. :/"
26+
exit 1
27+
fi
28+
29+
echo "[$i/$max_try] try in ${retry_seconds}s once again ..."
30+
let "i++"
31+
sleep $retry_seconds
32+
33+
nc -z $service $port
34+
result=$?
35+
done
36+
echo "[$i/$max_try] $service:${port} is available."
37+
}
38+
39+
for i in ${SERVICE_PRECONDITION[@]}
40+
do
41+
wait_for_it ${i}
42+
done
43+
944
case "$1" in
1045
webserver)
1146
bootstrap

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ x-airflow-common: &airflow-common
1616
HDFS_PORT: "8020"
1717
INGESTION_API_URL: "http://api:3000"
1818
SCRIPTS_PATH_PREFIX: /scripts/spark/
19+
SERVICE_PRECONDITION: airflow-db:5432
1920
depends_on:
2021
- airflow-db
2122

@@ -77,6 +78,7 @@ services:
7778
command: "hive --service metastore"
7879
environment:
7980
NODE_TYPE: metastore
81+
SERVICE_PRECONDITION: hive-postgres:5432 namenode:50070
8082
ports:
8183
- 9083:9083
8284

hadoop/docker/hive/entrypoint.sh

+35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
11
#!/bin/bash
2+
function wait_for_it()
3+
{
4+
local serviceport=$1
5+
local service=${serviceport%%:*}
6+
local port=${serviceport#*:}
7+
local retry_seconds=5
8+
local max_try=100
9+
let i=1
10+
11+
nc -z $service $port
12+
result=$?
13+
14+
until [ $result -eq 0 ]; do
15+
echo "[$i/$max_try] check for ${service}:${port}..."
16+
echo "[$i/$max_try] ${service}:${port} is not available yet"
17+
if (( $i == $max_try )); then
18+
echo "[$i/$max_try] ${service}:${port} is still not available; giving up after ${max_try} tries. :/"
19+
exit 1
20+
fi
21+
22+
echo "[$i/$max_try] try in ${retry_seconds}s once again ..."
23+
let "i++"
24+
sleep $retry_seconds
25+
26+
nc -z $service $port
27+
result=$?
28+
done
29+
echo "[$i/$max_try] $service:${port} is available."
30+
}
31+
32+
for i in ${SERVICE_PRECONDITION[@]}
33+
do
34+
wait_for_it ${i}
35+
done
36+
237
if [ ! -f populated -a "$NODE_TYPE" == "metastore" ]; then
338
schematool -dbType postgres -initSchema
439
touch populated

kubernetes/airflow/scheduler.yml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ spec:
2424
value: airflow-postgres-svc.airflow.svc.cluster.local
2525
- name: POSTGRES_PORT
2626
value: "5432"
27+
- name: SERVICE_PRECONDITION
28+
value: airflow-postgres-svc.airflow.svc.cluster.local:5432
2729
- name: EXECUTOR
2830
value: KubernetesExecutor
2931
- name: HDFS_HOST

kubernetes/airflow/webserver.yml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ spec:
2424
value: airflow-postgres-svc.airflow.svc.cluster.local
2525
- name: POSTGRES_PORT
2626
value: "5432"
27+
- name: SERVICE_PRECONDITION
28+
value: airflow-postgres-svc.airflow.svc.cluster.local:5432
2729
- name: EXECUTOR
2830
value: KubernetesExecutor
2931
- name: HDFS_HOST

kubernetes/hive/metastore.yml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ spec:
2424
env:
2525
- name: NODE_TYPE
2626
value: metastore
27+
- name: SERVICE_PRECONDITION
28+
value: hive-postgres-svc.dataplatform.svc.cluster.local:5432 namenode-svc.dataplatform.svc.cluster.local:50070
2729
args:
2830
- "bash"
2931
- "-c"

0 commit comments

Comments
 (0)