Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,11 @@ if [ "$1" = 'postgres' ]; then

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

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

gosu postgres "$@" &
pid="$!"
for i in {30..0}; do
if echo 'SELECT 1' | psql --username postgres &> /dev/null; then
break
fi
echo 'PostgreSQL init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'PostgreSQL init process failed'
exit 1
fi
# internal start of server in order to allow set-up using psql-client
gosu postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses=''" \
-w start # does not listen on TCP/IP and waits
# until start finishes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should keep this or a similar test to make sure it is ready to run some SQL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not necessary because as far as I understand pg_ctl will only exit 0 if connection is possible. Moreover, later we do psql anyway i.e. if connection not possible the next psql will exit > 0 anyway.

: ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER}
Expand Down Expand Up @@ -91,11 +81,7 @@ if [ "$1" = 'postgres' ]; then
echo
done

if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'PostgreSQL init process failed'
exit 1
fi

gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
set_listen_addresses '*'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is now only used once, we can just put the seds here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, I would keep the function. however, an alternative is to supply the listen_address as option to pg_ctl. That would even render seds obsolote.


echo
Expand Down