From 7e308433bf8acfed75fb8befbd37ef13bd647423 Mon Sep 17 00:00:00 2001 From: David Foucher Date: Tue, 23 Jun 2020 15:43:33 +0200 Subject: [PATCH] Add restart script for troubleshooting and script to update web --- README.md | 12 ++++++++---- docker/restart_stack.sh | 36 ++++++++++++++++++++++++++++++++++++ docker/update_api.sh | 2 +- docker/update_web.sh | 15 +++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100755 docker/restart_stack.sh create mode 100755 docker/update_web.sh diff --git a/README.md b/README.md index 0ae2ca95..9b4260d1 100644 --- a/README.md +++ b/README.md @@ -125,13 +125,11 @@ OLD_VERSION and BACK_VERSION must be compatible ### Update API 1. Update `VERSION` in `.env` file -2. Update API, in `docker` folder process : `update_api.sh trefle` +2. Update API, in `docker` folder process : `./update_api.sh trefle` ### Update WEB 1. Update `BACK_VERSION` in `.env` file -2. Update API, in `docker` folder process : `docker-compose up -d --no-deps` -3. Reload authorisations.csv : `sh update_access.sh` - +2. Update the website, in `docker` folder process : `./update_web.sh` ## Update acces @@ -142,3 +140,9 @@ logs are in docker/logs Format for authorisations.csv : `email,password,files` Note: multiple files must be separated with a "|" + +## Troubleshooting + +Try to restart the stack with `./restart_stack.sh` + + diff --git a/docker/restart_stack.sh b/docker/restart_stack.sh new file mode 100755 index 00000000..13889002 --- /dev/null +++ b/docker/restart_stack.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +OPTION=$1 + +date >> update.log +echo $* >> update.log + +if [ -n "$OPTION" ] +then + if [ "$OPTION" == "build-recreate" ] + then + echo "[INIT] Force rebuild and recreate new container" | tee -a update.log + docker-compose up -d --build --force-recreate \ + || { echo "[FAILED] Can't rebuild and recreate container - try ./restart_stack.sh build-local" | tee -a update.log; exit 1; } + echo "[DONE] All container rebuilt and restarted" | tee -a update.log + elif [ "$OPTION" == "build-local" ] + then + echo "[INIT] Force rebuild locally and recreate new container" | tee -a update.log + docker-compose -f docker-compose.yml -f docker-compose.override-build.yml up -d --build --force-recreate \ + || { echo "[FAILED] Can't rebuild and recreate container localy - try ./restart_stack.sh restart-docker" | tee -a update.log; exit 1; } + echo "[DONE] All container locally rebuilt and restarted" | tee -a update.log + elif [ "$OPTION" == "restart-docker" ] + then + echo "[INIT] Force restart docker" | tee -a update.log + systemctl restart docker.service && ./restart_stack.sh \ + || { echo "[FAILED] Can't restart docker service and rebuild trefle stack" | tee -a update.log; exit 1; } + echo "[DONE] Docker service restarted" | tee -a update.log + fi +else + echo "[INIT] restart container" | tee -a update.log + docker-compose restart \ + || { echo "[FAILED] Can't restart container - try ./restart_stack.sh build-recreate" | tee -a update.log; exit 1; } + echo "[DONE] All container restarted" | tee -a update.log +fi + +exit 0; diff --git a/docker/update_api.sh b/docker/update_api.sh index 1c35b116..b0ee3aa7 100755 --- a/docker/update_api.sh +++ b/docker/update_api.sh @@ -1,6 +1,6 @@ #!/bin/bash -SERVICE_NAME=${1?"Usage: docker_update [trefle|trefle-old]"} +SERVICE_NAME=${1?"Usage: ./update_api.sh [trefle|trefle-old]"} date >> update.log echo $* >> update.log diff --git a/docker/update_web.sh b/docker/update_web.sh new file mode 100755 index 00000000..8197fdf5 --- /dev/null +++ b/docker/update_web.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +date >> update.log +echo $* >> update.log + +echo "[INIT] rebuild" +docker-compose up -d --build --no-deps web \ + || { echo "[FAILED] Can't rebuild web container" | tee -a update.log; exit 1; } + +echo "[INIT] refresh access" | tee -a update.log +./update_access.sh \ + || { echo "[FAILED] Can't refresh access" | tee -a update.log; exit 1; } \ + +echo "[DONE] refresh access" | tee -a update.log \ + && exit 0 -- GitLab