-
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 1 commit
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 |
---|---|---|
|
@@ -7,8 +7,8 @@ set_listen_addresses() { | |
} | ||
|
||
if [ "$1" = 'postgres' ]; then | ||
mkdir -p "$PGDATA" | ||
chown -R postgres "$PGDATA" | ||
mkdir -p "${PGDATA}" | ||
chown -R postgres "${PGDATA}" | ||
|
||
chmod g+s /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" | ||
|
||
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} \ | ||
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. Curly braces unnecessary, but does need quotes, 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. yes, will change 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. Just FYI; from Google's Shell Style Guide:
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. "but see details" --> where are the details? 😞 |
||
-o "-c listen_addresses=''" \ | ||
-w start # does not listen on TCP/IP and wait | ||
# until start finished | ||
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. Whitespace here needs to be made consistently tabs, too. 👍 |
||
|
||
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. 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 commentThe 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. |
||
: ${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 | ||
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. Same comment as line 48. 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. also pg_ctl will exit non-zero. Indeed, I forgot to catch this e.g. by gosu postgres pg_ctl -D ${PGDATA} -m fast -w stop || {echo >&2 'PostgreSQL init process failed'; exit 1} 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. IMO if |
||
set_listen_addresses '*' | ||
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. 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.
The curly braces are unnecessary here.
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.
yes, habit of mine and my editor highlights them the better, will take that back