Skip to content

Instantly share code, notes, and snippets.

@flat235
Created March 19, 2019 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flat235/fc9ed2fb554620aa2cc793a95ec0a286 to your computer and use it in GitHub Desktop.
Save flat235/fc9ed2fb554620aa2cc793a95ec0a286 to your computer and use it in GitHub Desktop.
rolling upgrade of elasticsearch (debian edition)
#!/bin/bash
# written according to
# https://www.elastic.co/guide/en/elasticsearch/reference/5.6/rolling-upgrades.html
# NO PLUGIN SUPPORT
# Dependencies
# - curl
# - jq
ELASTIC_HOST="${ELASTIC_HOST:-localhost}"
ELASTIC_PORT="${ELASTIC_PORT:-9200}"
echo "disabling shard allocation"
curl -s -X PUT "${ELASTIC_HOST}:${ELASTIC_PORT}/_cluster/settings" -H 'Content-Type: application/json' -d'
{
"transient": {
"cluster.routing.allocation.enable": "none"
}
}
' | jq '.'
echo "stopping indexing and synced flush"
curl -s -X POST "${ELASTIC_HOST}:${ELASTIC_PORT}/_flush/synced" | jq '.'
# upgrade
systemctl stop elasticsearch
apt-get -y upgrade elasticsearch
systemctl daemon-reload
systemctl start elasticsearch
echo "waiting for node to come up"
until curl -s -X GET "${ELASTIC_HOST}:${ELASTIC_PORT}/_cat/nodes" | grep $(hostname); do
echo -n "."
sleep 1
done
echo "reenabling shard allocation"
curl -s -X PUT "${ELASTIC_HOST}:${ELASTIC_PORT}/_cluster/settings" -H 'Content-Type: application/json' -d'
{
"transient": {
"cluster.routing.allocation.enable": "all"
}
}
' | jq '.'
echo "waiting for cluster status to become green again"
until curl -s -X GET "${ELASTIC_HOST}:${ELASTIC_PORT}/_cat/health" | grep green; do
echo -n "."
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment