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