-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcouch2pg-entrypoint.sh
executable file
·72 lines (58 loc) · 1.62 KB
/
couch2pg-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
#!/bin/bash
set -e
WAIT_THRESHOLD="${WAIT_THRESHOLD:-20}"
SLEEP_SECONDS="${SLEEP_SECONDS:-5}"
welcome_message(){
echo "Starting couch2pg process">&2
}
set_postgres_url(){
export POSTGRESQL_URL=postgres://$POSTGRES_USER_NAME:$POSTGRES_PASSWORD@$POSTGRES_SERVER_NAME:5432/$POSTGRES_DB_NAME
echo "Set postgres URL to $POSTGRESQL_URL" >&2
}
check_if_postgres_is_ready(){
#waiting for postgres
wait_count=0
echo "check_if_postgres_is_ready with \"pg_isready -q -h $POSTGRES_SERVER_NAME -U $POSTGRES_USER_NAME --d $POSTGRES_DB_NAME\""
until pg_isready -q -h $POSTGRES_SERVER_NAME -U $POSTGRES_USER_NAME --d $POSTGRES_DB_NAME
do
echo "Waiting for PostgreSQL..." >&2
wait_count=$((wait_count +1))
if [[ "$wait_count" -gt $WAIT_THRESHOLD ]]; then
echo "No PostgreSQL DB Found" >&2
exit 1
fi
sleep $SLEEP_SECONDS
done
echo "Postgres is ready moving on ...">&2
}
get_couch_http_code(){
curl --silent --show-error --head "$COUCHDB_URL/" --write-out '%{http_code}' | tail -n1
}
check_if_couchdb_is_ready(){
# check if couchdb is up
wait_count=0
echo "START Checking for cht couchdb at ${COUCHDB_URL}" >&2
until get_couch_http_code | grep "200" > /dev/null
do
echo "Waiting for cht couchdb" >&2
wait_count=$((wait_count +1))
if [[ "$wait_count" -gt $WAIT_THRESHOLD ]]; then
echo "No couchdb end point Found" >&2
exit 1
fi
sleep $SLEEP_SECONDS
done
echo "couchdb is ready">&2
}
launch_couch2pg(){
node index.js
}
main (){
welcome_message
set_postgres_url
check_if_couchdb_is_ready
check_if_postgres_is_ready
echo "Launching couch2pg">&2
launch_couch2pg
}
"$@"