-
Notifications
You must be signed in to change notification settings - Fork 4
/
glfs-health.sh
executable file
·121 lines (89 loc) · 2.21 KB
/
glfs-health.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
#
# Usage: $0 VOLUME [HOST [TRANSPORT]]
#
DEFAULT_HOST=localhost
DEFAULT_PORT=6996
DEFAULT_TYPE=tcp
DEFAULT_NAME=test
mnt=/tmp/.glusterfs.mnt.$$;
log=/tmp/.glusterfs.log.$$;
pid=/tmp/.glusterfs.pid.$$;
glfs=`which glusterfs 2>/dev/null`;
glfs=/usr/local/sbin/glusterfs;
function parse_cmd_args()
{
HOST=$DEFAULT_HOST;
PORT=$DEFAULT_PORT;
TYPE=$DEFAULT_TYPE;
NAME=$DEFAULT_NAME;
if test "x$1" != "x"; then
NAME=$1
fi
if test "x$2" != "x"; then
HOST=$2
fi
if test "x$3" != "x"; then
TYPE=$3
fi
}
function glfs()
{
mkdir -p $mnt;
$glfs -s $HOST --volfile-id $NAME -l $log -p $pid -LTRACE $mnt &
sleep 0.3;
}
function cleanup()
{
[ -f $pid ] && kill -TERM `cat $pid`;
umount -l $mnt >/dev/null 2>&1;
rm -rf $conf $pid #$log;
rmdir $mnt;
}
function watsup()
{
ans="Unknown Error"
for i in $(seq 1 10); do
if grep -iq "failed to fetch volume file (key:$NAME)" $log; then
ans="Volume $NAME does not exist"
break;
fi
if grep -iq 'failed to get the port number for remote subvolume' $log; then
ans="Volume $NAME is not started"
break;
fi
if grep -iq 'DNS resolution failed on host' $log; then
ans=$(sed -n s/'.*DNS resolution failed on host '/'DNS resolution failed: '/p $log | tail -n 1);
break
fi
if grep -iq 'connection refused' $log; then
ans=$(sed -n s/'.*connection to \([^ ]*\) failed (Connection refused).*'/'Brick \1 crashed'/p $log | tail -n 1)
break
fi
if grep -iq ': got RPC_CLNT_CONNECT' $log; then
ans="Server Unresponsive"
fi
if grep -iq 'socket header signature does not match :O' $log; then
ans="Unknown service encountered"
break
fi
if grep -iq ': SETVOLUME on remote-host failed:' $log; then
ans=$(sed -n s/'.*: SETVOLUME on remote-host failed: '//p $log | tail -n 1);
break
fi
if grep -iq 'attached to remote volume' $log; then
ans="OK"
break
fi
sleep 0.3
done
echo $ans
}
function main()
{
trap cleanup EXIT;
parse_cmd_args "$@"
glfs;
watsup;
}
main "$@"