Skip to content

Commit 7b15401

Browse files
committed
run directory creation & permission change when PGDATA is a mountpoint
Signed-off-by: Minh-Quan TRAN <[email protected]>
1 parent b927923 commit 7b15401

13 files changed

+130
-78
lines changed

10/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

10/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

11/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

11/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.3/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.3/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.4/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.4/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.5/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.5/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.6/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.6/docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

docker-entrypoint.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030

3131
# allow the container to be started with `--user`
3232
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
33-
mkdir -p "$PGDATA"
34-
chown -R postgres "$PGDATA"
35-
chmod 700 "$PGDATA"
33+
if mountpoint $PGDATA; then
34+
mkdir -p "$PGDATA"
35+
chown -R postgres "$PGDATA"
36+
chmod 700 "$PGDATA"
37+
fi
3638

3739
mkdir -p /var/run/postgresql
3840
chown -R postgres /var/run/postgresql
@@ -49,9 +51,11 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
4951
fi
5052

5153
if [ "$1" = 'postgres' ]; then
52-
mkdir -p "$PGDATA"
53-
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
54-
chmod 700 "$PGDATA" 2>/dev/null || :
54+
if mountpoint $PGDATA; then
55+
mkdir -p "$PGDATA"
56+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
57+
chmod 700 "$PGDATA" 2>/dev/null || :
58+
fi
5559

5660
# look specifically for PG_VERSION, as it is expected in the DB dir
5761
if [ ! -s "$PGDATA/PG_VERSION" ]; then

0 commit comments

Comments
 (0)