Skip to content

Commit d49499c

Browse files
committed
more sane way of starting and stopping postgres server using pg_ctl as recommended per postgresql docs
1 parent a82c28e commit d49499c

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

docker-entrypoint.sh

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ set_listen_addresses() {
77
}
88

99
if [ "$1" = 'postgres' ]; then
10-
mkdir -p "$PGDATA"
11-
chown -R postgres "$PGDATA"
10+
mkdir -p "${PGDATA}"
11+
chown -R postgres "${PGDATA}"
1212

1313
chmod g+s /run/postgresql
1414
chown -R postgres /run/postgresql
@@ -44,21 +44,11 @@ if [ "$1" = 'postgres' ]; then
4444

4545
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
4646

47-
set_listen_addresses '' # we're going to start up postgres, but it's not ready for use yet (this is initialization), so don't listen to the outside world yet
48-
49-
gosu postgres "$@" &
50-
pid="$!"
51-
for i in {30..0}; do
52-
if echo 'SELECT 1' | psql --username postgres &> /dev/null; then
53-
break
54-
fi
55-
echo 'PostgreSQL init process in progress...'
56-
sleep 1
57-
done
58-
if [ "$i" = 0 ]; then
59-
echo >&2 'PostgreSQL init process failed'
60-
exit 1
61-
fi
47+
# internal start of server in order to allow set-up using psql-client
48+
gosu postgres pg_ctl -D ${PGDATA} \
49+
-o "-c listen_addresses=''" \
50+
-w start # does not listen on TCP/IP and wait
51+
# until start finished
6252

6353
: ${POSTGRES_USER:=postgres}
6454
: ${POSTGRES_DB:=$POSTGRES_USER}
@@ -91,11 +81,7 @@ if [ "$1" = 'postgres' ]; then
9181
echo
9282
done
9383

94-
if ! kill -s TERM "$pid" || ! wait "$pid"; then
95-
echo >&2 'PostgreSQL init process failed'
96-
exit 1
97-
fi
98-
84+
gosu postgres pg_ctl -D ${PGDATA} -m fast -w stop
9985
set_listen_addresses '*'
10086

10187
echo

0 commit comments

Comments
 (0)