Skip to content

Instantly share code, notes, and snippets.

@BlackFoks
Last active January 26, 2016 10:17
Show Gist options
  • Save BlackFoks/574d24beccdf88e3a530 to your computer and use it in GitHub Desktop.
Save BlackFoks/574d24beccdf88e3a530 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Install a custom ElasticSearch version - https://www.elastic.co/products/elasticsearch
#
# To run this script in Codeship, add the following
# command to your project's test setup command:
# \curl -sSL https://raw.githubusercontent.com/codeship/scripts/master/packages/elasticsearch.sh | bash -s
#
# Add at least the following environment variables to your project configuration
# (otherwise the defaults below will be used).
# * ELASTICSEARCH_VERSION
# * ELASTICSEARCH_PORT
#
ELASTICSEARCH_VERSION="0.90.13"
ELASTICSEARCH_PORT="9200"
ELASTICSEARCH_DIR="$HOME/elasticsearch"
ELASTICSEARCH_WAIT_TIME="30"
echo "ELASTICSEARCH_VERSION = $ELASTICSEARCH_VERSION"
echo "ELASTICSEARCH_PORT = $ELASTICSEARCH_PORT"
echo "ELASTICSEARCH_DIR = $ELASTICSEARCH_DIR"
echo "ELASTICSEARCH_WAIT_TIME = $ELASTICSEARCH_WAIT_TIME"
echo "Stop existing ElasticSearch server (1.2.2)..."
curl -XPOST 'http://localhost:9200/_shutdown'
# The download location of version 2.x seems to follow a different URL structure to 1.x
if [ ${ELASTICSEARCH_VERSION:0:1} -eq 2 ]
then
ELASTICSEARCH_DL_URL="https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/${ELASTICSEARCH_VERSION}/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"
else
ELASTICSEARCH_DL_URL="https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"
fi
set -e
CACHED_DOWNLOAD="${HOME}/cache/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz"
echo "Creating ElasticSearch folder..."
mkdir -p "${ELASTICSEARCH_DIR}"
echo "Downloading ElasticSearch $ELASTICSEARCH_VERSION..."
wget --continue --output-document "${CACHED_DOWNLOAD}" "${ELASTICSEARCH_DL_URL}"
echo "Unpacking downloaded ElasticSearch"
tar -xaf "${CACHED_DOWNLOAD}" --strip-components=1 --directory "${ELASTICSEARCH_DIR}"
echo "http.port: ${ELASTICSEARCH_PORT}" >> ${ELASTICSEARCH_DIR}/config/elasticsearch.yml
# Make sure to use the exact parameters you want for ElasticSearch and give it enough sleep time to properly start up
nohup bash -c "${ELASTICSEARCH_DIR}/bin/elasticsearch 2>&1" &
sleep "${ELASTICSEARCH_WAIT_TIME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment