forked from RedHatInsights/vulnerability-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait-for-services.sh
executable file
·38 lines (32 loc) · 1.21 KB
/
wait-for-services.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
#!/usr/bin/bash
set -e
cmd="$@"
if [ ! -z "$POSTGRESQL_DATABASE" ]; then
>&2 echo "Checking if PostgreSQL is up"
until python3 -c "import psycopg2;c=psycopg2.connect(host=\"$POSTGRESQL_HOST\",database=\"$POSTGRESQL_DATABASE\",user=\"$POSTGRESQL_USER\",port=\"$POSTGRESQL_PORT\",password=\"$POSTGRESQL_PASSWORD\");c.close()" &> /dev/null; do
>&2 echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
else
>&2 echo "Skipping PostgreSQL check"
fi
if [ ! -z "$VMAAS_WEBSOCKET_HOST" ]; then
>&2 echo "Checking if websocket server is up"
until curl http://$VMAAS_WEBSOCKET_HOST/api/v1/monitoring/health &>/dev/null; do
>&2 echo "Websocket server is unavailable - sleeping"
sleep 1
done
else
>&2 echo "Skipping websocket server check"
fi
if [ ! -z "$KAFKA_HOST" ] && echo "from kafka import KafkaConsumer" | python3 &> /dev/null; then
>&2 echo "Checking if Kafka server is up"
until echo "from kafka import KafkaConsumer;c=KafkaConsumer(bootstrap_servers=[\"$KAFKA_HOST:$KAFKA_PORT\"]);c.close()" | python3 &> /dev/null; do
>&2 echo "Kafka server is unavailable - sleeping"
sleep 1
done
else
>&2 echo "Skipping Kafka server check"
fi
>&2 echo "Everything is up - executing command"
exec $cmd