From cbd93ca7d8136d47e4b41f9980f8c3dd76e7ce9b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Oct 2019 10:44:29 +0200 Subject: [PATCH 01/11] pgSQL upgrade script: check for postmaster.pid --- scripts/postgre-upgrade.sh | 40 ++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index 57f1bbafc..fe38c933f 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -39,10 +39,10 @@ config() then if [ -f "$FM_PATH/config/application.yml" ] then - PG_HOST=$(cat "$FM_PATH/config/application.yml" | grep POSTGRES_HOST | awk '{print $2}') + PG_HOST=$(grep POSTGRES_HOST "$FM_PATH/config/application.yml" | awk '{print $2}') elif [ -f "$FM_PATH/config/env" ] then - PG_HOST=$(cat "$FM_PATH/config/env" | grep POSTGRES_HOST | awk '{split($0,a,"="); print a[2]}') + PG_HOST=$(grep POSTGRES_HOST "$FM_PATH/config/env" | awk '{split($0,a,"="); print a[2]}') else echo "Fab-manager's environment file not found, please run this script from the installation folder" exit 1 @@ -64,11 +64,11 @@ test_free_space() { # checking disk space (minimum required = 1.2GB) required=$(du -d 0 "$PG_PATH" | awk '{ print $1 }') - space=$(df $FM_PATH | awk '/[0-9]%/{print $(NF-2)}') + space=$(df "$FM_PATH" | awk '/[0-9]%/{print $(NF-2)}') if [ "$space" -lt "$required" ] then echo "Not enough free disk space to perform upgrade. Please free at least $required bytes of disk space and try again" - df -h $FM_PATH + df -h "$FM_PATH" exit 7 fi } @@ -77,12 +77,16 @@ test_docker_compose() { if [[ -f "$FM_PATH/docker-compose.yml" ]] then - docker-compose ps | grep postgres - if [[ $? = 0 ]] + if [[ $(docker-compose ps | grep postgres) = 0 ]] then TYPE="DOCKER-COMPOSE" - local container_id=$(docker-compose ps | grep postgre | awk '{print $1}') - PG_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container_id") + local container_id, ip + container_id=$(docker-compose ps | grep postgre | awk '{print $1}') + ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container_id") + if [ "$PG_IP" != "$ip" ]; then + puts "IP address is not matching, exiting..." + exit 8 + fi fi fi } @@ -110,6 +114,26 @@ prepare_path() docker_down() { docker-compose down + ensure_pg_down +} + +ensure_pg_down() +{ + if [ -f "$PG_PATH/postmaster.pid" ]; then + echo 'ERROR: lock file "postmaster.pid" exists' + if [[ $(docker-compose ps | grep postgres) = 1 ]]; then + read -rp 'docker-compose container is not running. Confirm delete the lock file? (y/N) ' confirm Date: Tue, 22 Oct 2019 10:54:48 +0200 Subject: [PATCH 02/11] fix bash: if cmd --- scripts/postgre-upgrade.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index fe38c933f..f333fd227 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -77,7 +77,7 @@ test_docker_compose() { if [[ -f "$FM_PATH/docker-compose.yml" ]] then - if [[ $(docker-compose ps | grep postgres) = 0 ]] + if docker-compose ps | grep postgres then TYPE="DOCKER-COMPOSE" local container_id, ip @@ -121,7 +121,7 @@ ensure_pg_down() { if [ -f "$PG_PATH/postmaster.pid" ]; then echo 'ERROR: lock file "postmaster.pid" exists' - if [[ $(docker-compose ps | grep postgres) = 1 ]]; then + if ! docker-compose ps | grep postgres; then read -rp 'docker-compose container is not running. Confirm delete the lock file? (y/N) ' confirm Date: Tue, 22 Oct 2019 10:58:07 +0200 Subject: [PATCH 03/11] pg upgrade script: fix ip test --- scripts/postgre-upgrade.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index f333fd227..49b3c229c 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -80,11 +80,12 @@ test_docker_compose() if docker-compose ps | grep postgres then TYPE="DOCKER-COMPOSE" - local container_id, ip + local container_id container_id=$(docker-compose ps | grep postgre | awk '{print $1}') + local ip ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container_id") if [ "$PG_IP" != "$ip" ]; then - puts "IP address is not matching, exiting..." + echo "IP address is not matching ($PG_IP != $ip), exiting..." exit 8 fi fi From 8217918cec4af4eae92da83ac169e8e222fa41fd Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Oct 2019 11:04:21 +0200 Subject: [PATCH 04/11] enlight pg upgrade script --- scripts/postgre-upgrade.sh | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index 49b3c229c..d79e4634a 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -35,19 +35,7 @@ config() FM_PATH=$(pwd) TYPE="NOT-FOUND" read -rp "Is fab-manager installed at \"$FM_PATH\"? (y/N) " confirm Date: Tue, 22 Oct 2019 11:10:17 +0200 Subject: [PATCH 05/11] redirect ioctl err messages to /dev/null --- scripts/postgre-upgrade.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index d79e4634a..5f711d1c7 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -65,7 +65,7 @@ test_docker_compose() { if [[ -f "$FM_PATH/docker-compose.yml" ]] then - if docker-compose ps | grep postgres + if docker-compose ps | grep postgres 2>/dev/null then TYPE="DOCKER-COMPOSE" fi @@ -102,7 +102,7 @@ ensure_pg_down() { if [ -f "$PG_PATH/postmaster.pid" ]; then echo 'ERROR: lock file "postmaster.pid" exists' - if ! docker-compose ps | grep postgres; then + if ! docker-compose ps | grep postgres 2>/dev/null; then read -rp 'docker-compose container is not running. Confirm delete the lock file? (y/N) ' confirm Date: Tue, 22 Oct 2019 11:25:34 +0200 Subject: [PATCH 06/11] revert if cmd to using 0 --- scripts/postgre-upgrade.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index 5f711d1c7..6f0997871 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -65,7 +65,8 @@ test_docker_compose() { if [[ -f "$FM_PATH/docker-compose.yml" ]] then - if docker-compose ps | grep postgres 2>/dev/null + docker-compose ps | grep postgres + if [[ $? = 0 ]] then TYPE="DOCKER-COMPOSE" fi @@ -102,7 +103,8 @@ ensure_pg_down() { if [ -f "$PG_PATH/postmaster.pid" ]; then echo 'ERROR: lock file "postmaster.pid" exists' - if ! docker-compose ps | grep postgres 2>/dev/null; then + docker-compose ps | grep postgres + if [[ $? = 1 ]]; then read -rp 'docker-compose container is not running. Confirm delete the lock file? (y/N) ' confirm Date: Tue, 22 Oct 2019 11:47:04 +0200 Subject: [PATCH 07/11] double confirm on clean + fix read_path --- scripts/postgre-upgrade.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index 6f0997871..c7e008915 100644 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -76,7 +76,7 @@ test_docker_compose() read_path() { PG_PATH=$(awk "BEGIN { FS=\"\n\"; RS=\"\"; } { match(\$0, /image: postgres:$OLD(\n|.)+volumes:(\n|.)+(-.*postgresql\/data)/, lines); FS=\"[ :]+\"; RS=\"\r\n\"; split(lines[3], line); print line[2] }" "$FM_PATH/docker-compose.yml") - PG_PATH="${PG_PATH/\$\{PWD\}/$(pwd)}" + PG_PATH="${PG_PATH/@(\$\{PWD\}|\.)/$(pwd)}" PG_PATH="${PG_PATH/[[:space:]]/}" } @@ -155,10 +155,12 @@ docker_up() clean() { read -rp "Remove the previous PostgreSQL data folder? (y/N) " confirm Date: Tue, 22 Oct 2019 11:48:24 +0200 Subject: [PATCH 08/11] make script executable --- scripts/postgre-upgrade.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/postgre-upgrade.sh diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh old mode 100644 new mode 100755 From a787814c6a1ed45c6729d8ebf33fce1e049ca3d9 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Oct 2019 11:54:37 +0200 Subject: [PATCH 09/11] debug pg_upgrade command --- scripts/postgre-upgrade.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index c7e008915..5e764fecb 100755 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -121,6 +121,7 @@ ensure_pg_down() pg_upgrade() { + echo "docker run --rm -v $PG_PATH:/var/lib/postgresql/$OLD/data -v $NEW_PATH:/var/lib/postgresql/$NEW/data tianon/postgres-upgrade:$OLD-to-$NEW" docker run --rm \ -v "$PG_PATH:/var/lib/postgresql/$OLD/data" \ -v "$NEW_PATH:/var/lib/postgresql/$NEW/data" \ From 0555883ea34100a11439dd82ee462fed9835440d Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Oct 2019 12:20:00 +0200 Subject: [PATCH 10/11] fix read path --- scripts/postgre-upgrade.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/postgre-upgrade.sh b/scripts/postgre-upgrade.sh index 5e764fecb..52a652104 100755 --- a/scripts/postgre-upgrade.sh +++ b/scripts/postgre-upgrade.sh @@ -76,7 +76,8 @@ test_docker_compose() read_path() { PG_PATH=$(awk "BEGIN { FS=\"\n\"; RS=\"\"; } { match(\$0, /image: postgres:$OLD(\n|.)+volumes:(\n|.)+(-.*postgresql\/data)/, lines); FS=\"[ :]+\"; RS=\"\r\n\"; split(lines[3], line); print line[2] }" "$FM_PATH/docker-compose.yml") - PG_PATH="${PG_PATH/@(\$\{PWD\}|\.)/$(pwd)}" + PG_PATH="${PG_PATH/\$\{PWD\}/$FM_PATH}" + PG_PATH="${PG_PATH/\./$FM_PATH}" PG_PATH="${PG_PATH/[[:space:]]/}" } From 9aa69a3fac7d64488c4e4558c99bee6a4d4f96f7 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 22 Oct 2019 12:51:56 +0200 Subject: [PATCH 11/11] Version 4.2.2 --- CHANGELOG.md | 18 +++++++++++------- package.json | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7c84d72e..598207f52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog Fab Manager +## v4.2.2 2019 October 22 + +- Fix a bug: PostgreSQL upgrade script won't run on some systems + ## v4.2.1 2019 October 21 - Updated axlsx gem to caxlsx 3.0 @@ -34,16 +38,16 @@ - Fix a bug: unauthorized user can see the edit project form - Fix a bug: do not display each days in invoices for multiple days event reservation - Fix a security issue: fixed [CVE-2015-9284](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-9284) -- [TODO DEPLOY] **IMPORTANT** Please read [postgres_upgrade.md](doc/postgres_upgrade.md) for instructions on upgrading PostgreSQL. -- [TODO DEPLOY] `rake db:migrate` - [TODO DEPLOY] -> (only dev) `yarn install` and `bundle install` - [TODO DEPLOY] -> (only dev) configure `DEFAULT_HOST: 'localhost:5000'` and `DEFAULT_PROTOCOL: http` in [application.yml](config/application.yml.default) -- [TODO DEPLOY] add the `RECAPTCHA_SITE_KEY` and `RECAPTCHA_SECRET_KEY` environment variables (see [doc/environment.md](doc/environment.md) for configuration details) -- [TODO DEPLOY] add the `MAX_CAO_SIZE` environment variable (see [doc/environment.md](doc/environment.md) for configuration details) -- [TODO DEPLOY] add the `MAX_IMPORT_SIZE` environment variable (see [doc/environment.md](doc/environment.md) for configuration details) +- [TODO DEPLOY] `rake db:migrate` - [TODO DEPLOY] add `- ${PWD}/imports:/usr/src/app/imports` in the volumes list of your fabmanager service in [docker-compose.yml](docker/docker-compose.yml) -- [TODO DEPLOY] add the `FABLAB_WITHOUT_INVOICES` environment variable (see [doc/environment.md](doc/environment.md) for configuration details) -- [TODO DEPLOY] add the following `SMTP_TLS` environment variables (see [doc/environment.md](doc/environment.md) for configuration details) +- [TODO DEPLOY] add the `RECAPTCHA_SITE_KEY` and `RECAPTCHA_SECRET_KEY` environment variables (see [doc/environment.md](doc/environment.md#RECAPTCHA_SITE_KEY) for configuration details) +- [TODO DEPLOY] add the `MAX_CAO_SIZE` environment variable (see [doc/environment.md](doc/environment.md#MAX_CAO_SIZE) for configuration details) +- [TODO DEPLOY] add the `MAX_IMPORT_SIZE` environment variable (see [doc/environment.md](doc/environment.md#MAX_IMPORT_SIZE) for configuration details) +- [TODO DEPLOY] add the `FABLAB_WITHOUT_INVOICES` environment variable (see [doc/environment.md](doc/environment.md#FABLAB_WITHOUT_INVOICES) for configuration details) +- [TODO DEPLOY] add the `SMTP_TLS` environment variable (see [doc/environment.md](doc/environment.md#SMTP_TLS) for configuration details) +- [TODO DEPLOY] **IMPORTANT** Please read [postgres_upgrade.md](doc/postgres_upgrade.md) for instructions on upgrading PostgreSQL. ## v4.1.1 2019 September 20 diff --git a/package.json b/package.json index 48d1a0ca5..380c00823 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fab-manager", - "version": "4.2.1", + "version": "4.2.2", "description": "FabManager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.", "keywords": [ "fablab",