Skip to content

Instantly share code, notes, and snippets.

@jtadeulopes
Last active November 24, 2019 06:54
Show Gist options
  • Save jtadeulopes/ae1f1ffe53000012b27b1112aecaa4b7 to your computer and use it in GitHub Desktop.
Save jtadeulopes/ae1f1ffe53000012b27b1112aecaa4b7 to your computer and use it in GitHub Desktop.
A script for installing ES on SemaphoreCI
#! /usr/bin/env bash
## Usage:
## wget https://gist.githubusercontent.com/jtadeulopes/ae1f1ffe53000012b27b1112aecaa4b7/raw/45f792729d8b26e42f07028d0693e4de51024383/es-semaphore.sh && bash es-semaphore.sh <es-version>
##
ES_HOST="0.0.0.0"
ES_PORT="9200"
ES_VERSION=${1:-'5.0.0'}
DEB='elasticsearch-'"$ES_VERSION"'.deb'
# URL="https://artifacts.elastic.co/downloads/elasticsearch/$DEB"
URL="https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/${ES_VERSION}/elasticsearch-${ES_VERSION}.tar.gz"
function stall_for_elasticsearch() {
echo ">> Waiting for ElasticSearch to become available"
while true; do
printf "."
nc -4 -w 5 $ES_HOST $ES_PORT 2>/dev/null && break
sleep 1
done
printf "\n"
}
function setup_java() {
source /opt/change-java-version.sh
change-java-version 8
}
function remove_installed_version() {
sudo service elasticsearch stop
sudo apt-get purge -y elasticsearch
sudo rm -rf /var/lib/elasticsearch
}
function install_new_version() {
if ! [ -e $SEMAPHORE_CACHE_DIR/$DEB ]; then (cd $SEMAPHORE_CACHE_DIR; wget $URL); fi
echo ">> Installing ElasticSearch $ES_VERSION"
echo 'Y' | sudo dpkg -i $SEMAPHORE_CACHE_DIR/$DEB
sudo service elasticsearch start
echo ">> Installation completed"
}
function run_health_check() {
echo ">> Running health check..."
curl http://"$ES_HOST":"$ES_PORT"/_cluster/health?pretty=true
}
setup_java
remove_installed_version
install_new_version
stall_for_elasticsearch
run_health_check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment