1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#!/bin/sh
. /etc/init.d/functions
. /etc/profile
#This script's function is to check master NFS status.And if master NFS server is down,it will switch to backup
#NFS server
#Author:yongzhen
#Date:2015-11-18
#Email:[email protected]
while true
do
/usr/sbin/showmount -e 172.16.1.17 >/dev/null 2>&1
if [ $? -ne 0 ]
then
/usr/bin/ssh 172.16.1.18 /bin/umount -lf /data >/dev/null 2>&1
/usr/bin/ssh 172.16.1.20 /bin/chown -R nfsnobody.nfsnobody /data >/dev/null 2>&1
/usr/bin/ssh 172.16.1.18 /bin/mount -t nfs 172.16.1.20:/data /data >/dev/null 2>&1
/usr/bin/ssh 172.16.1.18 /application/nginx/sbin/nginx -s reload >/dev/null 2>&1
echo "NFS Server is down!!! At $(date +%F_%H:%M:%S)">/home/yongzhen/warning/nfs_warning_$(date +%F).log
curl_id=$(/usr/bin/curl -I -s -w %{http_code} -o /dev/null www.etiantian.org)
if [ $curl_id -ne 200 ]
then
echo "Switch to backup NFS server is Failed">>/home/yongzhen/warning/nfs_warning_$(date +%F).log
else
echo "Switch to backup NFS server is Successful">>/home/yongzhen/warning/nfs_warning_$(date +%F).log
fi
mail -s "NFS Server Warning" [email protected]
exit 1
fi
sleep 5
done