Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de2aa0b

Browse files
committed
Check for "help" to short circuit server starting (since they break when passed to pg_ctl)
1 parent 4c4693e commit de2aa0b

13 files changed

+234
-13
lines changed

10/alpine/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

10/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

11/alpine/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

11/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

12/alpine/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

12/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

9.4/alpine/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

9.4/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

9.5/alpine/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

9.5/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,30 @@ docker_temp_server_stop() {
229229
pg_ctl -D "$PGDATA" -m fast -w stop
230230
}
231231

232+
# check arguments for an option that would cause postgres to stop
233+
# return true if there is one
234+
_pg_want_help() {
235+
local arg
236+
for arg; do
237+
case "$arg" in
238+
# postgres --help | grep 'then exit'
239+
# leaving out -C on purpose since it always fails and is unhelpful:
240+
# postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
241+
-'?'|--help|--describe-config|-V|--version)
242+
return 0
243+
;;
244+
esac
245+
done
246+
return 1
247+
}
248+
232249
_main() {
233250
# if first arg looks like a flag, assume we want to run postgres server
234251
if [ "${1:0:1}" = '-' ]; then
235252
set -- postgres "$@"
236253
fi
237254

238-
if [ "$1" = 'postgres' ]; then
255+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
239256
docker_setup_env
240257
# setup data directories and permissions (when run as root)
241258
docker_create_db_directories

0 commit comments

Comments
 (0)