1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

fix ES upgrade script for classical docker installations

This commit is contained in:
Sylvain 2018-11-26 16:49:26 +01:00
parent ffbe3e0b4a
commit 770ae9aaef
2 changed files with 21 additions and 8 deletions

View File

@ -80,10 +80,14 @@ This procedure is not easy to follow so if you don't need to write some code for
Your system may provide a pre-packaged version of docker in its repositories, but this version may be outdated.
Please refer to [ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/), [debian](https://docs.docker.com/install/linux/docker-ce/debian/) or [MacOS](https://docs.docker.com/docker-for-mac/install/) documentation to setup a recent version of docker.
5. Add your current user to the docker group and restart.
5. Add your current user to the docker group, to allow using docker without sudo.
This may not be required on some systems, if docker was already installed.
```bash
# add the docker group if it doesn't already exist
sudo groupadd doker
# add the current user to the docker group
sudo usermod -aG docker $(whoami)
# restart to validate changes
sudo reboot
```

View File

@ -334,8 +334,11 @@ upgrade_docker()
local name=$(docker inspect -f '{{.Name}}' "$id" | sed s:^/::g)
# get container network name
local network=$(docker inspect -f '{{.NetworkSettings.Networks}}' "$id" | sed 's/map\[\(.*\):0x[a-f0-9]*\]/\1/')
# get container mapping to data folder
local mounts=$(docker inspect -f '{{.Mounts}}' "$id" | sed 's/} {/\n/g' | sed 's/^\[\?{\?bind[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*true \(rprivate\)\?}\?]\?$/-v \1:\2/g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')
# get container mappings
local volumes=$(docker inspect -f '{{.Mounts}}' "$id" | sed 's/} {/\n/g' | sed 's/^\[\?{\?bind[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*true \(rprivate\)\?}\?]\?$/-v \1:\2/g')
local mounts=$(echo "$volumes" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')
# get mapped ports
local ports=$(docker inspect -f '{{.NetworkSettings.Ports}}' "$id") | sed 's!\([0-9]*\)/tcp:\[{0\.0\.0\.0 \([0-9]*\)}\]!\1:\2!g' | sed 's/^map\[\(.*\)\]/\1/'| sed 's/^map\[\(.*\)\]/\1/' | sed 's/ / -p /' | sed 's/^/-p /'
prepare_upgrade
# stop current elastic
docker stop "$name"
@ -344,12 +347,18 @@ upgrade_docker()
local image="elasticsearch:$target"
local image_name="$image"
if [ $target = '6.2' ]
then
then
image_name="elasticsearch-oss:$target"
image="docker.elastic.co/elasticsearch/$image_name"
elif [ $target = '5.6' ]
then
configdir=$(echo "$volumes" | grep config | awk -F'[ :]' '{print $2}')
echo -e "\nCopying ElasticSearch 2.4 configuration files from $(pwd)/docker to $configdir..."
sudo cp docker/elasticsearch.yml "$configdir"
sudo cp docker/log4j2.properties "$configdir"
fi
docker pull "$image"
echo docker run --restart=always -d --name="$name" --network="$network" --ip="$ES_IP" "$mounts" "$image_name" | bash
echo docker run --restart=always -d --name="$name" --network="$network" --ip="$ES_IP" "$mounts" "$ports" "$image_name" | bash
wait_for_online
wait_for_green_status
# check status
@ -479,7 +488,7 @@ reindex_indices()
local migration_index="$index""_$1"
migration_indices+="$migration_index,"
# create the temporary migration index with the previous mapping
curl -XPUT "http://$ES_IP:9200/$migration_index/" 2>/dev/null -H 'Content-Type: application/json' -d "$definition"
curl -XPUT "http://$ES_IP:9200/$migration_index/" 2>/dev/null -H 'Content-Type: application/json' -d "$definition"
# reindex data content to the new migration index
curl -XPOST "$ES_IP:9200/_reindex?pretty" 2>/dev/null -H 'Content-Type: application/json' -d '{
"source": {
@ -534,7 +543,7 @@ reindex_final_indices()
local final_index=$(echo "$index" | sed "s/\(.*\)_$previous$/\1/")
final_indices+="$final_index,"
# create the final index with the previous mapping
curl -XPUT "http://$ES_IP:9200/$final_index" 2>/dev/null -H 'Content-Type: application/json' -d "$definition"
curl -XPUT "http://$ES_IP:9200/$final_index" 2>/dev/null -H 'Content-Type: application/json' -d "$definition"
# reindex data content to the new migration index
curl -XPOST "$ES_IP:9200/_reindex?pretty" 2>/dev/null -H 'Content-Type: application/json' -d '{
"source": {
@ -548,7 +557,7 @@ reindex_final_indices()
echo "Indices are reindexing. This may take a while, waiting to finish... "
# first we wait for all indices states became green
wait_for_green_status
# then we wait for all documents to be reindexed
# then we wait for all documents to be reindexed
local new_docs=$(curl "$ES_IP:9200/_cat/indices?index=$final_indices" 2>/dev/null | awk '{s+=$7} END {printf "%.0f", s}')
while [ "$new_docs" != "$docs" ]
do