Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix entry scripts to start up correctly.
  • Loading branch information
jtwebman committed Oct 26, 2016
commit 6a289462e8767ff520a9931b9bc3c221914d7ddb
35 changes: 17 additions & 18 deletions 9.4/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/bin/sh
set -e
#!/bin/sh -e

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
set_listen_addresses() {
sedEscapedValue="$(echo "$1" | sed 's/[\/&]/\\&/g')"
sed -ri "s/^#?(listen_addresses\s*=\s*)\S+/\1'$sedEscapedValue'/" "$PGDATA/postgresql.conf"
}

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chmod 700 "$PGDATA"
chown -R postgres "$PGDATA"

mkdir -p /run/postgresql
chmod g+s /run/postgresql
chown -R postgres /run/postgresql
chmod g+s /var/run/postgresql
chown -R postgres /var/run/postgresql

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
eval "su-exec postgres initdb $POSTGRES_INITDB_ARGS"
su-exec postgres initdb

# check password first so we can output the warning before postgres
# messes it up
Expand All @@ -33,7 +32,6 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is
effectively any other container on the same
system.

Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run".
****************************************************
Expand All @@ -46,17 +44,17 @@ if [ "$1" = 'postgres' ]; then
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
# does not listen on TCP/IP and waits until start finishes
su-exec postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-o "-c listen_addresses=''" \
-w start

: ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER}
export POSTGRES_USER POSTGRES_DB

if [ "$POSTGRES_DB" != 'postgres' ]; then
psql -v ON_ERROR_STOP=1 --username postgres <<-EOSQL
psql --username postgres <<-EOSQL
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
Expand All @@ -67,23 +65,24 @@ if [ "$1" = 'postgres' ]; then
else
op='CREATE'
fi
psql -v ON_ERROR_STOP=1 --username postgres <<-EOSQL

psql --username postgres <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
echo

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB"; echo ;;
*) echo "$0: ignoring $f" ;;
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f" && echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
set_listen_addresses '*'

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand Down
35 changes: 17 additions & 18 deletions 9.5/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/bin/sh
set -e
#!/bin/sh -e

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
set_listen_addresses() {
sedEscapedValue="$(echo "$1" | sed 's/[\/&]/\\&/g')"
sed -ri "s/^#?(listen_addresses\s*=\s*)\S+/\1'$sedEscapedValue'/" "$PGDATA/postgresql.conf"
}

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chmod 700 "$PGDATA"
chown -R postgres "$PGDATA"

mkdir -p /run/postgresql
chmod g+s /run/postgresql
chown -R postgres /run/postgresql
chmod g+s /var/run/postgresql
chown -R postgres /var/run/postgresql

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
eval "su-exec postgres initdb $POSTGRES_INITDB_ARGS"
su-exec postgres initdb

# check password first so we can output the warning before postgres
# messes it up
Expand All @@ -33,7 +32,6 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is
effectively any other container on the same
system.

Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run".
****************************************************
Expand All @@ -46,17 +44,17 @@ if [ "$1" = 'postgres' ]; then
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
# does not listen on TCP/IP and waits until start finishes
su-exec postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-o "-c listen_addresses=''" \
-w start

: ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER}
export POSTGRES_USER POSTGRES_DB

if [ "$POSTGRES_DB" != 'postgres' ]; then
psql -v ON_ERROR_STOP=1 --username postgres <<-EOSQL
psql --username postgres <<-EOSQL
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
Expand All @@ -67,23 +65,24 @@ if [ "$1" = 'postgres' ]; then
else
op='CREATE'
fi
psql -v ON_ERROR_STOP=1 --username postgres <<-EOSQL

psql --username postgres <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
echo

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB"; echo ;;
*) echo "$0: ignoring $f" ;;
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f" && echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
set_listen_addresses '*'

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand Down
35 changes: 17 additions & 18 deletions 9.6/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/bin/sh
set -e
#!/bin/sh -e

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
set_listen_addresses() {
sedEscapedValue="$(echo "$1" | sed 's/[\/&]/\\&/g')"
sed -ri "s/^#?(listen_addresses\s*=\s*)\S+/\1'$sedEscapedValue'/" "$PGDATA/postgresql.conf"
}

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chmod 700 "$PGDATA"
chown -R postgres "$PGDATA"

mkdir -p /run/postgresql
chmod g+s /run/postgresql
chown -R postgres /run/postgresql
chmod g+s /var/run/postgresql
chown -R postgres /var/run/postgresql

# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
eval "su-exec postgres initdb $POSTGRES_INITDB_ARGS"
su-exec postgres initdb

# check password first so we can output the warning before postgres
# messes it up
Expand All @@ -33,7 +32,6 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is
effectively any other container on the same
system.

Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run".
****************************************************
Expand All @@ -46,17 +44,17 @@ if [ "$1" = 'postgres' ]; then
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA/pg_hba.conf"

# internal start of server in order to allow set-up using psql-client
# does not listen on external TCP/IP and waits until start finishes
# does not listen on TCP/IP and waits until start finishes
su-exec postgres pg_ctl -D "$PGDATA" \
-o "-c listen_addresses='localhost'" \
-o "-c listen_addresses=''" \
-w start

: ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER}
export POSTGRES_USER POSTGRES_DB

if [ "$POSTGRES_DB" != 'postgres' ]; then
psql -v ON_ERROR_STOP=1 --username postgres <<-EOSQL
psql --username postgres <<-EOSQL
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
Expand All @@ -67,23 +65,24 @@ if [ "$1" = 'postgres' ]; then
else
op='CREATE'
fi
psql -v ON_ERROR_STOP=1 --username postgres <<-EOSQL

psql --username postgres <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
echo

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB"; echo ;;
*) echo "$0: ignoring $f" ;;
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < "$f" && echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

su-exec postgres pg_ctl -D "$PGDATA" -m fast -w stop
set_listen_addresses '*'

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand Down