Skip to content

Instantly share code, notes, and snippets.

@aliostad
Created August 25, 2017 09:15
Show Gist options
  • Save aliostad/76aaa79864838b2c4092bf74370b345e to your computer and use it in GitHub Desktop.
Save aliostad/76aaa79864838b2c4092bf74370b345e to your computer and use it in GitHub Desktop.
Rolling upgrade for Elasticsearch and Kibana
esversion="5.5.2"
kibversion="5.5.2"
username=<specify>
password=<specify>
nodecount=4 #change
oldesv=$(dpkg -s elasticsearch 2>/dev/null | grep Version | cut -f2 -d' ')
oldkibv=$(dpkg -s kibana 2>/dev/null | grep Version | cut -f2 -d' ')
if [[ -z $(apt-key list | grep "Elasticsearch Signing Key") ]]; then
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -
fi
if [[ -z $(sudo apt list 2>/dev/null | grep apt-transport-https) ]]; then
sudo apt-get update && sudo apt-get install apt-transport-https
fi
if [[ ! -f /etc/apt/sources.list.d/elastic-5.x.list ]]; then
echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
fi
upgrade_elastic(){
if [ $esversion != $oldesv ]; then
#disable allocation
curl -d '{"transient": {"cluster.routing.allocation.enable": "none"}}' \
-u $username:$password -k -X PUT https://localhost:9200/_cluster/settings
sudo apt-get update
sudo service elasticsearch stop
sudo apt-get -y install elasticsearch=$esversion
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin remove x-pack
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin remove repository-azure
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install repository-azure
sudo service elasticsearch start
while [[ $(curl -u $username:$password -k -s https://localhost:9200/_cat/nodes | wc -l) != $nodecount ]]; do
sleep 2
echo "Waiting for the sun..."
done
# flush
curl -u $username:$password -k -X POST -d '' https://localhost:9200/_flush/synced
# enable allocation
curl -d '{"transient": {"cluster.routing.allocation.enable": "all"}}' \
-u $username:$password -k -X PUT https://localhost:9200/_cluster/settings
fi
}
upgrade_kibana(){
if [ $kibversion != $oldkibv ]; then
sudo apt-get update
sudo service kibana stop
sudo apt-get -y install kibana=$kibversion
sudo /usr/share/kibana/bin/kibana-plugin remove x-pack
sudo /usr/share/kibana/bin/kibana-plugin install x-pack
sudo service kibana start
fi
}
upgrade_elastic
if [ ! -z $oldkibv ]; then
upgrade_kibana
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment