From 04881c4089c6f9fcb96c31170b41eead0efb82b2 Mon Sep 17 00:00:00 2001 From: Anthony Bretaudeau Date: Thu, 1 Feb 2024 10:38:42 +0100 Subject: [PATCH] rework daemon waiting --- tools/genenotebook/launch_gnb.sh | 46 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tools/genenotebook/launch_gnb.sh b/tools/genenotebook/launch_gnb.sh index c45f9cc..4c1ad3d 100755 --- a/tools/genenotebook/launch_gnb.sh +++ b/tools/genenotebook/launch_gnb.sh @@ -2,17 +2,26 @@ set -e -mongod --dbpath ./mongo_db/ --unixSocketPrefix `pwd` --bind_ip fake_socket --logpath ./mongod.log --pidfilepath ./mongo.pid & +echo "Running mongod: " +mongod --dbpath ./mongo_db/ --unixSocketPrefix "$(pwd)" --bind_ip fake_socket --logpath ./mongod.log --pidfilepath ./mongo.pid & -sleep 15 +echo "Waiting while mongod starts up" + +tries=0 # "Listening on" is for mongodb 5x -if ! grep -q "Listening on" ./mongod.log; then - echo "Failed to launch MongoDB:" 1>&2; - cat ./mongod.log 1>&2; - kill $GNB_PID; - exit 1; -fi; +while ! grep -q "Listening on" ./mongod.log; do + + tries=$((tries + 1)) + + if [ "$tries" -ge 30 ]; then + echo "Failed to launch MongoDB:" 1>&2; + cat ./mongod.log 1>&2; + exit 1; + fi + + sleep 3 +done; TMP_STORAGE=$(pwd)/tmp_storage mkdir "$TMP_STORAGE" @@ -23,11 +32,18 @@ genoboo run --storage-path "$TMP_STORAGE" --port ${GNB_PORT} --mongo-url mongodb export GNB_PID=$! -sleep 15 +tries_gnb=0 + +while ! grep -q "GeneNoteBook server started, serving" ./gnb.log; do + + tries_gnb=$((tries_gnb + 1)) + + if [ "$tries_gnb" -ge 30 ]; then + echo "Failed to launch GeneNoteBook:" 1>&2; + cat ./gnb.log 1>&2; + kill $GNB_PID $(<"./mongo.pid"); + exit 1; + fi -if ! grep -q "GeneNoteBook server started, serving" ./gnb.log; then - echo "Failed to launch GeneNoteBook:" 1>&2; - cat ./gnb.log 1>&2; - kill $GNB_PID $(<"./mongo.pid"); - exit 1; -fi; + sleep 3 +done;