pg_isready
789 Bytes
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
#!/bin/sh
set -xe
_msg() {
column_count=${#1}
echo "$1" 1>&2
_dotted=
}
_dot() {
[ "z$_dotted" = "z" ] && echo -n " " 1>&2 && _dotted=1
echo -n "." 1>&2
column_count=$(($column_count + 1))
if [ $column_count = 20 ]; then
echo
column_count=1
fi
}
_done() {
echo " done." 1>&2
column_count=1
}
_msg "Waiting for postgres to acception connections:"
while :; do
tries=10
while [ $tries -gt 0 ]; do
if pg_isready -h "$PGHOST" 1>/dev/null 2>/dev/null; then break 2; fi
sleep 1
tries=$(($tries - 1))
done
_dot
done
_done
_msg "Waiting for $PGUSER@$PGDATABASE to be available:"
while :; do
tries=10
while [ $tries -gt 0 ]; do
if psql 1>/dev/null 2>/dev/null; then break 2; fi
sleep 1
tries=$(($tries - 1))
done
_dot
done
_done