-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
executable file
·51 lines (41 loc) · 1.27 KB
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -Eeo pipefail
# Starts a simply-configured server with default authentication that trusts
# local connections from inside the container.
export PGDATA=${PGDATA:-/var/lib/postgresql/data/pgdata}
main() {
if [ "${1:-postgres}" != 'postgres' ]; then
exec "$@"
fi
if [ "$(id -u)" = '0' ]; then
cat >&2 <<-'EOE'
Error: Postgres cannot be run by root. Please restart the container
with specifying a user, or run another application on startup.
EOE
exit 1
fi
# Initialize the database.
mkdir -p "$PGDATA"
chmod 700 "$PGDATA" || :
if [ ! -s "$PGDATA/PG_VERSION" ]; then
opts=(
-D "$PGDATA"
-U postgres
-c listen_addresses='*'
-c dynamic_library_path="\$libdir:/var/lib/postgresql/tembo/mod"
--auth trust
--encoding UNICODE
)
if [ "$(pg_config --version | perl -ne '/(\d+)/ & print $1')" -ge 17 ]; then
# Prefer builtin C.UTF-8.
opts+=(--locale-provider builtin --builtin-locale C.UTF-8)
else
# Default to en_US.UTF-8.
opts+=(--locale en_US.UTF-8)
fi
initdb "${opts[@]}"
fi
# Start the server. Logs go to STDOUT.
postgres
}
main "$@"