mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-11-02 20:30:17 -06:00
Add an option to load/replace the servers.json file on each container startup. #8540
This commit is contained in:
1 parent
f9af74529c
commit
2d10e95311
2 files changed
+34
-11
No files matched your search
@@ -134,6 +134,14 @@ Override the default file path for the server definition list. See the
|
|||||||
/pgadmin4/servers.json mapped file below for more information. See the format
|
/pgadmin4/servers.json mapped file below for more information. See the format
|
||||||
of the `Servers JSON file <https://www.pgadmin.org/docs/pgadmin4/latest/import_export_servers.html#json-format>`_.
|
of the `Servers JSON file <https://www.pgadmin.org/docs/pgadmin4/latest/import_export_servers.html#json-format>`_.
|
||||||
|
|
||||||
|
**PGADMIN_REPLACE_SERVERS_ON_STARTUP**
|
||||||
|
|
||||||
|
*Default: null*
|
||||||
|
|
||||||
|
By default, the server definitions are only loaded on first launch, i.e. when initializing the configuration database. See PGADMIN_SERVER_JSON_FILE above.
|
||||||
|
|
||||||
|
If this variable is set to True, the server definitions will be replaced on every launch. This can be used to declaratively manage the server definitions.
|
||||||
|
|
||||||
**PGADMIN_PREFERENCES_JSON_FILE**
|
**PGADMIN_PREFERENCES_JSON_FILE**
|
||||||
|
|
||||||
*Default: /pgadmin4/preferences.json*
|
*Default: /pgadmin4/preferences.json*
|
||||||
|
|||||||
+26
-11
@@ -72,6 +72,27 @@ if [ -n "${PGADMIN_CONFIG_CONFIG_DATABASE_URI}" ]; then
|
|||||||
external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)")
|
external_config_db_exists=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from check_external_config_db import check_external_config_db; val = check_external_config_db("${PGADMIN_CONFIG_CONFIG_DATABASE_URI}"); print(val)")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# DRY of the code to load the PGADMIN_SERVER_JSON_FILE
|
||||||
|
function load_server_json_file() {
|
||||||
|
export PGADMIN_SERVER_JSON_FILE="${PGADMIN_SERVER_JSON_FILE:-/pgadmin4/servers.json}"
|
||||||
|
|
||||||
|
EXTRA_ARGS=""
|
||||||
|
|
||||||
|
if [ "${PGADMIN_REPLACE_SERVERS_ON_STARTUP}" = "True" ]; then
|
||||||
|
EXTRA_ARGS="--replace"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "${PGADMIN_SERVER_JSON_FILE}" ]; then
|
||||||
|
# When running in Desktop mode, no user is created
|
||||||
|
# so we have to import servers anonymously
|
||||||
|
if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then
|
||||||
|
/venv/bin/python3 /pgadmin4/setup.py load-servers "${PGADMIN_SERVER_JSON_FILE}" ${EXTRA_ARGS}
|
||||||
|
else
|
||||||
|
/venv/bin/python3 /pgadmin4/setup.py load-servers "${PGADMIN_SERVER_JSON_FILE}" --user "${PGADMIN_DEFAULT_EMAIL}" ${EXTRA_ARGS}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ ! -f /var/lib/pgadmin/pgadmin4.db ] && [ "${external_config_db_exists}" = "False" ]; then
|
if [ ! -f /var/lib/pgadmin/pgadmin4.db ] && [ "${external_config_db_exists}" = "False" ]; then
|
||||||
if [ -z "${PGADMIN_DEFAULT_EMAIL}" ] || { [ -z "${PGADMIN_DEFAULT_PASSWORD}" ] && [ -z "${PGADMIN_DEFAULT_PASSWORD_FILE}" ]; }; then
|
if [ -z "${PGADMIN_DEFAULT_EMAIL}" ] || { [ -z "${PGADMIN_DEFAULT_PASSWORD}" ] && [ -z "${PGADMIN_DEFAULT_PASSWORD_FILE}" ]; }; then
|
||||||
echo 'You need to define the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD or PGADMIN_DEFAULT_PASSWORD_FILE environment variables.'
|
echo 'You need to define the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD or PGADMIN_DEFAULT_PASSWORD_FILE environment variables.'
|
||||||
@@ -111,19 +132,11 @@ if [ ! -f /var/lib/pgadmin/pgadmin4.db ] && [ "${external_config_db_exists}" = "
|
|||||||
# Importing pgadmin4 (from this script) is enough
|
# Importing pgadmin4 (from this script) is enough
|
||||||
/venv/bin/python3 run_pgadmin.py
|
/venv/bin/python3 run_pgadmin.py
|
||||||
|
|
||||||
export PGADMIN_SERVER_JSON_FILE="${PGADMIN_SERVER_JSON_FILE:-/pgadmin4/servers.json}"
|
|
||||||
export PGADMIN_PREFERENCES_JSON_FILE="${PGADMIN_PREFERENCES_JSON_FILE:-/pgadmin4/preferences.json}"
|
export PGADMIN_PREFERENCES_JSON_FILE="${PGADMIN_PREFERENCES_JSON_FILE:-/pgadmin4/preferences.json}"
|
||||||
|
|
||||||
# Pre-load any required servers
|
# Pre-load any required servers
|
||||||
if [ -f "${PGADMIN_SERVER_JSON_FILE}" ]; then
|
load_server_json_file
|
||||||
# When running in Desktop mode, no user is created
|
|
||||||
# so we have to import servers anonymously
|
|
||||||
if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then
|
|
||||||
/venv/bin/python3 /pgadmin4/setup.py load-servers "${PGADMIN_SERVER_JSON_FILE}"
|
|
||||||
else
|
|
||||||
/venv/bin/python3 /pgadmin4/setup.py load-servers "${PGADMIN_SERVER_JSON_FILE}" --user "${PGADMIN_DEFAULT_EMAIL}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# Pre-load any required preferences
|
# Pre-load any required preferences
|
||||||
if [ -f "${PGADMIN_PREFERENCES_JSON_FILE}" ]; then
|
if [ -f "${PGADMIN_PREFERENCES_JSON_FILE}" ]; then
|
||||||
if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then
|
if [ "${PGADMIN_CONFIG_SERVER_MODE}" = "False" ]; then
|
||||||
@@ -145,7 +158,9 @@ if [ ! -f /var/lib/pgadmin/pgadmin4.db ] && [ "${external_config_db_exists}" = "
|
|||||||
chmod 600 /var/lib/pgadmin/storage/${PGADMIN_USER_CONFIG_DIR}/.pgpass
|
chmod 600 /var/lib/pgadmin/storage/${PGADMIN_USER_CONFIG_DIR}/.pgpass
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
# If already initialised and PGADMIN_REPLACE_SERVERS_ON_STARTUP is set to true, then load the server json file.
|
||||||
|
elif [ "${PGADMIN_REPLACE_SERVERS_ON_STARTUP}" = "True" ]; then
|
||||||
|
load_server_json_file
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start Postfix to handle password resets etc.
|
# Start Postfix to handle password resets etc.
|
||||||
|
|||||||
Reference in new issue
Block a user