From a1b4f3d0a7296f02aeb395abbe610eb426babb1f Mon Sep 17 00:00:00 2001 From: Ricardo Lima Canela Date: Wed, 17 Apr 2019 14:24:50 -0300 Subject: [PATCH] verifica quatro vezes se solr esta online (#2732) --- Dockerfile | 1 + check_solr.sh | 13 ++++++++++--- start.sh | 14 +++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 015357a40..9c33fcd0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,6 +39,7 @@ RUN rm -rf /var/interlegis/sapl/sapl/.env && \ rm -rf /var/interlegis/sapl/sapl.db RUN chmod +x /var/interlegis/sapl/start.sh && \ + chmod +x /var/interlegis/sapl/check_solr.sh && \ ln -sf /dev/stdout /var/log/nginx/access.log && \ ln -sf /dev/stderr /var/log/nginx/error.log && \ mkdir /var/log/sapl/ && touch /var/interlegis/sapl/sapl.log && \ diff --git a/check_solr.sh b/check_solr.sh index b3c4760c4..c600466bb 100644 --- a/check_solr.sh +++ b/check_solr.sh @@ -4,15 +4,22 @@ SOLR_URL=$1 +RETRY_COUNT=1 +RETRY_LIMIT=4 + echo "Waiting for solr connection at $SOLR_URL ..." -while true; do +while [[ $RETRY_COUNT < $RETRY_LIMIT ]]; do + echo "Attempt to connect to solr: $RETRY_COUNT of $RETRY_LIMIT" + let RETRY_COUNT=RETRY_COUNT+1; echo "$SOLR_URL/solr/admin/collections?action=LIST" RESULT=$(curl -s -o /dev/null -I "$SOLR_URL/solr/admin/collections?action=LIST" -w '%{http_code}') echo $RESULT - if [ "$RESULT" -eq '200' ]; then + if [ $RESULT == 200 ]; then echo "Solr server is up!" - break + exit 1 else sleep 3 fi done +echo "Solr connection failed." +exit 2 \ No newline at end of file diff --git a/start.sh b/start.sh index 3afa0176c..750852431 100755 --- a/start.sh +++ b/start.sh @@ -71,11 +71,19 @@ if [ "${USE_SOLR-False}" == "True" ] || [ "${USE_SOLR-False}" == "true" ]; then echo "REPLICATION FACTOR: $RF" echo "MAX SHARDS PER NODE: $MAX_SHARDS_PER_NODE" echo "=========================================" - + + echo "running solr script" /bin/bash check_solr.sh $SOLR_URL + CHECK_SOLR_RETURN=$? + + if [ $CHECK_SOLR_RETURN == 1 ]; then + echo "Connecting to solr..." + python3 solr_api.py -u $SOLR_URL -c $SOLR_COLLECTION -s $NUM_SHARDS -rf $RF -ms $MAX_SHARDS_PER_NODE & + # python3 manage.py rebuild_index --noinput & + else + echo "Solr is offline, not possible to connect." + fi - python3 solr_api.py -u $SOLR_URL -c $SOLR_COLLECTION -s $NUM_SHARDS -rf $RF -ms $MAX_SHARDS_PER_NODE & - # python3 manage.py rebuild_index --noinput & else echo "Suporte a SOLR não inicializado." fi