-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdist_one.sh
More file actions
executable file
·93 lines (81 loc) · 2.25 KB
/
dist_one.sh
File metadata and controls
executable file
·93 lines (81 loc) · 2.25 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
#!/bin/bash
# 1.1.1.1=1.2.2.2 1.3.3.3
# 1.2.2.2=2.2.2.1 2.2.2.2
inform_stat() {
local id=$1
curl "http://my.down.speedtopcdn.com/index.php/ajax/distStat?id=$id" -x 127.0.0.1:80
}
oneLoop() {
list="$(grep ${ip}= ${joblist} | awk -F '=' '{print $2}')"
if [ -n "${list}" ]; then
for node in ${list}
do
chk="/tmp/cdn/${id}/${node}"
chkres=$(flock -x "/tmp/cdn/${id}/.lock" -c "[ ! -f ${chk} ] && touch ${chk} && echo Go")
if [ "${chkres}" = "Go" ]; then
bash $workingDir/dist_dl_one.sh ${joblist} ${user} ${id} "${url}" ${node} ${level} ${ip} ${size} ${sETag} ${snode} ${mode} ${md5} &
fi
done
jobs
echo "Waiting for jobs to finish"
wait
fi
}
sliceLoop() {
list="$(grep ${ip}= ${joblist} | awk -F '=' '{print $2}')"
if [ -n "${list}" ]; then
for node in ${list}
do
bash $workingDir/dist_dl_one.sh ${joblist} ${user} ${id} "${url}" ${node} ${level} ${ip} ${size} ${sETag} ${snode} ${mode} &
done
fi
}
joblist="$1"
user="$2"
id="$3"
url="$4"
ip="$5"
level="$6"
size="$7"
sETag=$8
mode=$9
md5=${10}
snode=$(/sbin/ifconfig | grep "inet addr" | grep -v 127.0.0.1 | awk '{print $2}' | tr -d "addr:" | head -1)
if [ "$ip" == "127.0.0.1" ]; then
ip="$snode"
sed -i -r "s/\<127.0.0.1\>/${snode}/" ${joblist}
fi
# tage=1 common distribution
# tage=2 section upload and distribution
# tage=9 delete node temp file
workingDir=$(cd $(dirname $0); pwd -P)
echo [`date "+%Y-%m-%d %H:%M:%S"`] $@ >> /tmp/cdnlog.log
if [ "$#" -lt "9" ];then
echo "Usage:"
echo "$(basename $0) joblist user id url ip level size sETag mode"
exit 1
fi
if [ "$level" = "0" ];then
rm -rf /tmp/cdn/${id}
rm -rf /tmp/cdnlogs/${id}
rm -rf /tmp/cdnlogs.ssh/${user}/${id}
mkdir -p /tmp/cdn/${id}
mkdir -p /tmp/cdnlogs/${id}
mkdir -p /tmp/cdnlogs.ssh/${user}/${id}
fi
let level++
test $mode -eq 2 -o $mode -eq 9 && sliceLoop
test $mode -eq 1 && oneLoop
if [ "$level" = "2" ];then
wait
#while :
#do
# backPros=$(ps -ef| grep "${url}" | grep -v grep | wc -l)
# if [ $backPros -eq 0 ]; then
inform_stat "$id"
# break
# else
# sleep 1 && continue
# fi
#done
fi