From a42dbfc535a86426a7ceaf2c37a13aa3a1286efd Mon Sep 17 00:00:00 2001 From: Elian Loraux <elian.loraux@tetras-libre.fr> Date: Thu, 25 Jul 2024 16:24:54 +0200 Subject: [PATCH] =?UTF-8?q?Scipt=20de=20bascule=20r=C3=A9seau=20c=C3=B4t?= =?UTF-8?q?=C3=A9=20aquila?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto-start-reverseSSHproxy.sh | 47 +++++++++++++++++++++++++++++++++++ net-switch.sh | 2 -- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 auto-start-reverseSSHproxy.sh diff --git a/auto-start-reverseSSHproxy.sh b/auto-start-reverseSSHproxy.sh new file mode 100644 index 0000000..0adfb2e --- /dev/null +++ b/auto-start-reverseSSHproxy.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + + +# Si tetrix joingnable +# Si etatCourant != Normal +# etatCourrant = Normal +# StopperServiceSurAquila +# Sinon +# Si etatCourant != Backup +# etatCourant = Backup +# DemarrerServiceSurAquila + + + +IPPubliqueTetrixChezOVH="109.190.180.230" + +URL="https://$IPPubliqueTetrixChezOVH" + +stateFile="/opt/net-state" +reverseSSHproxyPath="/home/dockerweb/reverse-ssh-proxy" + +# Faire une requête HTTP et vérifier le code de statut de la réponse +HTTP_STATUS=$(curl -o /dev/null -w "%{http_code}\n" -s -k $URL) + + +if [[ -f "$stateFile" ]]; then + + $state=`cat $stateFile` + # Vérifier si le service est accessible (code de statut 200) + if [ $HTTP_STATUS -eq 200 ]; then + if [[ $state != "normal" ]]; then + # Switch on normal mode + cd $reverseSSHproxyPath + docker-compose down + echo "normal" > "$stateFile" + fi + else + if [[ $state = "normal" ]]; then + # Switch on back up mode + cd $reverseSSHproxyPath + docker-compose up -d + echo "backup" > "$stateFile" + fi + fi +else + echo "normal" > "$stateFile" +fi diff --git a/net-switch.sh b/net-switch.sh index 2fad441..c6f8b3c 100644 --- a/net-switch.sh +++ b/net-switch.sh @@ -20,7 +20,6 @@ if [[ -f "$stateFile" ]]; then if [[ $IPPubliqueTetrixChezOVH == $currentIP ]]; then if [[ $state != "normal" ]]; then # Switch on normal mode - # ssh dockerweb@aquila.tetras-libre.fr 'cd reverse-ssh-proxy && docker-compose down' pid=`ps aux | grep test.sh | grep -v grep | awk '{print $2}'` kill $pid change_dns $APIKEY $IPPubliqueTetrixChezOVH @@ -29,7 +28,6 @@ if [[ -f "$stateFile" ]]; then else if [[ $state = "normal" ]]; then # Switch on back up mode - # ssh dockerweb@aquila.tetras-libre.fr 'cd reverse-ssh-proxy && docker-compose up' bash $reverseSSHProxyPath & change_dns $APIKEY $IPPubliqueAquilaChezOVH echo "backup" > "$stateFile" -- GitLab