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"
46 [ $all_ok -eq 1 ] || sleep 1
48 echo "`/bin/date` Local service $service_name is up"
52 ######################################################
53 # wait for a set of tcp ports
54 # usage: ctdb_wait_tcp_ports SERVICE_NAME <ports...>
55 ######################################################
56 ctdb_wait_tcp_ports() {
60 [ -z "$wait_ports" ] && return;
62 echo "`/bin/date` Waiting for tcp service $service_name to start"
63 while [ $all_ok -eq 0 ]; do
65 for p in $wait_ports; do
66 if [ -x /usr/bin/netcat ]; then
67 /usr/bin/netcat -z 127.0.0.1 $p || all_ok=0
68 elif [ -x /usr/bin/nc ]; then
69 /usr/bin/nc -z 127.0.0.1 $p || all_ok=0
71 echo "`date` netcat not found - cannot check tcp ports"
75 [ $all_ok -eq 1 ] || sleep 1
76 ctdb status > /dev/null 2>&1 || {
77 echo "ctdb daemon has died. Exiting tcp wait $service_name"
81 echo "`/bin/date` Local tcp services for $service_name are up"
86 ######################################################
87 # wait for a set of directories
88 # usage: ctdb_wait_directories SERVICE_NAME <directories...>
89 ######################################################
90 ctdb_wait_directories() {
94 [ -z "$wait_dirs" ] && return;
96 echo "`/bin/date` Waiting for local directories for $service_name"
97 while [ $all_ok -eq 0 ]; do
99 for d in $wait_dirs; do
100 [ -d $d ] || all_ok=0
102 [ $all_ok -eq 1 ] || sleep 1
103 ctdb status > /dev/null 2>&1 || {
104 echo "ctdb daemon has died. Exiting directory wait for $service_name"
108 echo "`/bin/date` Local directories for $service_name are available"
112 ######################################################
113 # check that a rpc server is registered with portmap
114 # and responding to requests
115 # usage: ctdb_check_rpc SERVICE_NAME PROGNUM VERSION
116 ######################################################
121 rpcinfo -u localhost $prognum $version > /dev/null || {
122 echo "`date` ERROR: $service_name not responding to rpc requests"
127 ######################################################
128 # check a set of directories is available
129 # usage: ctdb_check_directories SERVICE_NAME <directories...>
130 ######################################################
131 ctdb_check_directories() {
135 [ -z "$wait_dirs" ] && return;
136 for d in $wait_dirs; do
138 echo "`date` ERROR: $service_name directory $d not available"
144 ######################################################
145 # check a set of tcp ports
146 # usage: ctdb_check_tcp_ports SERVICE_NAME <ports...>
147 ######################################################
148 ctdb_check_tcp_ports() {
152 [ -z "$wait_ports" ] && return;
153 for p in $wait_ports; do
155 if [ -x /usr/bin/netcat ]; then
156 /usr/bin/netcat -z 127.0.0.1 $p || all_ok=0
157 elif [ -x /usr/bin/nc ]; then
158 /usr/bin/nc -z 127.0.0.1 $p || all_ok=0
160 [ $all_ok -eq 1 ] || {
161 echo "`date` ERROR: $service_name tcp port $p is not responding"
167 ######################################################
168 # check a command returns zero status
169 # usage: ctdb_check_command SERVICE_NAME <command>
170 ######################################################
171 ctdb_check_command() {
174 [ -z "$wait_cmd" ] && return;
175 $wait_cmd > /dev/null 2>&1 || {
176 echo "`date` ERROR: $service_name - $wait_cmd returned error"