2018-04-04 10:18:17 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-12-08 23:39:46 -06:00
|
|
|
# Populate config_distro.py. This has some default config, as well as anything
|
2019-08-22 09:24:04 -05:00
|
|
|
# provided by the user through the PGADMIN_CONFIG_* environment variables.
|
2019-12-08 23:39:46 -06:00
|
|
|
# Only update the file on first launch. The empty file is created during the
|
|
|
|
# container build so it can have the required ownership.
|
|
|
|
if [ `wc -m /pgadmin4/config_distro.py | awk '{ print $1 }'` = "0" ]; then
|
2019-08-22 09:24:04 -05:00
|
|
|
cat << EOF > /pgadmin4/config_distro.py
|
|
|
|
HELP_PATH = '../../docs'
|
|
|
|
DEFAULT_BINARY_PATHS = {
|
2019-10-11 05:13:06 -05:00
|
|
|
'pg': '/usr/local/pgsql-12'
|
2019-08-22 09:24:04 -05:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# This is a bit kludgy, but necessary as the container uses BusyBox/ash as
|
|
|
|
# it's shell and not bash which would allow a much cleaner implementation
|
|
|
|
for var in $(env | grep PGADMIN_CONFIG_ | cut -d "=" -f 1); do
|
|
|
|
echo ${var#PGADMIN_CONFIG_} = $(eval "echo \$$var") >> /pgadmin4/config_distro.py
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2018-04-04 10:18:17 -05:00
|
|
|
if [ ! -f /var/lib/pgadmin/pgadmin4.db ]; then
|
|
|
|
if [ -z "${PGADMIN_DEFAULT_EMAIL}" -o -z "${PGADMIN_DEFAULT_PASSWORD}" ]; then
|
|
|
|
echo 'You need to specify PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD environment variables'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the default username and password in a
|
|
|
|
# backwards compatible way
|
|
|
|
export PGADMIN_SETUP_EMAIL=${PGADMIN_DEFAULT_EMAIL}
|
|
|
|
export PGADMIN_SETUP_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
|
|
|
|
|
|
|
|
# Initialize DB before starting Gunicorn
|
|
|
|
# Importing pgadmin4 (from this script) is enough
|
|
|
|
python run_pgadmin.py
|
2018-12-05 11:16:46 -06:00
|
|
|
|
2019-08-23 03:53:24 -05:00
|
|
|
export PGADMIN_SERVER_JSON_FILE=${PGADMIN_SERVER_JSON_FILE:-/pgadmin4/servers.json}
|
2018-12-05 11:16:46 -06:00
|
|
|
# Pre-load any required servers
|
2019-06-27 09:56:37 -05:00
|
|
|
if [ -f "${PGADMIN_SERVER_JSON_FILE}" ]; then
|
2019-12-17 01:45:04 -06:00
|
|
|
# When running in Desktop mode, no user is created
|
|
|
|
# so we have to import servers anonymously
|
|
|
|
if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then
|
|
|
|
/usr/local/bin/python /pgadmin4/setup.py --load-servers "${PGADMIN_SERVER_JSON_FILE}"
|
|
|
|
else
|
|
|
|
/usr/local/bin/python /pgadmin4/setup.py --load-servers "${PGADMIN_SERVER_JSON_FILE}" --user ${PGADMIN_DEFAULT_EMAIL}
|
|
|
|
fi
|
2018-12-05 11:16:46 -06:00
|
|
|
fi
|
2018-04-04 10:18:17 -05:00
|
|
|
fi
|
|
|
|
|
2018-12-05 08:44:23 -06:00
|
|
|
# Start Postfix to handle password resets etc.
|
|
|
|
/usr/sbin/postfix start
|
|
|
|
|
2019-03-01 05:55:17 -06:00
|
|
|
# Get the session timeout from the pgAdmin config. We'll use this (in seconds)
|
|
|
|
# to define the Gunicorn worker timeout
|
|
|
|
TIMEOUT=$(cd /pgadmin4 && python -c 'import config; print(config.SESSION_EXPIRATION_TIME * 60 * 60 * 24)')
|
|
|
|
|
2018-04-04 10:18:17 -05:00
|
|
|
# NOTE: currently pgadmin can run only with 1 worker due to sessions implementation
|
|
|
|
# Using --threads to have multi-threaded single-process worker
|
|
|
|
|
|
|
|
if [ ! -z ${PGADMIN_ENABLE_TLS} ]; then
|
2019-12-02 19:14:01 -06:00
|
|
|
exec gunicorn --timeout ${TIMEOUT} --bind ${PGADMIN_LISTEN_ADDRESS:-[::]}:${PGADMIN_LISTEN_PORT:-443} -w 1 --threads ${GUNICORN_THREADS:-25} --access-logfile ${GUNICORN_ACCESS_LOGFILE:--} --keyfile /certs/server.key --certfile /certs/server.cert run_pgadmin:app
|
2018-04-04 10:18:17 -05:00
|
|
|
else
|
2019-12-02 19:14:01 -06:00
|
|
|
exec gunicorn --timeout ${TIMEOUT} --bind ${PGADMIN_LISTEN_ADDRESS:-[::]}:${PGADMIN_LISTEN_PORT:-80} -w 1 --threads ${GUNICORN_THREADS:-25} --access-logfile ${GUNICORN_ACCESS_LOGFILE:--} run_pgadmin:app
|
2018-04-04 10:18:17 -05:00
|
|
|
fi
|