From c10d35a7d86334020359df432220eedc63136b94 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 29 Nov 2018 16:35:45 +0100 Subject: [PATCH 1/3] fix and improvements in ES upgrade script --- CHANGELOG.md | 4 ++ doc/elastic_upgrade.md | 91 +++++++++++++++++++++++++++++++++++++- docker/elasticsearch.yml | 3 +- scripts/elastic-upgrade.sh | 18 +++++++- 4 files changed, 112 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2386f8e0..730587fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog Fab Manager +- Allow running the ElasticSearch upgrade script while being root +- Fix an issue with ES upgrade script, preventing reindexing in some cases +- Improved ES upgrade documentation + # v2.7.1 2018 November 27 - Updated angular.js to 1.6 diff --git a/doc/elastic_upgrade.md b/doc/elastic_upgrade.md index a4cc4517d..79a9ed901 100644 --- a/doc/elastic_upgrade.md +++ b/doc/elastic_upgrade.md @@ -1,5 +1,7 @@ # Instructions for upgrading ElasticSearch +## Automatic upgrade + Fab-manager release 2.6.5 has upgraded its dependency to ElasticSearch from version 1.7 to version 5.6 as the previous was unsupported for months. To keep using fab-manager you need to upgrade your installation with the new version. We've wrote a script to automate the process while keeping your data integrity, but there's some requirements to understand before running it. @@ -22,6 +24,93 @@ cd /apps/fabmanager \curl https://raw.githubusercontent.com/LaCasemate/fab-manager/master/scripts/elastic-upgrade.sh | bash ``` +## Manual upgrade + For instructions regarding a manual upgrade, please refer to the official documentation: + - https://www.elastic.co/guide/en/elasticsearch/reference/2.4/restart-upgrade.html -- https://www.elastic.co/guide/en/elasticsearch/reference/5.6/restart-upgrade.html \ No newline at end of file +- https://www.elastic.co/guide/en/elasticsearch/reference/5.6/restart-upgrade.html + +## Revert the upgrade + +So something goes wrong and the upgrade was not successful. +Sad news, but everything isn't lost, follow this procedure to downgrade to ElasticSearch 1.7. + +First, check the status of your indices: + +```bash +# Replace fabmanager_elasticsearch_1 in the next command with your container's name. +# You can get it running `docker ps` +ES_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' fabmanager_elasticsearch_1) +curl "$ES_IP:9200/_cat/indices?v" +``` + +You should get something like this: +``` +health status index pri rep docs.count docs.deleted store.size pri.store.size +green open fablab_24 1 0 1944 0 1mb 1mb +green open stats_24 1 0 0 0 2.8mb 104b +green open stats 5 0 13515 0 2.7mb 2.7mb +green open fablab 5 0 1944 4 1.2mb 1.2mb +``` + +Here, we can see that the migration is not complete, as *docs.count* are not equal for `stat_24` and `stats`. + + +Now let's stop and remove the ElasticSearch container. + +```bash +docker-compose stop elasticsearch +docker-compose rm -f elasticsearch +docker-compose down +``` + +Then, edit your [docker-compose.yml](../docker/docker-compose.yml) and change the *elasticsearch* block according to the following: + + + + + +
+
+  elasticsearch:
+    image: elasticsearch:2.4
+    ulimits:
+      memlock:
+        soft: -1
+        hard: -1
+    environment:
+      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
+    volumes:
+      - ${PWD}/elasticsearch/config:/usr/share/elasticsearch/config
+      - ${PWD}/elasticsearch:/usr/share/elasticsearch/data
+    restart: always
+
+
+=> + +
+  elasticsearch:
+    image: elasticsearch:1.7
+    volumes:
+      - ${PWD}/elasticsearch:/usr/share/elasticsearch/data
+    restart: always
+
+
+ +Restart your containers: + +```bash +docker-compose pull +docker-compose up -d +``` + +Now you're back with ElasticSearch 1.7. You can safely restart the upgrade script. + +## Debugging the upgrade + +You can check for any error during container startup, using: + +```bash +docker-compose logs elasticsearch +``` diff --git a/docker/elasticsearch.yml b/docker/elasticsearch.yml index 40d2ada9d..daed6f231 100644 --- a/docker/elasticsearch.yml +++ b/docker/elasticsearch.yml @@ -1,6 +1,5 @@ http.host: 0.0.0.0 script.inline: true -script.stored: true -script.painless.regex.enabled: true +script.engine.groovy.inline.update: true path.repo: /usr/share/elasticsearch diff --git a/scripts/elastic-upgrade.sh b/scripts/elastic-upgrade.sh index 5d67aa5fa..44933d0b2 100755 --- a/scripts/elastic-upgrade.sh +++ b/scripts/elastic-upgrade.sh @@ -308,6 +308,19 @@ upgrade_compose() then sed -i.bak "/image: $image/s/.*/&\n ulimits:\n memlock:\n soft: -1\n hard: -1/" "$FM_PATH/docker-compose.yml" fi + if [ $target = '2.4' ] + then + # get current data directory + dir=$(awk 'BEGIN { FS="\n"; RS="";} { match($0, /image: elasticsearch:2\.4(\n|.)+volumes:(\n|.)+(-.*elasticsearch\/data)/, lines); FS="[ :]+"; RS="\r\n"; split(lines[3], line); print line[2] }' "$FM_PATH/docker-compose.yml") + # set the configuration directory + dir=$(echo "${dir//[$'\t\r\n ']}/config") + # insert configuration directory into docker-compose bindings + awk "BEGIN { FS=\"\n\"; RS=\"\";} { print gensub(/(image: elasticsearch:2\.4(\n|.)+)volumes:\n/, \"\\1volumes:\n - ${dir}:/usr/share/elasticsearch/config\n\", \"g\") }" "$FM_PATH/docker-compose.yml" > "$FM_PATH/.awktmpfile" && mv "$FM_PATH/.awktmpfile" "$FM_PATH/docker-compose.yml" + echo -e "\nCopying ElasticSearch 2.4 configuration files from $(pwd)/docker to $dir..." + mkdir -p "$dir" + curl -sSL https://raw.githubusercontent.com/LaCasemate/fab-manager/master/docker/elasticsearch.yml > "$dir/elasticsearch.yml" + curl -sSL https://raw.githubusercontent.com/LaCasemate/fab-manager/master/docker/log4j2.properties > "$dir/log4j2.properties" + fi docker-compose pull docker-compose up -d wait_for_online @@ -351,7 +364,7 @@ upgrade_docker() then image_name="elasticsearch-oss:$target" image="docker.elastic.co/elasticsearch/$image_name" - elif [ $target = '5.6' ] + elif [ $target = '2.4' ] then configdir=$(echo "$volumes" | grep config | awk -F'[ :]' '{print $2}') echo -e "\nCopying ElasticSearch 2.4 configuration files from $(pwd)/docker to $configdir..." @@ -497,6 +510,9 @@ reindex_indices() }, "dest": { "index": "'"$migration_index"'" + }, + "script": { + "inline": "ctx._source.remove('"'"'_id'"'"')" } }' done From 8b874411e15234c49a9a57374b0d45943d66a90d Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 29 Nov 2018 16:53:58 +0100 Subject: [PATCH 2/3] instructions to skip ES upgrade --- doc/elastic_upgrade.md | 40 ++++++++++++++++++++++++++++++++++++++++ lib/tasks/fablab.rake | 6 +++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/doc/elastic_upgrade.md b/doc/elastic_upgrade.md index 79a9ed901..1d130befe 100644 --- a/doc/elastic_upgrade.md +++ b/doc/elastic_upgrade.md @@ -114,3 +114,43 @@ You can check for any error during container startup, using: ```bash docker-compose logs elasticsearch ``` + +## Skip the upgrade + +The upgrade is not working and you can't debug it? +You can skip it by deleting your ES database, installing ES 5.6 and resynchronizing ES from your PostgreSQL database. + +**This is not recommended on old installations as this can lead to data losses.** + +Here's the procedure: + +```bash +curl -XDELETE "$ES_IP:9200/fablab" +curl -XDELETE "$ES_IP:9200/stats" +# delete any other index, if applicable +``` +Stop and remove your container, then edit your [docker-compose.yml](../docker/docker-compose.yml) and set the following: + +```yml + elasticsearch: + image: elasticsearch:5.6 + ulimits: + memlock: + soft: -1 + hard: -1 + environment: + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + volumes: + - ${PWD}/elasticsearch/config:/usr/share/elasticsearch/config + - ${PWD}/elasticsearch:/usr/share/elasticsearch/data + restart: always +``` + +Copy [elasticsearch.yml](../docker/elasticsearch.yml) and [log4j2.properties](../docker/log4j2.properties) to `elasticsearch/config`, then pull and restart your containers. + +Finally reindex your data: +```bash +rake fablab:es_build_stats +rake fablab:generate_stats[3000] +rake fablab:es_build_projects_index +``` diff --git a/lib/tasks/fablab.rake b/lib/tasks/fablab.rake index 4f4873f97..34ea66b98 100644 --- a/lib/tasks/fablab.rake +++ b/lib/tasks/fablab.rake @@ -43,10 +43,10 @@ namespace :fablab do desc '(re)Build ElasticSearch fablab base for stats' task es_build_stats: :environment do - puts "DELETE stats" + puts 'DELETE stats' `curl -XDELETE http://#{ENV["ELASTICSEARCH_HOST"]}:9200/stats` - puts "PUT index stats" + puts 'PUT index stats' `curl -XPUT http://#{ENV["ELASTICSEARCH_HOST"]}:9200/stats -d' { "settings" : { @@ -60,7 +60,7 @@ namespace :fablab do %w[account event machine project subscription training user space].each do |stat| puts "PUT Mapping stats/#{stat}" - `curl -XPUT http://#{ENV["ELASTICSEARCH_HOST"]}:9200/stats/#{stat}/_mapping -d ' + `curl -XPUT http://#{ENV["ELASTICSEARCH_HOST"]}:9200/stats/#{stat}/_mapping -d ' { "properties": { "type": { From bfa51cb633bddcdb776178f294d80baf2e40552f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 29 Nov 2018 16:56:16 +0100 Subject: [PATCH 3/3] Version 2.7.2 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 730587fad..e0957e647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab Manager +# v2.7.2 2018 November 29 + - Allow running the ElasticSearch upgrade script while being root - Fix an issue with ES upgrade script, preventing reindexing in some cases - Improved ES upgrade documentation diff --git a/package.json b/package.json index 5166f24c5..6b76395fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fab-manager", - "version": "2.7.1", + "version": "2.7.2", "description": "FabManager is the FabLab management solution. It is web-based, open-source and totally free.", "keywords": [ "fablab",