diff --git a/.travis.yml b/.travis.yml index 6de58c103..041317ddc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ addons: secure: "PfhLGBKRgNqhKuYCJsK+VPhdAzcgWFGeeOyxC/eS8gtlvIISVdgyZE+r30uIei0DFI6zEiN62eW4d+xtT4j7/e2ZcAcx7U52mza/SnQNuu3nCGQDJB8VOvV5NbnwXfi8vfr4e889Mt7k3ocd2c4gqB4UtRqrzhygj7HN+B/GfEk=" env: matrix: - # - ELASTIC_SEARCH_VERSION="7.5.1-amd64" COVERAGE=true RAILS_ENV=test # Future target (production needs upgrading) + - ELASTIC_SEARCH_VERSION="7.5.1-amd64" COVERAGE=true RAILS_ENV=test # Future target (production needs upgrading) # - ELASTIC_SEARCH_VERSION="6.7.1" COVERAGE=true RAILS_ENV=test # last 6.x release - ELASTIC_SEARCH_VERSION="6.2.3" COVERAGE=true RAILS_ENV=test # matches productions - STATIC_CHECKS=true @@ -32,9 +32,10 @@ before_install: - sudo apt clean - sudo apt update - sudo apt install dpkg + - ./script/install_elasticsearch.sh - sudo apt install google-chrome-stable - ./script/install_linters.sh - - ./script/install_elasticsearch.sh + - ./script/check_elasticsearch.sh script: - > if [ "${STATIC_CHECKS}" = "true" ]; then diff --git a/script/check_elasticsearch.sh b/script/check_elasticsearch.sh new file mode 100755 index 000000000..5f1c45a50 --- /dev/null +++ b/script/check_elasticsearch.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +if [[ -z "$ELASTIC_SEARCH_VERSION" ]]; then + echo "ELASTIC_SEARCH_VERSION variable not set" +else + host="localhost:9200" + response="" + attempt=0 + maxattempts=25 + + # this would wait forever + # until curl --silent -XGET --fail ${host} do printf '.'; sleep 1; done + + until [ "$response" = "200" ]; do + if [ $attempt -ge ${maxattempts} ]; then + echo "FAILED. Elasticsearch not responding after $attempt tries." + sudo tail /var/log/elasticsearch/*.log + exit 1 + fi + echo "Contacting Elasticsearch on ${host}. Try number ${attempt}" + response=$(curl --write-out %{http_code} --silent --output /dev/null $host) + + sleep 1 + attempt=$((attempt+1)) + done + + echo "SUCCESS. Elasticsearch is responding." +fi diff --git a/script/install_elasticsearch.sh b/script/install_elasticsearch.sh index ba533782e..d040e241a 100755 --- a/script/install_elasticsearch.sh +++ b/script/install_elasticsearch.sh @@ -12,33 +12,19 @@ else shasum -a 512 -c "elasticsearch-${ELASTIC_SEARCH_VERSION}.deb.sha512" + echo "Installing Elasticsearch ${ELASTIC_SEARCH_VERSION}" sudo dpkg -i --force-confnew "elasticsearch-${ELASTIC_SEARCH_VERSION}.deb" + if [[ $ELASTIC_SEARCH_VERSION == 7\.* ]]; then + # https://stackoverflow.com/questions/55951531/running-elasticsearch-7-0-on-a-travis-xenial-build-host + sudo sed -i.old 's/-Xms1g/-Xms128m/' /etc/elasticsearch/jvm.options + sudo sed -i.old 's/-Xmx1g/-Xmx128m/' /etc/elasticsearch/jvm.options + echo -e '-XX:+DisableExplicitGC\n-Djdk.io.permissionsUseCanonicalPath=true\n-Dlog4j.skipJansi=true\n-server\n' | sudo tee -a /etc/elasticsearch/jvm.options + sudo chown -R elasticsearch:elasticsearch /etc/default/elasticsearch + fi + echo "Starting Elasticsearch ${ELASTIC_SEARCH_VERSION}" # sudo service elasticsearch start sudo systemctl start elasticsearch - - host="localhost:9200" - response="" - attempt=0 - maxattempts=25 - - # this would wait forever - # until curl --silent -XGET --fail ${host} do printf '.'; sleep 1; done - - until [ "$response" = "200" ]; do - if [ $attempt -ge ${maxattempts} ]; then - echo "FAILED. Elasticsearch not responding after $attempt tries." - sudo tail /var/log/elasticsearch/*.log - exit 1 - fi - echo "Contacting Elasticsearch on ${host}. Try number ${attempt}" - response=$(curl --write-out %{http_code} --silent --output /dev/null $host) - - sleep 1 - attempt=$((attempt+1)) - done fi - -echo "SUCCESS. Elasticsearch is responding."