Skip to content

Commit 0e45b71

Browse files
committed
Apply function name changes as discussed in docker-library/mysql#471
1 parent 0a09daf commit 0e45b71

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

docker-entrypoint.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _is_sourced() {
3131
}
3232

3333
# used to create initial posgres directories and if run as root, ensure ownership to the "postgres" user
34-
docker_create_database_dirs() {
34+
docker_create_db_directories() {
3535
local user="$(id -u)"
3636

3737
mkdir -p "$PGDATA"
@@ -82,7 +82,7 @@ docker_init_database_dir() {
8282
}
8383

8484
# print large warning if POSTGRES_PASSWORD is empty
85-
docker_print_password_warning() {
85+
docker_verify_minimum_env() {
8686
# check password first so we can output the warning before postgres
8787
# messes it up
8888
if [ "${#POSTGRES_PASSWORD}" -ge 100 ]; then
@@ -119,7 +119,7 @@ docker_print_password_warning() {
119119
# run, source, or read files from /docker-entrypoint-initdb.d (or specified directory)
120120
docker_process_init_files() {
121121
# psql here for backwards compatiblilty "${psql[@]}"
122-
psql=( docker_psql_run )
122+
psql=( docker_process_sql )
123123

124124
local initDir="${1:-/docker-entrypoint-initdb.d}"
125125

@@ -137,16 +137,16 @@ docker_process_init_files() {
137137
. "$f"
138138
fi
139139
;;
140-
*.sql) echo "$0: running $f"; docker_psql_run -f "$f"; echo ;;
141-
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_psql_run; echo ;;
140+
*.sql) echo "$0: running $f"; docker_process_sql -f "$f"; echo ;;
141+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;;
142142
*) echo "$0: ignoring $f" ;;
143143
esac
144144
echo
145145
done
146146
}
147147

148148
# run `psql` with proper arguments for user and db
149-
docker_psql_run() {
149+
docker_process_sql() {
150150
local query_runner=( psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --no-password )
151151
if [ -n "$POSTGRES_DB" ]; then
152152
query_runner+=( --dbname "$POSTGRES_DB" )
@@ -157,25 +157,25 @@ docker_psql_run() {
157157

158158
# create initial postgresql superuser with password and database
159159
# uses environment variables for input: POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB
160-
docker_setup_database() {
160+
docker_setup_db() {
161161
if [ "$POSTGRES_DB" != 'postgres' ]; then
162-
POSTGRES_DB= docker_psql_run --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
162+
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
163163
CREATE DATABASE :"db" ;
164164
EOSQL
165165
echo
166166
fi
167167
}
168168

169169
# get user/pass and db from env vars or via file
170-
docker_setup_env_vars() {
170+
docker_setup_env() {
171171
file_env 'POSTGRES_PASSWORD'
172172

173173
file_env 'POSTGRES_USER' 'postgres'
174174
file_env 'POSTGRES_DB' "$POSTGRES_USER"
175175
}
176176

177177
# append md5 or trust auth to pg_hba.conf based on existence of POSTGRES_PASSWORD
178-
docker_setup_pg_hba() {
178+
pg_setup_hba_conf() {
179179
local authMethod
180180
if [ "$POSTGRES_PASSWORD" ]; then
181181
authMethod='md5'
@@ -191,7 +191,7 @@ docker_setup_pg_hba() {
191191

192192
# start socket-only postgresql server for setting up user or running scripts
193193
# all arguments will be passed along as arguments to `postgres` (via pg_ctl)
194-
docker_temporary_pgserver_start() {
194+
docker_temp_server_start() {
195195
# internal start of server in order to allow set-up using psql-client
196196
# does not listen on external TCP/IP and waits until start finishes (can be overridden via args)
197197
PGUSER="${PGUSER:-$POSTGRES_USER}" \
@@ -201,7 +201,7 @@ docker_temporary_pgserver_start() {
201201
}
202202

203203
# stop postgresql server after done setting up user and running scripts
204-
docker_temporary_pgserver_stop() {
204+
docker_temp_server_stop() {
205205
PGUSER="${PGUSER:-postgres}" \
206206
pg_ctl -D "$PGDATA" -m fast -w stop
207207
}
@@ -212,34 +212,34 @@ _main() {
212212
set -- postgres "$@"
213213
fi
214214

215-
# setup data directories and permissions, then restart script as postgres user
216-
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
217-
docker_create_database_dirs
218-
exec gosu postgres "$BASH_SOURCE" "$@"
219-
fi
220215

221216
if [ "$1" = 'postgres' ]; then
222-
docker_create_database_dirs
217+
# setup data directories and permissions (when run as root)
218+
docker_create_db_directories
219+
if [ "$(id -u)" = '0' ]; then
220+
# then restart script as postgres user
221+
exec gosu postgres "$BASH_SOURCE" "$@"
222+
fi
223223

224224
# only run initialization on an empty data directory
225225
# look specifically for PG_VERSION, as it is expected in the DB dir
226226
if [ ! -s "$PGDATA/PG_VERSION" ]; then
227227
docker_init_database_dir
228228

229-
docker_setup_env_vars
230-
docker_print_password_warning
231-
docker_setup_pg_hba
229+
docker_setup_env
230+
docker_verify_minimum_env
231+
pg_setup_hba_conf
232232

233233
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
234234
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
235235
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
236-
docker_temporary_pgserver_start "${@:2}"
236+
docker_temp_server_start "${@:2}"
237237

238-
docker_setup_database
238+
docker_setup_db
239239

240240
docker_process_init_files
241241

242-
docker_temporary_pgserver_stop
242+
docker_temp_server_stop
243243
unset PGPASSWORD
244244

245245
echo

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy