1 # utility functions for ctdb event scripts
3 #######################################
4 # pull in a system config file, if any
7 if [ -f /etc/sysconfig/$name ]; then
9 elif [ -f /etc/default/$name ]; then
15 ######################################################
16 # simulate /sbin/service on platforms that don't have it
20 if [ -x /sbin/service ]; then
21 /sbin/service "$service_name" "$op"
22 elif [ -x /etc/init.d/$service_name ]; then
23 /etc/init.d/$service_name "$op"
24 elif [ -x /etc/rc.d/init.d/$service_name ]; then
25 /etc/init.d/$service_name "$op"
30 ######################################################
31 # wait for a command to return a zero exit status
32 # usage: ctdb_wait_command SERVICE_NAME <command>
33 ######################################################
37 [ -z "$wait_cmd" ] && return;
39 echo "`/bin/date` Waiting for service $service_name to start"
40 while [ $all_ok -eq 0 ]; do
41 $wait_cmd > /dev/null 2>&1 && all_ok=1
42 ctdb status > /dev/null 2>&1 || {
43 echo "ctdb daemon has died. Exiting wait for $service_name"
47 echo "`/bin/date` Local service $service_name is up"
51 ######################################################
52 # wait for a set of tcp ports
53 # usage: ctdb_wait_tcp_ports SERVICE_NAME <ports...>
54 ######################################################
55 ctdb_wait_tcp_ports() {
59 [ -z "$wait_ports" ] && return;
61 echo "`/bin/date` Waiting for tcp service $service_name to start"
62 while [ $all_ok -eq 0 ]; do
64 for p in $wait_ports; do
65 if [ -x /usr/bin/netcat ]; then
66 /usr/bin/netcat -z 127.0.0.1 $p || all_ok=0
67 elif [ -x /usr/bin/nc ]; then
68 /usr/bin/nc -z 127.0.0.1 $p || all_ok=0
70 echo "`date` netcat not found - cannot check tcp ports"
74 [ $all_ok -eq 1 ] || sleep 1
75 ctdb status > /dev/null 2>&1 || {
76 echo "ctdb daemon has died. Exiting tcp wait $service_name"
80 echo "`/bin/date` Local tcp services for $service_name are up"
85 ######################################################
86 # wait for a set of directories
87 # usage: ctdb_wait_directories SERVICE_NAME <directories...>
88 ######################################################
89 ctdb_wait_directories() {
93 [ -z "$wait_dirs" ] && return;
95 echo "`/bin/date` Waiting for local directories for $service_name"
96 while [ $all_ok -eq 0 ]; do
98 for d in $wait_dirs; do
101 [ $all_ok -eq 1 ] || sleep 1
102 ctdb status > /dev/null 2>&1 || {
103 echo "ctdb daemon has died. Exiting directory wait for $service_name"
107 echo "`/bin/date` Local directories for $service_name are available"
111 ######################################################
112 # check that a rpc server is registered with portmap
113 # and responding to requests
114 # usage: ctdb_check_rpc SERVICE_NAME PROGNUM VERSION
115 ######################################################
120 rpcinfo -u localhost $prognum $version > /dev/null || {
121 echo "`date` ERROR: $service_name not responding to rpc requests"
126 ######################################################
127 # check a set of directories is available
128 # usage: ctdb_check_directories SERVICE_NAME <directories...>
129 ######################################################
130 ctdb_check_directories() {
134 [ -z "$wait_dirs" ] && return;
135 for d in $wait_dirs; do
137 echo "`date` ERROR: $service_name directory $d not available"
143 ######################################################
144 # check a set of tcp ports
145 # usage: ctdb_check_tcp_ports SERVICE_NAME <ports...>
146 ######################################################
147 ctdb_check_tcp_ports() {
151 [ -z "$wait_ports" ] && return;
152 for p in $wait_ports; do
154 if [ -x /usr/bin/netcat ]; then
155 /usr/bin/netcat -z 127.0.0.1 $p || all_ok=0
156 elif [ -x /usr/bin/nc ]; then
157 /usr/bin/nc -z 127.0.0.1 $p || all_ok=0
159 [ $all_ok -eq 1 ] || {
160 echo "`date` ERROR: $service_name tcp port $p is not responding"
166 ######################################################
167 # check a command returns zero status
168 # usage: ctdb_check_command SERVICE_NAME <command>
169 ######################################################
170 ctdb_check_command() {
173 [ -z "$wait_cmd" ] && return;
174 $wait_cmd > /dev/null 2>&1 || {
175 echo "`date` ERROR: $service_name - $wait_cmd returned error"