Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • nocloud/server-utils
1 result
Select Git revision
Show changes
Commits on Source (6)
#!/usr/bin/env bash
# ==============================================
#
# This is second part of switch network between WAN and 4G
# This script is Aquila part
#
# ==============================================
# if tetrix reachable
# if etatCourant != Normal
# currentStatre = Normal
# stoppedAquilaService
# else
# if currentStatre != Backup
# currentStatre = Backup
# startAquilaService
# ==============================================
tetrixPublicIPOnOVH="109.190.180.230"
URL="https://$tetrixPublicIPOnOVH"
stateFile="/opt/net-state"
reverseSSHproxyPath="/home/dockerweb/reverse-ssh-proxy"
# Send HTTP request on tetrix to get status code
HTTP_STATUS=$(curl -o /dev/null -w "%{http_code}\n" -s -k $URL)
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
do_sendmail_start() {
cat <<EOF | sendmail -t root
Subject: [$(hostname)] Serveur Tetrix injoignable
Bonjour,
$(hostname) viens de detecter que Tetrix est injoignable par son IP normale ($tetrixPublicIPOnOVH).
Le système d'accès à distance à Tétrix via $(hostname) (reverseSSHproxyPath) est actif,
dès que le réseau passera en mode de secours (4G), ce dernier sera joignable à nouveau.
Cordialement,
EOF
}
do_sendmail_stop() {
cat <<EOF | sendmail -t root
Subject: [$(hostname)] Serveur Tetrix injoignable
Bonjour,
$(hostname) viens de detecter que Tetrix est à nouveau joignable par son IP nornale ($tetrixPublicIPOnOVH).
Le système d'accès à distance à Tétrix via $(hostname) (reverseSSHproxyPath) est désactivé,
dès que le réseau repassera en mode de normal (Fibre), ce dernier sera joignable à nouveau.
Cordialement,
EOF
}
#!/usr/bin/env bash
# ==============================================
#
# This is first part of switch network between WAN and 4G
# This script is Tetrix part
#
# ==============================================
# if myPublicIP == tetrixPublicIPOnOVH
# if currentStatre != Normal
# currentStatre = Normal
# stoppedSSHTunnel
# changeTetrixAndWithGandiAPI to tetrixPublicIPOnOVH
# sandMainAtRoot
# Else
# if currentStatre != Backup
# currentStatre = Backup
# startSSHTunnel
# changeTetrixAndWithGandiAPI vers aquilaPublicIPOnOVH
# sandMainAtRoot
# ==============================================
tetrixPublicIPOnOVH="109.190.180.230"
aquilaPublicIPOnOVH="5.135.140.89"
# Gandi personal Token
APIKEY="PUT YOUT PERSONAL TOKEN" # Jeton sur passbotl
stateFile="/opt/net-state"
currentIP=`curl 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
change_dns() {
APIKEY=$1
CURRENTIP=$2
curl -s -X PUT --header "Authorization: Bearer ${APIKEY}" \
--header "Content-Type: application/json" \
-d "{\"rrset_values\": [\"${CURRENTIP}\"], \"rrset_ttl\": "300"}" \
https://api.gandi.net/v5/livedns/domains/tetras-libre.fr/records/tetrixx/A
}
do_sendmail_start() {
cat <<EOF | sendmail -t $recipient
Subject: [$(hostname)] Bascule du réseau en $1
Bonjour,
La bascule automatique du réseau viens de s'activer sur $(hostname). Passage en $1.
Pour utiliser gitlab, vous devez ajouter ces lignes dans ~/.ssh/config :
host gitlab.tetras-libre.fr
Port 2223
La bascule se fait via un changement de DNS qui peut mettre un peu de temps à ce propager (3h) max.
Pendant ce temps vous pouvez ajouter les lignes suivantes dans /etc/hosts:
$aquilaPublicIPOnOVH nextcloud.tetras-libre.fr
$aquilaPublicIPOnOVH gitlab.tetras-libre.fr
$aquilaPublicIPOnOVH dolibarr.tetras-libre.fr
$aquilaPublicIPOnOVH passbolt.tetras-libre.fr
En cas de problème, contactez $adminemail
Cordialement,
EOF
}
do_sendmail_stop() {
cat <<EOF | sendmail -t $recipient
Subject: [$(hostname)] Bascule du réseau en $1
Bonjour,
La bascule automatique du réseau viens de s'activer sur $(hostname). Passage en $1.
Pour utiliser gitlab, pensez à supprimer les lignes concernant gitlab.tetras-libre.fr dans ~/.ssh/config.
La bascule se fait via un changement de DNS qui peut mettre un peu de temps à ce propager (3h) max.
Pendant ce temps vous pouvez ajouter les lignes suivantes dans /etc/hosts:
$tetrixPublicIPOnOVH nextcloud.tetras-libre.fr
$tetrixPublicIPOnOVH gitlab.tetras-libre.fr
$tetrixPublicIPOnOVH dolibarr.tetras-libre.fr
$tetrixPublicIPOnOVH passbolt.tetras-libre.fr
En cas de problème, contactez $adminemail
EOF
}
#!/bin/bash
HTTPS_PORT=8080
SSHPORT_INT=2223
SSHPORT=2222
PROXY_HOST=aquila.tetras-libre.fr
while true; do
/usr/bin/ssh -i /root/.ssh/id_rsa -N -R ${HTTPS_PORT}:localhost:443 -R ${SSHPORT_INT}:localhost:22 -o "ExitOnForwardFailure yes" -o "StrictHostKeyChecking no" -o "ServerAliveInterval 60" sshuser@${PROXY_HOST} -p ${SSHPORT}
echo "Ssh failed $?"
sleep 5
done
......@@ -19,6 +19,14 @@ case $1 in
"fin")
mutt -s "Fin des operations de maintenance" -i modele-mail-fin $mailtosend
;;
"netbasculestart")
mailtosend="sysadmin@tetras-libre.fr"
mutt -s "Basculement auto du réseau WAN vers 4G" -i modele-mail-netbascule-start $mailtosend
;;
"netbasculestart")
mailtosend="sysadmin@tetras-libre.fr"
mutt -s "Basculement auto du réseau 4G vers WAN" -i modele-mail-netbascule-stop $mailtosend
;;
*)
echo "Usage: $0 {annonce|debut|fin}"
exit 1
......