diff --git a/docker/README.md b/docker/README.md index 708407b27..71f1e6d6e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -53,7 +53,7 @@ Choose one, depending on your budget, on the server's location, on the uptime gu You will need at least 2GB of addressable memory (RAM + swap) to install and use FabManager. We recommend 4 GB RAM for larger communities. -On DigitalOcean, create a Droplet with One-click apps **"Docker on Ubuntu 16.04 LTS"**. +On DigitalOcean, create a Droplet with One-click apps **"Docker on Ubuntu 16.04 LTS"**. This way, Docker and Docker-compose are preinstalled. Choose a datacenter and set the hostname as your domain name. diff --git a/scripts/elastic-upgrade.sh b/scripts/elastic-upgrade.sh new file mode 100644 index 000000000..f11c486a7 --- /dev/null +++ b/scripts/elastic-upgrade.sh @@ -0,0 +1,173 @@ +#!/usr/bin/env bash + +# 3 options: +# - docker compose +# - docker "simple" +# - classic installation +# > macOS +# > ubuntu +# > debian + + +config() +{ + FM_PATH=$(pwd) + read -rp "Is fab-manager installed at \"$FM_PATH\"? (y/n)" confirm /dev/null | head -n 1 | cut -d$' ' -f2) + if [ "$http_res" -eq 200 ] + then + echo "ONLINE" + else + echo "OFFLINE" + fi +} + +detect_installation() +{ + echo "Detecting installation type..." + + TYPE="NOT-FOUND" + local compose=$(test_docker_compose) + if [[ "$compose" = "DOCKER-COMPOSE" ]] + then + echo "Docker-compose installation detected." + TYPE="DOCKER-COMPOSE" + else + local docker=$(test_docker) + if [[ "$docker" = "DOCKER-COMPOSE" ]] + then + echo "Classical docker installation detected." + TYPE="DOCKER" + else + local classic=$(test_classic) + if [[ "$classic" = "CLASSIC" ]] + then + echo "Local installation detected on the host system." + TYPE="CLASSIC" + fi + fi + fi + + if [[ "$TYPE" = "NOT-FOUND" ]] + then + echo "ElasticSearch 1.7 was not found on the current system, exiting..." + exit 2 + else + echo "Detecting online status..." + if [[ "$TYPE" != "NOT-FOUND" ]] + then + STATUS=$(test_running) + fi + fi +} + +upgrade_compose() +{ + echo "Upgrading docker-compose installation..." + docker-compose stop elasticsearch + docker-compose rm -f elasticsearch + sed -i.bak s/image: elasticsearch:1.7/image: elasticsearch:2.4/g "$FM_PATH/docker-compose.yml" + docker-compose pull + docker-compose up -d + sleep 10 + STATUS=$(test_running) + if [[ "$STATUS" = "ONLINE" ]]; then + echo "Migration to elastic 2.4 was successful." + else + echo "Unable to find an active ElasticSearch instance, something may have went wrong, exiting..." + exit 4 + fi +} + +upgrade_docker() +{ + echo "Upgrading docker installation..." + local containers=$(docker ps | grep elasticsearch:1.7) + # get container id + local id=$(docker inspect -f '{{.Id}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(echo "$containers" | awk '{print $1}') | grep "$ES_IP" | awk '{print $1}') + # get container name + local name=$(docker inspect -f '{{.Name}}' "$id" | sed s:^/::g) + # get container network name + local network=$(docker inspect -f '{{.NetworkSettings.Networks}}' "$id" | sed) + # get container mapping to data folder + docker pull elasticsearch:2.4 + docker run --restart=always -d --name=fabmanager-elastic -v /home/core/fabmanager/elasticsearch:/usr/share/elasticsearch/data elasticsearch:2.4 + +} + + +upgrade_classic() +{ + echo "Automated upgrade of local installation is not supported." + echo "Please refer to your distribution instructions to install ElasticSearch 2.4" + echo "For more informations: https://www.elastic.co/guide/en/elasticsearch/reference/2.0/setup-upgrade.html" +} + +start_upgrade() +{ + case "$TYPE" in + "DOCKER-COMPOSE") + upgrade_compose + ;; + "DOCKER") + upgrade_docker + ;; + "CLASSIC") + upgrade_classic + ;; + *) + echo "Unexpected ElasticSearch installation $TYPE" + exit 3 + esac +} + +upgrade_elastic() +{ + config + detect_installation + start_upgrade +} + +upgrade_elastic "$@" \ No newline at end of file