Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check redis connection before boot #10472

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/web-and-data/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ RUN apt-get update; apt-get install -y --no-install-recommends \
build-essential \
default-mysql-client \
default-libmysqlclient-dev \
redis-tools \
python3 \
python3-setuptools \
python3-dev \
python3-pip \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install wheel

ENV PORTAL_WEB_HOME=/cbioportal-webapp
Expand Down
74 changes: 74 additions & 0 deletions docker/web-and-data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,73 @@ migrate_db() {
fi
}

parse_redis_params_from_config_and_command_line() {
if [[ -f $CUSTOM_PROPERTIES_FILE ]]; then
PROPERTIES_FILE=$CUSTOM_PROPERTIES_FILE
else
PROPERTIES_FILE=$BAKED_IN_WAR_CONFIG_FILE
fi
for param in redis.leader_address redis.follower_address persistence.cache_type redis.database redis.password; do
if $(parse_db_params_from_command_line $@ | grep -q $param); then
prop=$(parse_db_params_from_command_line $@ | grep "^$param" || [[ $? == 1 ]])
else
prop=$(grep -v '^#' $PROPERTIES_FILE | grep "^$param" || [[ $? == 1 ]])
fi
if [[ -n "$prop" ]]
then
# Replace dot in parameter name with underscore.
prop=$(sed "s/^db\./db_/" <<< $prop)
echo $prop
fi
done
}

check_redis_connections() {
eval $(parse_redis_params_from_config_and_command_line $@)

# check if persistence.cache_type is redis
if [[ -n $persistence_cache_type ]] && [[ $persistence_cache_type == "redis" ]]; then
# check if redis.leader_address is set
if [[ -n $redis_leader_address ]]; then
# check if redis.follower_address is set
if [[ -n $redis_follower_address ]]; then
# check if redis.database is set
if [[ -n $redis_database ]]; then
# check if redis.password is set
if [[ -n $redis_password ]]; then
# check if redis.leader_address is reachable
while ! redis-cli -u ${redis_leader_address} -a $redis_password PING;
do
sleep 5s;
echo "Redis leader address not reachable (yet?)"
done
echo "Redis leader connection success"
# check if redis.follower_address is reachable
while ! redis-cli -u ${redis_leader_address} -a $redis_password PING;
do
sleep 5s;
echo "Redis follower address not reachable (yet?)"
done
echo "Redis follower connection success"
else
echo "Redis password not set"
exit 1
fi
else
echo "Redis database not set"
exit 1
fi
else
echo "Redis follower address not set"
exit 1
fi
else
echo "Redis leader address not set"
exit 1
fi
fi
}

_main() {
# when running the webapp, check db and do migration first
# check if command is something like "java -jar webapp-runner.jar"
Expand All @@ -120,6 +187,13 @@ _main() {
check_db_connection $@
migrate_db $@

if [ -n "$SHOW_DEBUG_INFO" ] && [ "$SHOW_DEBUG_INFO" != "false" ]; then
echo "Using redis config:"
parse_redis_params_from_config_and_command_line $@
fi

check_redis_connections $@

if [ -n "$SHOW_DEBUG_INFO" ] && [ "$SHOW_DEBUG_INFO" != "false" ]; then
echo Running: "$@"
fi
Expand Down
Loading