chg: [startup] Wait until redis is ready before starting the zmqs

scripts
pull/121/head
mokaddem 2019-08-30 11:39:14 +02:00
parent 19842f9445
commit 3e218cd145
2 changed files with 27 additions and 10 deletions

View File

@ -6,6 +6,29 @@ GREEN="\\033[1;32m"
DEFAULT="\\033[0;39m" DEFAULT="\\033[0;39m"
RED="\\033[1;31m" 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 # Getting CWD where bash script resides
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DASH_HOME="${DIR}" DASH_HOME="${DIR}"
@ -61,6 +84,8 @@ else
fi fi
sleep 0.1 sleep 0.1
wait_until_redis_is_ready;
if [ "${check_dashboard_port}" == "1" ]; then if [ "${check_dashboard_port}" == "1" ]; then
echo -e $GREEN"\t* Launching flask server"$DEFAULT echo -e $GREEN"\t* Launching flask server"$DEFAULT
${ENV_PY} ./server.py & ${ENV_PY} ./server.py &

View File

@ -20,19 +20,11 @@ else
exit 1 exit 1
fi fi
PID_SCREEN=$(screen -ls | grep ${SCREEN_NAME} | cut -f2 | cut -d. -f1) PID_SCREEN=$(screen -ls | grep ${SCREEN_NAME} | cut -f2 | cut -d. -f1)
if [[ $PID_SCREEN ]]; then if [[ $PID_SCREEN ]]; then
echo -e $RED"* A screen '$SCREEN_NAME' is already launched"$DEFAULT echo -e $RED"* A screen '$SCREEN_NAME' is already launched"$DEFAULT
echo "Would you like to restart it (y/n)? " echo -e $GREEN"Killing $PID_SCREEN"$DEFAULT;
read answer kill $PID_SCREEN
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo -e $GREEN"Killing $PID_SCREEN"$DEFAULT;
kill $PID_SCREEN
else
echo 'Exiting'
exit 0;
fi
else else
echo 'No screen detected' echo 'No screen detected'
fi fi