From fd7e39e95906020870ecff022eadab4961bef5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 22 Mar 2023 16:17:57 +0100 Subject: [PATCH 1/4] Add script to set Neo4j in offline (maintenance) mode and back online --- deployment/scripts/cluster.neo4j.sh | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 deployment/scripts/cluster.neo4j.sh diff --git a/deployment/scripts/cluster.neo4j.sh b/deployment/scripts/cluster.neo4j.sh new file mode 100755 index 000000000..9d996b0be --- /dev/null +++ b/deployment/scripts/cluster.neo4j.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# base setup +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) + +# check CONFIGURATION +if [ -z ${CONFIGURATION} ]; then + echo "You must provide a `CONFIGURATION` via environment variable" + exit 1 +fi + +# configuration +KUBECONFIG=${KUBECONFIG:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/kubeconfig.yaml} + +case $1 in + offline-mode) + # maintenance mode on + ${SCRIPT_DIR}/cluster.maintenance.sh on + + # set Neo4j in offline mode (maintenance) + kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ + | jq '.spec.template.spec.containers[] += {"command": ["tail", "-f", "/dev/null"]}' \ + | kubectl --kubeconfig=${KUBECONFIG} apply -f - + + # wait for the container to restart + sleep 60 + ;; + online-mode) + # set Neo4j in online mode + kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ + | jq 'del(.spec.template.spec.containers[].command)' \ + | kubectl --kubeconfig=${KUBECONFIG} apply -f - + + # wait for the container to restart + sleep 60 + + # maintenance mode off + ${SCRIPT_DIR}/cluster.maintenance.sh off + ;; + *) + echo -e "Run this script with first argument either 'offline-mode' or 'online-mode'" + exit + ;; +esac From 8d68537e3212dea6492c28faba0e8c1c58e7c5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 22 Mar 2023 16:18:07 +0100 Subject: [PATCH 2/4] Refactor backup script by using new 'cluster.neo4j.sh' --- deployment/scripts/cluster.backup.sh | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/deployment/scripts/cluster.backup.sh b/deployment/scripts/cluster.backup.sh index 7d9cbd44d..22be2869b 100755 --- a/deployment/scripts/cluster.backup.sh +++ b/deployment/scripts/cluster.backup.sh @@ -19,15 +19,8 @@ BACKUP_FOLDER=${BACKUP_FOLDER:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/ mkdir -p ${BACKUP_FOLDER} # maintenance mode on -${SCRIPT_DIR}/cluster.maintenance.sh on - -# shutdown database -kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ - | jq '.spec.template.spec.containers[] += {"command": ["tail", "-f", "/dev/null"]}' \ - | kubectl --kubeconfig=${KUBECONFIG} apply -f - - -# wait for the container to restart -sleep 60 +# set Neo4j in offline mode (maintenance) +${SCRIPT_DIR}/cluster.neo4j.sh offline-mode # database backup kubectl --kubeconfig=${KUBECONFIG} -n default exec -it \ @@ -40,13 +33,6 @@ kubectl --kubeconfig=${KUBECONFIG} cp \ kubectl --kubeconfig=${KUBECONFIG} cp \ default/$(kubectl --kubeconfig=${KUBECONFIG} -n default get pods | grep ocelot-backend |awk '{ print $1 }'):/app/public/uploads $BACKUP_FOLDER/public-uploads -# restart database -kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ - | jq 'del(.spec.template.spec.containers[].command)' \ - | kubectl --kubeconfig=${KUBECONFIG} apply -f - - -# wait for the container to restart -sleep 60 - +# set Neo4j in online mode # maintenance mode off -${SCRIPT_DIR}/cluster.maintenance.sh off \ No newline at end of file +${SCRIPT_DIR}/cluster.neo4j.sh online-mode \ No newline at end of file From 16ce5673a315ec5ee97fd4f791d79d052f3a5af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 25 Oct 2023 13:26:23 +0200 Subject: [PATCH 3/4] Change 'cluster.neo4j.sh' switching command to same mechanic as maintenance --- deployment/scripts/cluster.backup.sh | 4 ++-- deployment/scripts/cluster.neo4j.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deployment/scripts/cluster.backup.sh b/deployment/scripts/cluster.backup.sh index 64ea2a756..2ca7bd206 100755 --- a/deployment/scripts/cluster.backup.sh +++ b/deployment/scripts/cluster.backup.sh @@ -20,7 +20,7 @@ mkdir -p ${BACKUP_FOLDER} # maintenance mode on # set Neo4j in offline mode (maintenance) -${SCRIPT_DIR}/cluster.neo4j.sh offline-mode +${SCRIPT_DIR}/cluster.neo4j.sh off # database backup kubectl --kubeconfig=${KUBECONFIG} -n default exec -it \ @@ -35,4 +35,4 @@ kubectl --kubeconfig=${KUBECONFIG} cp \ # set Neo4j in online mode # maintenance mode off -${SCRIPT_DIR}/cluster.neo4j.sh online-mode \ No newline at end of file +${SCRIPT_DIR}/cluster.neo4j.sh on \ No newline at end of file diff --git a/deployment/scripts/cluster.neo4j.sh b/deployment/scripts/cluster.neo4j.sh index 9d996b0be..f886b0916 100755 --- a/deployment/scripts/cluster.neo4j.sh +++ b/deployment/scripts/cluster.neo4j.sh @@ -14,7 +14,7 @@ fi KUBECONFIG=${KUBECONFIG:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/kubeconfig.yaml} case $1 in - offline-mode) + off) # maintenance mode on ${SCRIPT_DIR}/cluster.maintenance.sh on @@ -26,7 +26,7 @@ case $1 in # wait for the container to restart sleep 60 ;; - online-mode) + on) # set Neo4j in online mode kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ | jq 'del(.spec.template.spec.containers[].command)' \ @@ -39,7 +39,7 @@ case $1 in ${SCRIPT_DIR}/cluster.maintenance.sh off ;; *) - echo -e "Run this script with first argument either 'offline-mode' or 'online-mode'" + echo -e "Run this script with first argument either 'off' or 'on'" exit ;; esac From 85e6b5fc48d7f42d1a1ed3d0c69b327bc5d84670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 25 Oct 2023 13:56:14 +0200 Subject: [PATCH 4/4] Change 'cluster.neo4j.sh' commands to 'maintenance on' and 'maintenance off' --- deployment/scripts/cluster.backup.sh | 10 +++--- deployment/scripts/cluster.neo4j.sh | 48 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/deployment/scripts/cluster.backup.sh b/deployment/scripts/cluster.backup.sh index 2ca7bd206..9503061cf 100755 --- a/deployment/scripts/cluster.backup.sh +++ b/deployment/scripts/cluster.backup.sh @@ -18,9 +18,8 @@ BACKUP_FOLDER=${BACKUP_FOLDER:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/ # create backup fodler mkdir -p ${BACKUP_FOLDER} -# maintenance mode on -# set Neo4j in offline mode (maintenance) -${SCRIPT_DIR}/cluster.neo4j.sh off +# cluster maintenance mode on && Neo4j maintenance mode on +${SCRIPT_DIR}/cluster.neo4j.sh maintenance on # database backup kubectl --kubeconfig=${KUBECONFIG} -n default exec -it \ @@ -33,6 +32,5 @@ kubectl --kubeconfig=${KUBECONFIG} cp \ kubectl --kubeconfig=${KUBECONFIG} cp \ default/$(kubectl --kubeconfig=${KUBECONFIG} -n default get pods | grep ocelot-backend |awk '{ print $1 }'):/app/public/uploads $BACKUP_FOLDER/public-uploads -# set Neo4j in online mode -# maintenance mode off -${SCRIPT_DIR}/cluster.neo4j.sh on \ No newline at end of file +# Neo4j maintenance mode off && cluster maintenance mode off +${SCRIPT_DIR}/cluster.neo4j.sh maintenance off \ No newline at end of file diff --git a/deployment/scripts/cluster.neo4j.sh b/deployment/scripts/cluster.neo4j.sh index f886b0916..41ebe4227 100755 --- a/deployment/scripts/cluster.neo4j.sh +++ b/deployment/scripts/cluster.neo4j.sh @@ -14,32 +14,40 @@ fi KUBECONFIG=${KUBECONFIG:-${SCRIPT_DIR}/../configurations/${CONFIGURATION}/kubeconfig.yaml} case $1 in - off) - # maintenance mode on - ${SCRIPT_DIR}/cluster.maintenance.sh on + maintenance) + case $2 in + on) + # maintenance mode on + ${SCRIPT_DIR}/cluster.maintenance.sh on - # set Neo4j in offline mode (maintenance) - kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ - | jq '.spec.template.spec.containers[] += {"command": ["tail", "-f", "/dev/null"]}' \ - | kubectl --kubeconfig=${KUBECONFIG} apply -f - + # set Neo4j in offline mode (maintenance) + kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ + | jq '.spec.template.spec.containers[] += {"command": ["tail", "-f", "/dev/null"]}' \ + | kubectl --kubeconfig=${KUBECONFIG} apply -f - - # wait for the container to restart - sleep 60 - ;; - on) - # set Neo4j in online mode - kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ - | jq 'del(.spec.template.spec.containers[].command)' \ - | kubectl --kubeconfig=${KUBECONFIG} apply -f - + # wait for the container to restart + sleep 60 + ;; + off) + # set Neo4j in online mode + kubectl --kubeconfig=${KUBECONFIG} get deployment ocelot-neo4j -o json \ + | jq 'del(.spec.template.spec.containers[].command)' \ + | kubectl --kubeconfig=${KUBECONFIG} apply -f - - # wait for the container to restart - sleep 60 + # wait for the container to restart + sleep 60 - # maintenance mode off - ${SCRIPT_DIR}/cluster.maintenance.sh off + # maintenance mode off + ${SCRIPT_DIR}/cluster.maintenance.sh off + ;; + *) + echo -e "Run this script with first argument either 'off' or 'on'" + exit + ;; + esac ;; *) - echo -e "Run this script with first argument either 'off' or 'on'" + echo -e "Run this script with first argument 'maintenance'" exit ;; esac