blob: f7ffd01079f58f26b69a9eb9625d7adb195b8428 (
plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# utility functions for ctdb event scripts
#######################################
# pull in a system config file, if any
loadconfig() {
name="$1"
if [ -f /etc/sysconfig/$name ]; then
. /etc/sysconfig/$name
elif [ -f /etc/default/$name ]; then
. /etc/default/$name
elif [ -f /etc/ctdb/sysconfig/$name ]; then
. /etc/ctdb/sysconfig/$name
fi
}
######################################################
# simulate /sbin/service on platforms that don't have it
service() {
service_name="$1"
op="$2"
if [ -x /sbin/service ]; then
/sbin/service "$service_name" "$op"
elif [ -x /etc/init.d/$service_name ]; then
/etc/init.d/$service_name "$op"
elif [ -x /etc/rc.d/init.d/$service_name ]; then
/etc/rc.d/init.d/$service_name "$op"
fi
}
######################################################
# wait for a command to return a zero exit status
# usage: ctdb_wait_command SERVICE_NAME <command>
######################################################
ctdb_wait_command() {
service_name="$1"
wait_cmd="$2"
[ -z "$wait_cmd" ] && return;
all_ok=0
echo "`/bin/date` Waiting for service $service_name to start"
while [ $all_ok -eq 0 ]; do
$wait_cmd > /dev/null 2>&1 && all_ok=1
ctdb status > /dev/null 2>&1 || {
echo "ctdb daemon has died. Exiting wait for $service_name"
exit 1
}
[ $all_ok -eq 1 ] || sleep 1
done
echo "`/bin/date` Local service $service_name is up"
}
######################################################
# wait for a set of tcp ports
# usage: ctdb_wait_tcp_ports SERVICE_NAME <ports...>
######################################################
ctdb_wait_tcp_ports() {
service_name="$1"
shift
wait_ports="$*"
[ -z "$wait_ports" ] && return;
all_ok=0
echo "`/bin/date` Waiting for tcp service $service_name to start"
while [ $all_ok -eq 0 ]; do
all_ok=1
for p in $wait_ports; do
if [ -x /usr/bin/netcat ]; then
/usr/bin/netcat -z 127.0.0.1 $p > /dev/null || all_ok=0
elif [ -x /usr/bin/nc ]; then
/usr/bin/nc -z 127.0.0.1 $p > /dev/null || all_ok=0
elif [ -x /usr/bin/netstat ]; then
(/usr/bin/netstat -a -n | egrep "0.0.0.0:$p\s*LISTEN" > /dev/null) || all_ok=0
else
echo "`date` - No tool to check tcp ports availabe. can not check in ctdb_wait_tcp_ports"
return
fi
done
[ $all_ok -eq 1 ] || sleep 1
ctdb status > /dev/null 2>&1 || {
echo "ctdb daemon has died. Exiting tcp wait $service_name"
exit 1
}
done
echo "`/bin/date` Local tcp services for $service_name are up"
}
######################################################
# wait for a set of directories
# usage: ctdb_wait_directories SERVICE_NAME <directories...>
######################################################
ctdb_wait_directories() {
service_name="$1"
shift
wait_dirs="$*"
[ -z "$wait_dirs" ] && return;
all_ok=0
echo "`/bin/date` Waiting for local directories for $service_name"
while [ $all_ok -eq 0 ]; do
all_ok=1
for d in $wait_dirs; do
[ -d $d ] || all_ok=0
done
[ $all_ok -eq 1 ] || sleep 1
ctdb status > /dev/null 2>&1 || {
echo "ctdb daemon has died. Exiting directory wait for $service_name"
exit 1
}
done
echo "`/bin/date` Local directories for $service_name are available"
}
######################################################
# check that a rpc server is registered with portmap
# and responding to requests
# usage: ctdb_check_rpc SERVICE_NAME PROGNUM VERSION
######################################################
ctdb_check_rpc() {
service_name="$1"
prognum="$2"
version="$3"
rpcinfo -u localhost $prognum $version > /dev/null || {
echo "`date` ERROR: $service_name not responding to rpc requests"
exit 1
}
}
######################################################
# check a set of directories is available
# usage: ctdb_check_directories SERVICE_NAME <directories...>
######################################################
ctdb_check_directories() {
service_name="$1"
shift
wait_dirs="$*"
[ -z "$wait_dirs" ] && return;
for d in $wait_dirs; do
[ -d $d ] || {
echo "`date` ERROR: $service_name directory $d not available"
exit 1
}
done
}
######################################################
# check a set of tcp ports
# usage: ctdb_check_tcp_ports SERVICE_NAME <ports...>
######################################################
ctdb_check_tcp_ports() {
service_name="$1"
shift
wait_ports="$*"
[ -z "$wait_ports" ] && return;
for p in $wait_ports; do
all_ok=1
if [ -x /usr/bin/netcat ]; then
/usr/bin/netcat -z 127.0.0.1 $p > /dev/null || all_ok=0
elif [ -x /usr/bin/nc ]; then
/usr/bin/nc -z 127.0.0.1 $p > /dev/null || all_ok=0
elif [ -x /usr/bin/netstat ]; then
(/usr/bin/netstat -a -n | egrep "0.0.0.0:$p .*LISTEN" > /dev/null ) || all_ok=0
fi
[ $all_ok -eq 1 ] || {
echo "`date` ERROR: $service_name tcp port $p is not responding"
exit 1
}
done
}
######################################################
# check a command returns zero status
# usage: ctdb_check_command SERVICE_NAME <command>
######################################################
ctdb_check_command() {
service_name="$1"
wait_cmd="$2"
[ -z "$wait_cmd" ] && return;
$wait_cmd > /dev/null 2>&1 || {
echo "`date` ERROR: $service_name - $wait_cmd returned error"
exit 1
}
}
|