Created
March 19, 2019 18:54
-
-
Save flat235/fc9ed2fb554620aa2cc793a95ec0a286 to your computer and use it in GitHub Desktop.
rolling upgrade of elasticsearch (debian edition)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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