From a37052fb155399834ba5272dd5bd5cb5a10cd621 Mon Sep 17 00:00:00 2001 From: Nicolas Lang Date: Sun, 17 Dec 2023 20:17:25 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Linux/Powershell/Keepalived/sync_nginx.sh | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Linux/Powershell/Keepalived/sync_nginx.sh diff --git a/Linux/Powershell/Keepalived/sync_nginx.sh b/Linux/Powershell/Keepalived/sync_nginx.sh new file mode 100644 index 0000000..f59273b --- /dev/null +++ b/Linux/Powershell/Keepalived/sync_nginx.sh @@ -0,0 +1,45 @@ +#!/bin/bash +KEYPATH="/root/.ssh/reverseproxy2" +REMOTEHOST="reverseproxy-2.domaine" + + +# La synchro se fait par une récupération depuis le backup de master. +# Si keepalived est master, on ne fait pas de synchro +STATE=`/bin/snmpget -v2c -c public 127.0.0.1 KEEPALIVED-MIB::vrrpInstanceState.1 | /bin/sed -Er 's/(.*)INTEGER: (.*)\(([0-9])\)/\2/g'` +echo "State : ${STATE}" +if [[ "$STATE" == "master" ]]; then + echo "Master : No sync" + exit 2 +fi + +# Si keepalived est down, on ne fait pas de synchro (maintenance) +systemctl is-active --quiet keepalived +if [ $? -ne 0 ]; then + echo "Keepalived down : no sync" + exit 0 +fi +echo "Run sync nginx" +RSYNCNGINX=$(/bin/rsync -e "ssh -i $KEYPATH" -aiuh root@$REMOTEHOST:/etc/nginx/ /etc/nginx) +if [ $? -eq 0 ]; then + +echo "Run sync Let's Encrypt'" + RSYNCLE=$(/bin/rsync -e "ssh -i $KEYPATH" -aiuh root@$REMOTEHOST:/etc/letsencrypt/ /etc/letsencrypt) +else + exit 3 +fi + +if [ $? -eq 0 ]; then + echo "Run sync www" + RSYNCWWW=$(/bin/rsync -e "ssh -i $KEYPATH" -aiuh root@$REMOTEHOST:/var/www/ /var/www) +else + exit 2 +fi + +if [ $? -eq 0 ]; then + if [ -n "${RSYNCNGINX}" ] || [ -n "${RSYNCWWW}" ]; then + /usr/sbin/nginx -s reload + echo "reloaded." + fi +else + exit 1 +fi \ No newline at end of file