11#! /usr/bin/env bash
2- PUID=${PUID:- 5050}
3- PGID=${PGID:- 0}
4-
5- if [ " $( id -u) " = " 0" ]; then
6- # Ensure a group with the target GID exists
7- if ! getent group " $PGID " > /dev/null 2>&1 ; then
8- addgroup -g " $PGID " pggroup
9- fi
10-
11- # Reassign the pgadmin user to the desired UID/GID
12- usermod -o -u " $PUID " -g " $PGID " pgadmin 2>&1 || \
13- echo " WARNING: usermod failed for UID=$PUID GID=$PGID "
14-
15- # Compose su-exec command
16- SU_EXEC=" su-exec $PUID :$PGID "
17- echo " pgAdmin will run as UID=$PUID , GID=$PGID "
18- else
19- SU_EXEC=" "
20- fi
212
223# Fixup the passwd file, in case we're on OpenShift
234if ! whoami > /dev/null 2>&1 ; then
@@ -28,27 +9,6 @@ if ! whoami > /dev/null 2>&1; then
289 fi
2910fi
3011
31- # Helper: chown a path only if it exists and isn't already owned correctly
32- safe_chown () {
33- local target=" $1 "
34- local owner=" $2 :$3 " # UID:GID
35-
36- # Skip if path doesn't exist
37- [ -e " $target " ] || return 0
38-
39- # Get current ownership
40- local current_uid current_gid
41- current_uid=$( stat -c ' %u' " $target " )
42- current_gid=$( stat -c ' %g' " $target " )
43-
44- # Skip if already owned correctly
45- if [ " $current_uid " = " $2 " ] && [ " $current_gid " = " $3 " ]; then
46- return 0
47- fi
48-
49- chown -R " $owner " " $target "
50- }
51-
5212# usage: file_env VAR [DEFAULT] ie: file_env 'XYZ_DB_PASSWORD' 'example'
5313# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
5414# "$XYZ_DB_PASSWORD" from a file, for Docker's secrets feature)
222182# to define the Gunicorn worker timeout
223183TIMEOUT=$( cd /pgadmin4 && /venv/bin/python3 -c ' import config; print(config.SESSION_EXPIRATION_TIME * 60 * 60 * 24)' )
224184
225- if [ " $( id -u) " = " 0" ]; then
226- for path in /run/pgadmin /var/lib/pgadmin " $CONFIG_DISTRO_FILE_PATH " /certs; do
227- safe_chown " $path " " $PUID " " $PGID "
228- done
229- fi
230-
231185# NOTE: currently pgadmin can run only with 1 worker due to sessions implementation
232186# Using --threads to have multi-threaded single-process worker
233187
242196fi
243197
244198if [ -n " ${PGADMIN_ENABLE_TLS} " ]; then
245- exec $SU_EXEC /venv/bin/gunicorn --limit-request-line " ${GUNICORN_LIMIT_REQUEST_LINE:- 8190} " --timeout " ${TIMEOUT} " --bind " ${BIND_ADDRESS} " -w 1 --threads " ${GUNICORN_THREADS:- 25} " --access-logfile " ${GUNICORN_ACCESS_LOGFILE:- -} " --keyfile /certs/server.key --certfile /certs/server.cert -c gunicorn_config.py run_pgadmin:app
199+ exec /venv/bin/gunicorn --limit-request-line " ${GUNICORN_LIMIT_REQUEST_LINE:- 8190} " --timeout " ${TIMEOUT} " --bind " ${BIND_ADDRESS} " -w 1 --threads " ${GUNICORN_THREADS:- 25} " --access-logfile " ${GUNICORN_ACCESS_LOGFILE:- -} " --keyfile /certs/server.key --certfile /certs/server.cert -c gunicorn_config.py run_pgadmin:app
246200else
247- exec $SU_EXEC /venv/bin/gunicorn --limit-request-line " ${GUNICORN_LIMIT_REQUEST_LINE:- 8190} " --limit-request-fields " ${GUNICORN_LIMIT_REQUEST_FIELDS:- 100} " --limit-request-field_size " ${GUNICORN_LIMIT_REQUEST_FIELD_SIZE:- 8190} " --timeout " ${TIMEOUT} " --bind " ${BIND_ADDRESS} " -w 1 --threads " ${GUNICORN_THREADS:- 25} " --access-logfile " ${GUNICORN_ACCESS_LOGFILE:- -} " -c gunicorn_config.py run_pgadmin:app
201+ exec /venv/bin/gunicorn --limit-request-line " ${GUNICORN_LIMIT_REQUEST_LINE:- 8190} " --limit-request-fields " ${GUNICORN_LIMIT_REQUEST_FIELDS:- 100} " --limit-request-field_size " ${GUNICORN_LIMIT_REQUEST_FIELD_SIZE:- 8190} " --timeout " ${TIMEOUT} " --bind " ${BIND_ADDRESS} " -w 1 --threads " ${GUNICORN_THREADS:- 25} " --access-logfile " ${GUNICORN_ACCESS_LOGFILE:- -} " -c gunicorn_config.py run_pgadmin:app
248202fi
0 commit comments