-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_site_check.sh
More file actions
executable file
·94 lines (85 loc) · 3.5 KB
/
source_site_check.sh
File metadata and controls
executable file
·94 lines (85 loc) · 3.5 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# Author: Payne Zheng <zzuai520@live.com>
# Date: 2017-05-15 15:30:43
# Location: Shenzhen
# Desc: check back origin site domain analytic
#
cleanUp() {
rm -f $domainBackList
}
report() {
local groupName apiUrl msg
#groupName="PLCDN-SUPPORT"
#groupName="PLCDN-STATUS"
apiUrl="http://push.plcdn.net:7890/20160128"
msg=$1
groupName=$2
wget -q --tries=1 --timeout=30 --header="To: $groupName" \
--post-data="$msg" "$apiUrl" \
-O /dev/null
}
makeMsg() {
local mType=$1
test $mType = xx && { totil=">Sourcesite failure";action="Notice customer..."; }
test $mType = ok && { totil=">Sourcesite recovery ok";action="Update to $analyticIp"; }
test $mType = up && { totil=">Sourcesite changed";action="Changed to $analyticIp"; }
test $mType = no && { totil=">Sourcesite unable resolution";action="Temporary settings $tempIP"; }
msg=$(echo -e "##### $totil \nOrgsite: $soudom \n \
###### Domain: $(sed -r -e 's/^/ /' -e 's/\s/\n \# /g' <<<$domain) \n From: $localIp \n \
Time: $(date '+%Y-%m-%d %H:%M:%S')\n Action: $action")
}
hostFile=/etc/hosts
upstreamFile=/etc/nginx/webconf.d/http_upstreams.conf
uidFile=/etc/nginx/webconf.d/siteuidlist.txt
localIp=$(awk '/bind/{print $2}' /etc/nginx/node.conf | tr -d ';')
domainBackList=$(mktemp)
tempIP=127.0.0.1
if test -z $1; then
awk '/server/{print $2}' $upstreamFile | grep -E '[a-z]+' | sed -r 's/:[0-9]+//g' | sort | uniq > $domainBackList
else
echo $1 > $domainBackList
fi
[ ! -n $domainBackList ] && exit
reloadTag=0
while read soudom
do
domain=$(grep -w $soudom $uidFile | awk '{print $3}')
hostAnalyticIp=$(grep -w $soudom $hostFile | awk '{print $1}')
analyticIp=$(nslookup $soudom 2>/dev/null | grep -vE '#53' | awk '/Address/{print $2}' | head -1)
if test -z $analyticIp; then
if grep -qw $soudom $hostFile; then
echo "failure: hosts exist nothing to do $soudom"
#makeMsg xx
#report "$msg" "PLCDN-SUPPORT"
test ! -z "$hostAnalyticIp" && continue
#test "$hostAnalyticIp" = "$tempIP" && continue
#sed -r -i "/$soudom/s/$hostAnalyticIp/$tempIP/" $hostFile
else
echo -e "$tempIP\t $soudom" >> $hostFile
echo "unable resolution: add $tempIP to hosts in $soudom"
fi
makeMsg no
report "$msg" "PLCDN-SUPPORT"
else
if test "$hostAnalyticIp" = "$tempIP"; then
sed -r -i "/$soudom/s/$hostAnalyticIp/$analyticIp/" $hostFile
echo "recovery: update $hostAnalyticIp to $analyticIp in $soudom"
makeMsg ok
report "$msg" "PLCDN-SUPPORT"
let reloadTag++
elif test -z "$hostAnalyticIp"; then
echo -e "$analyticIp\t $soudom" >> $hostFile
echo "newSourceDom: add $analyticIp $soudom to hosts"
elif test "$hostAnalyticIp" != "$analyticIp" -a ! -z "$hostAnalyticIp"; then
nslookup $soudom 2>/dev/null | grep -qw $hostAnalyticIp && \
{ echo "multiple ip: one of them already exists hosts $soudom"; continue; }
sed -r -i "/$soudom/s/$hostAnalyticIp/$analyticIp/" $hostFile
echo "changed: customer update $hostAnalyticIp to $analyticIp in $soudom"
#makeMsg up
#report "$msg" "PLCDN-SUPPORT"
fi
fi
done < $domainBackList
test $reloadTag -ne 0 && /etc/init.d/nginx reload
trap cleanUp exit