You've already forked postgres
mirror of
https://github.com/docker-library/postgres.git
synced 2025-07-26 23:21:10 +03:00
more sane way of starting and stopping postgres server using pg_ctl as recommended per postgresql docs
This commit is contained in:
@ -7,8 +7,8 @@ set_listen_addresses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" = 'postgres' ]; then
|
if [ "$1" = 'postgres' ]; then
|
||||||
mkdir -p "$PGDATA"
|
mkdir -p "${PGDATA}"
|
||||||
chown -R postgres "$PGDATA"
|
chown -R postgres "${PGDATA}"
|
||||||
|
|
||||||
chmod g+s /run/postgresql
|
chmod g+s /run/postgresql
|
||||||
chown -R postgres /run/postgresql
|
chown -R postgres /run/postgresql
|
||||||
@ -44,21 +44,11 @@ if [ "$1" = 'postgres' ]; then
|
|||||||
|
|
||||||
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"
|
{ 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
|
# internal start of server in order to allow set-up using psql-client
|
||||||
|
gosu postgres pg_ctl -D ${PGDATA} \
|
||||||
gosu postgres "$@" &
|
-o "-c listen_addresses=''" \
|
||||||
pid="$!"
|
-w start # does not listen on TCP/IP and wait
|
||||||
for i in {30..0}; do
|
# until start finished
|
||||||
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
|
|
||||||
|
|
||||||
: ${POSTGRES_USER:=postgres}
|
: ${POSTGRES_USER:=postgres}
|
||||||
: ${POSTGRES_DB:=$POSTGRES_USER}
|
: ${POSTGRES_DB:=$POSTGRES_USER}
|
||||||
@ -91,11 +81,7 @@ if [ "$1" = 'postgres' ]; then
|
|||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! kill -s TERM "$pid" || ! wait "$pid"; then
|
gosu postgres pg_ctl -D ${PGDATA} -m fast -w stop
|
||||||
echo >&2 'PostgreSQL init process failed'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set_listen_addresses '*'
|
set_listen_addresses '*'
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
Reference in New Issue
Block a user