From 3865a7b00f4eb0aa21fc45dddcf3927f99a269e5 Mon Sep 17 00:00:00 2001 From: Mitesh Shah Date: Tue, 15 Jan 2013 15:02:49 +0530 Subject: [PATCH] Mirror Files On Live & backup Servers --- failover/check-server-health.sh | 11 +++++++++++ failover/sync-with-inotify.sh | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 failover/check-server-health.sh create mode 100644 failover/sync-with-inotify.sh diff --git a/failover/check-server-health.sh b/failover/check-server-health.sh new file mode 100644 index 00000000..f8ba9e80 --- /dev/null +++ b/failover/check-server-health.sh @@ -0,0 +1,11 @@ +#!/bin/bash +while true +do + ping -c1 192.168.0.206 &> /dev/null + if [ $? == 0 ] + then + echo "[+] Server Becomes Alive ......" + rsync -avz --delete /var/www/ root@192.168.0.206:/var/www/ + exit 0; + fi +done diff --git a/failover/sync-with-inotify.sh b/failover/sync-with-inotify.sh new file mode 100644 index 00000000..52af0846 --- /dev/null +++ b/failover/sync-with-inotify.sh @@ -0,0 +1,23 @@ +#!/bin/bash +while true +do + # Monitor Files Changes For Create, Delete, Move, File Permissions + inotifywait --exclude .swp ~ -r -e create -e modify -e create -e delete -e move -e attrib --format %e:%f /var/www/ + + # Rsync When Files Changed + rsync -avz --delete /var/www/ root@192.168.0.206:/var/www/ + + # If Rsync Fails + if [ $? != 0 ] + then + + echo "[+] Checking Server Health Script Is Already Running Or Not ....." + ps ax | grep check-server-health.sh | grep -v grep + + if [ $? != 0 ] + then + echo "[+] Starting Check Server Health Script ....." + bash /root/bin/check-server-health.sh & + fi + fi +done