Skip to content

Instantly share code, notes, and snippets.

@jogaco
Created June 14, 2016 07:26
Show Gist options
  • Save jogaco/2142967ae2c9a9e9cce131cf910516bb to your computer and use it in GitHub Desktop.
Save jogaco/2142967ae2c9a9e9cce131cf910516bb to your computer and use it in GitHub Desktop.
Script to install a rolling upgrade of ElasticSearch, for a single node setup. Checked in ubuntu
#!/bin/bash
display_usage() {
echo "This script must be run with super-user privileges."
echo -e "\nUsage:\n$0 [es-version e.g.: "2.3.3"] \n"
}
# check whether user had supplied -h or --help . If yes display usage
if [[ ( $# == "--help") || $# == "-h" ]]
then
display_usage
exit 0
fi
if [ ! $# -eq 1 ]; then
echo "Error: wrong parameters. Please supply the ES version number to install. E.g. '2.3.3'"
exit 1
else
if [[ $1 =~ ^[0-9](\.[0-9])+$ ]]; then
echo "Will upgrade to ES version $1"
else
echo "$1: invalid version number"
exit 1
fi
fi
# display usage if the script is not run as root user
if [[ $USER != "root" ]]; then
echo "This script must be run as root!"
exit 1
fi
if [ -f elasticsearch-$1.deb ];
then
echo "elasticsearch-$1.deb found"
else
echo "Downloading elasticsearch-$1.deb"
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/$1/elasticsearch-$1.deb
if [ $? -eq 0 ]
then
echo "Downloaded elasticsearch-$1.deb"
else
echo "Could not download elasticsearch-$1.deb" >&2
exit 2
fi
fi
#Stop if anything fails
set -e
cp /etc/elasticsearch/elasticsearch.yml elasticsearch.yml.prev
curl -XPUT 'http://localhost:9200/_cluster/settings' -d'
{
"transient": {
"cluster.routing.allocation.enable": "none"
}
}'
curl -XPOST 'http://localhost:9200/_flush/synced'
service elasticsearch stop
dpkg -i elasticsearch-$1.deb
cd /usr/share/elasticsearch && bin/plugin remove cloud-aws
cd /usr/share/elasticsearch && bin/plugin install cloud-aws
service elasticsearch start
set +e
es_running="0"
for i in $(seq 1 5);
do
sleep 5
curl http://localhost:9200
if [ $? -eq 0 ]; then
es_running="1"
break
fi
done
if [ $es_running -eq "1" ]; then
curl -XPUT 'http://localhost:9200/_cluster/settings?pretty' -d'
{
"transient": {
"cluster.routing.allocation.enable": "all"
}
}'
if [ $? -eq 0 ]; then
echo "cluster.routing.allocation.enable set to all OK"
else
echo "Could not set cluster.routing.allocation.enable. Check logs"
fi
else
echo "Error: could not start elasticsearch service. Check logs"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment