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/docker-compose.yml b/docker-compose.yml index e2dfb6824..5fe0b554b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ sapldb: - "5432:5432" sapl: image: interlegis/sapl:3.1.153 +# build: . restart: always environment: ADMIN_PASSWORD: interlegis @@ -23,11 +24,27 @@ sapl: EMAIL_HOST_USER: usuariosmtp EMAIL_SEND_USER: usuariosmtp EMAIL_HOST_PASSWORD: senhasmtp +# USE_SOLR: 'True' +# SOLR_COLLECTION: sapl +# SOLR_URL: http://saplsolr:8983 TZ: America/Sao_Paulo volumes: - sapl_data:/var/interlegis/sapl/data - sapl_media:/var/interlegis/sapl/media links: - sapldb +# - saplsolr ports: - "80:80" + +#saplsolr: +# image: solr:7.4-alpine +# restart: always +# command: bin/solr start -c -f +# volumes: +# - solr_data:/opt/solr/server/solr +# - solr_configsets:/opt/solr/server/solr/configsets +# ports: +# - "8983:8983" + + diff --git a/start.sh b/start.sh index 0790c2c24..bea1eb959 100755 --- a/start.sh +++ b/start.sh @@ -70,11 +70,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