-
Notifications
You must be signed in to change notification settings - Fork 1.2k
more sane way of starting and stopping postgres server using pg_ctl #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| : ${POSTGRES_USER:=postgres} | ||
| : ${POSTGRES_DB:=$POSTGRES_USER} | ||
|
|
@@ -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 '*' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.