-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq_namenode.sh
executable file
·73 lines (65 loc) · 1.52 KB
/
q_namenode.sh
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
#!/bin/bash
usage(){
echo "Usage: $0 hostname port"
echo "Note: hostname can not be ip"
exit 1
}
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
# invoke usage
# call usage() function if filename not supplied
[[ $# -ne 2 ]] && usage
host=$1
port=$2
zkhosts=("ubuntu" "ubuntu" "ubuntu")
username="hadoop"
CONN_TIMEOUT=5
# check hostname
if valid_ip $1; then
usage
fi
unreached_hosts=0
for element in "${zkhosts[@]}"; do
echo "try to connect $element to execute fence!"
ssh -o ConnectTimeout=$CONN_TIMEOUT $username@$element "q_datanode.sh $host $port" &
done
# wait the jobs
for job in `jobs -p`
do
wait $job
echo "ssh datanode return $?"
if [ $? -eq 0 ]; then
let "unreached_hosts+=1"
elif [ $? -eq 2 ]; then
echo "Can not ssh to datanode, ret = 2!"
elif [ $? -eq 1 ]; then
exit 0
elif [ $? -eq 3 ]; then
exit 1
elif [ $? -eq 255 ]; then
echo "Can not ssh to datanode, ret= 255!"
fi
done
zknum=${#zkhosts[@]}
let qurom=zknum/2
echo "$unreached_hosts zks kill the active namenode successfully!"
if [ $unreached_hosts -gt $qurom ];then
echo "Fence successfully!"
exit 0
else
echo "Not enough zks kill the active namenode!"
exit 1
fi