From 3e218cd14512bcb7ca30d970af62c2b8c5589600 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Fri, 30 Aug 2019 11:39:14 +0200 Subject: [PATCH] chg: [startup] Wait until redis is ready before starting the zmqs scripts --- start_all.sh | 25 +++++++++++++++++++++++++ start_zmq.sh | 12 ++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/start_all.sh b/start_all.sh index a9b7c89..5895794 100755 --- a/start_all.sh +++ b/start_all.sh @@ -6,6 +6,29 @@ GREEN="\\033[1;32m" DEFAULT="\\033[0;39m" RED="\\033[1;31m" +function wait_until_redis_is_ready { + redis_not_ready=true + while $redis_not_ready; do + if checking_redis; then + redis_not_ready=false; + else + sleep 1 + fi + done + echo -e $GREEN"* Redis 6250 is running"$DEFAULT +} + +function checking_redis { + flag_redis=0 + bash -c 'redis-cli -p 6250 PING | grep "PONG" &> /dev/null' + if [ ! $? == 0 ]; then + echo -e $RED"Redis 6250 not ready"$DEFAULT + flag_redis=1 + fi + sleep 0.1 + return $flag_redis; +} + # Getting CWD where bash script resides DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DASH_HOME="${DIR}" @@ -61,6 +84,8 @@ else fi sleep 0.1 +wait_until_redis_is_ready; + if [ "${check_dashboard_port}" == "1" ]; then echo -e $GREEN"\t* Launching flask server"$DEFAULT ${ENV_PY} ./server.py & diff --git a/start_zmq.sh b/start_zmq.sh index dec1b76..f64b539 100755 --- a/start_zmq.sh +++ b/start_zmq.sh @@ -20,19 +20,11 @@ else exit 1 fi - PID_SCREEN=$(screen -ls | grep ${SCREEN_NAME} | cut -f2 | cut -d. -f1) if [[ $PID_SCREEN ]]; then echo -e $RED"* A screen '$SCREEN_NAME' is already launched"$DEFAULT - echo "Would you like to restart it (y/n)? " - read answer - if [ "$answer" != "${answer#[Yy]}" ] ;then - echo -e $GREEN"Killing $PID_SCREEN"$DEFAULT; - kill $PID_SCREEN - else - echo 'Exiting' - exit 0; - fi + echo -e $GREEN"Killing $PID_SCREEN"$DEFAULT; + kill $PID_SCREEN else echo 'No screen detected' fi