Skip to content

Instantly share code, notes, and snippets.

@simbo1905 simbo1905/run
Created Nov 29, 2018

What would you like to do?
OKD openshift randomise which database portal host to use for high availability
#!/bin/sh -e
if [[ ! -z ${DB_HOST_LIST} ]]; then
echo "Selecting DB_HOST from ${DB_HOST_LIST}"
echo "DB_HOST=${DB_HOST}"
source ${STI_SCRIPTS_PATH}/run

This comment has been minimized.

Copy link
Owner Author

simbo1905 commented Nov 29, 2018

At they give you two entrypoints to your high availability database cluster such as:

if you hard configure your DB_HOST to one or the other hostname then you have a single point of failure at the portal entry point. You may then need to manually reconfigure to use the surviving portal (aka HAProxy fronting your db as a TCP proxy).

with this snippet executable at .s2i/bin/run you can set DB_HOST_LIST as a comma-separated list like:

docker run -u 100000 -p 8080:8080 --env-file=./.env.staging -e DB_HOST_LIST="," uniqkey-backend-app

and it will log:


selected at random.

Note that if the DB_HOST is still being set as an env var when you login on the terminal you see what is set for the whole environment not how it is has been overridden in the script that launches php. The randomly selected value can be confirmed by looking at the /proc/1/environ (the environment of the process that docker launched):

bash-4.2$ strings /proc/1/environ | grep DB_HOST,

This means that when we set this new code and the new env var DB_HOST_LIST we should delete the old DB_HOST that is ignored else it will cause confusion by being visible in the terminal and web console of openshift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.