diff --git a/auto-start-reverseSSHproxy.sh b/auto-start-reverseSSHproxy.sh index c4754f8226f582dc46466ecf8e2d04ee76392410..c93adf4ae7fe10bb6060f56c6e5646e4dc4afc6e 100755 --- a/auto-start-reverseSSHproxy.sh +++ b/auto-start-reverseSSHproxy.sh @@ -16,7 +16,6 @@ # startAquilaService # ============================================== - tetrixPublicIPOnOVH="109.190.180.230" URL="https://$tetrixPublicIPOnOVH" @@ -28,30 +27,8 @@ reverseSSHproxyPath="/home/dockerweb/reverse-ssh-proxy" HTTP_STATUS=$(curl -o /dev/null -w "%{http_code}\n" -s -k $URL) -if [[ -f "$stateFile" ]]; then +# ===== function ===== # - $state=`cat $stateFile` - # check if tetrix is reachable (status code 200) - if [ $HTTP_STATUS -eq 200 ]; then - if [[ $state != "normal" ]]; then - # Switch on normal mode - cd $reverseSSHproxyPath - docker-compose down - echo "normal" > "$stateFile" - do_sendmail_start root - fi - else - if [[ $state = "normal" ]]; then - # Switch on back up mode - cd $reverseSSHproxyPath - docker-compose up -d - echo "backup" > "$stateFile" - do_sendmail_stop root - fi - fi -else - echo "normal" > "$stateFile" -fi do_sendmail_start() { cat <<EOF | sendmail -t root @@ -80,3 +57,29 @@ dès que le réseau repassera en mode de normal (Fibre), ce dernier sera joignab Cordialement, EOF } + + +if [[ -f "$stateFile" ]]; then + + $state=`cat $stateFile` + # check if tetrix is reachable (status code 200) + if [ $HTTP_STATUS -eq 200 ]; then + if [[ $state != "normal" ]]; then + # Switch on normal mode + cd $reverseSSHproxyPath + docker-compose down + echo "normal" > "$stateFile" + do_sendmail_start root + fi + else + if [[ $state == "normal" ]]; then + # Switch on back up mode + cd $reverseSSHproxyPath + docker-compose up -d + echo "backup" > "$stateFile" + do_sendmail_stop root + fi + fi +else + echo "normal" > "$stateFile" +fi diff --git a/net-switch.sh b/net-switch.sh index f2313afd9b0031e1cc69e75361a4787dafea4a57..665cea80b8a34cdb756a32872a9827687d3682da 100755 --- a/net-switch.sh +++ b/net-switch.sh @@ -29,41 +29,13 @@ APIKEY="PUT YOUT PERSONAL TOKEN" # Jeton sur passbotl stateFile="/opt/net-state" -currentIP=`curl api.ipify.org` +currentIP=`curl -s api.ipify.org` reverseSSHProxyPath="/opt/reverseSSHproxy.sh" recipient="all@tetras-libre.fr" adminemail="sysadmin@tetras-libre.fr" -# check if file exist -if [[ -f "$stateFile" ]]; then - - $state=`cat $stateFile` - - # Check if current ip is different of normal ip - if [[ $tetrixPublicIPOnOVH == $currentIP ]]; then - if [[ $state != "normal" ]]; then - # Switch on normal mode - pid=`ps aux | grep test.sh | grep -v grep | awk '{print $2}'` - kill $pid - change_dns $APIKEY $tetrixPublicIPOnOVH - echo "normal" > "$stateFile" - do_sendmail_start - fi - else - if [[ $state = "normal" ]]; then - # Switch on back up mode - bash $reverseSSHProxyPath & - change_dns $APIKEY $aquilaPublicIPOnOVH - echo "backup" > "$stateFile" - do_sendmail_stop - fi - fi -else - echo "normal" > "$stateFile" -fi - - +# ===== Function ==== # change_dns() { APIKEY=$1 @@ -129,3 +101,33 @@ $tetrixPublicIPOnOVH passbolt.tetras-libre.fr En cas de problème, contactez $adminemail EOF } + + + +# check if file exist +if [[ -f "$stateFile" ]]; then + + $state=`cat $stateFile` + + # Check if current ip is different of normal ip + if [[ $tetrixPublicIPOnOVH == $currentIP ]]; then + if [[ $state != "normal" ]]; then + # Switch on normal mode + pid=`ps aux | grep test.sh | grep -v grep | awk '{print $2}'` + kill $pid + change_dns $APIKEY $tetrixPublicIPOnOVH + echo "normal" > "$stateFile" + do_sendmail_start + fi + else + if [[ $state == "normal" ]]; then + # Switch on back up mode + bash $reverseSSHProxyPath & + change_dns $APIKEY $aquilaPublicIPOnOVH + echo "backup" > "$stateFile" + do_sendmail_stop + fi + fi +else + echo "normal" > "$stateFile" +fi