1 # utility functions for ctdb event scripts
3 PATH=/bin:/usr/bin:/usr/sbin:/sbin:$PATH
5 #######################################
6 # pull in a system config file, if any
10 foo="${service_config:-${service_name}}"
11 if [ -n "$foo" ] ; then
14 elif [ "$1" != "ctdb" ] ; then
19 if [ -f /etc/sysconfig/$1 ]; then
21 elif [ -f /etc/default/$1 ]; then
23 elif [ -f $CTDB_BASE/sysconfig/$1 ]; then
24 . $CTDB_BASE/sysconfig/$1
32 ##############################################################
33 # determine on what type of system (init style) we are running
35 # only do detection if not already set:
36 test "x$CTDB_INIT_STYLE" != "x" && return
38 if [ -x /sbin/startproc ]; then
39 CTDB_INIT_STYLE="suse"
40 elif [ -x /sbin/start-stop-daemon ]; then
41 CTDB_INIT_STYLE="debian"
43 CTDB_INIT_STYLE="redhat"
47 ######################################################
48 # simulate /sbin/service on platforms that don't have it
53 # do nothing, when no service was specified
54 [ -z "$_service_name" ] && return
56 if [ -x /sbin/service ]; then
57 /sbin/service "$_service_name" "$_op"
58 elif [ -x /etc/init.d/$_service_name ]; then
59 /etc/init.d/$_service_name "$_op"
60 elif [ -x /etc/rc.d/init.d/$_service_name ]; then
61 /etc/rc.d/init.d/$_service_name "$_op"
65 ######################################################
66 # simulate /sbin/service (niced) on platforms that don't have it
71 # do nothing, when no service was specified
72 [ -z "$_service_name" ] && return
74 if [ -x /sbin/service ]; then
75 nice /sbin/service "$_service_name" "$_op"
76 elif [ -x /etc/init.d/$_service_name ]; then
77 nice /etc/init.d/$_service_name "$_op"
78 elif [ -x /etc/rc.d/init.d/$_service_name ]; then
79 nice /etc/rc.d/init.d/$_service_name "$_op"
83 ######################################################
84 # wait for a command to return a zero exit status
85 # usage: ctdb_wait_command SERVICE_NAME <command>
86 ######################################################
90 [ -z "$wait_cmd" ] && return;
92 echo "Waiting for service $service_name to start"
93 while [ $all_ok -eq 0 ]; do
94 $wait_cmd > /dev/null 2>&1 && all_ok=1
95 ctdb status > /dev/null 2>&1 || {
96 echo "ctdb daemon has died. Exiting wait for $service_name"
99 [ $all_ok -eq 1 ] || sleep 1
101 echo "Local service $service_name is up"
105 ######################################################
106 # wait for a set of tcp ports
107 # usage: ctdb_wait_tcp_ports SERVICE_NAME <ports...>
108 ######################################################
109 ctdb_wait_tcp_ports() {
113 [ -z "$wait_ports" ] && return;
115 echo "Waiting for tcp service $service_name to start"
116 while [ $all_ok -eq 0 ]; do
118 for p in $wait_ports; do
119 if [ -x /usr/bin/netcat ]; then
120 /usr/bin/netcat -z 127.0.0.1 $p > /dev/null || all_ok=0
121 elif [ -x /usr/bin/nc ]; then
122 /usr/bin/nc -z 127.0.0.1 $p > /dev/null || all_ok=0
123 elif [ -x /usr/bin/netstat ]; then
124 (netstat -a -n | egrep "0.0.0.0:$p[[:space:]]*LISTEN" > /dev/null) || all_ok=0
125 elif [ -x /bin/netstat ]; then
126 (netstat -a -n | egrep "0.0.0.0:$p[[:space:]]*LISTEN" > /dev/null) || all_ok=0
128 echo "No tool to check tcp ports availabe. can not check in ctdb_wait_tcp_ports"
132 [ $all_ok -eq 1 ] || sleep 1
133 ctdb status > /dev/null 2>&1 || {
134 echo "ctdb daemon has died. Exiting tcp wait $service_name"
138 echo "Local tcp services for $service_name are up"
142 ######################################################
143 # check that a rpc server is registered with portmap
144 # and responding to requests
145 # usage: ctdb_check_rpc SERVICE_NAME PROGNUM VERSION
146 ######################################################
152 ctdb_check_rpc_out=$(rpcinfo -u localhost $prognum $version 2>&1)
153 if [ $? -ne 0 ] ; then
154 ctdb_check_rpc_out="ERROR: $progname failed RPC check:
156 echo "$ctdb_check_rpc_out"
161 ######################################################
162 # check a set of directories is available
163 # return 1 on a missing directory
164 # usage: ctdb_check_directories_probe SERVICE_NAME <directories...>
165 ######################################################
166 ctdb_check_directories_probe() {
167 while IFS="" read d ; do
173 [ -d "${d}/." ] || return 1
178 ######################################################
179 # check a set of directories is available
180 # usage: ctdb_check_directories SERVICE_NAME <directories...>
181 ######################################################
182 ctdb_check_directories() {
183 n="${1:-${service_name}}"
184 ctdb_check_directories_probe || {
185 echo "ERROR: $n directory \"$d\" not available"
190 ######################################################
191 # check a set of tcp ports
192 # usage: ctdb_check_tcp_ports <ports...>
193 ######################################################
195 # This flag file is created when a service is initially started. It
196 # is deleted the first time TCP port checks for that service succeed.
197 # Until then ctdb_check_tcp_ports() prints a more subtle "error"
198 # message if a port check fails.
199 _ctdb_check_tcp_common ()
201 _ctdb_service_started_file="$ctdb_fail_dir/$service_name.started"
204 ctdb_check_tcp_init ()
206 _ctdb_check_tcp_common
207 mkdir -p "${_ctdb_service_started_file%/*}" # dirname
208 touch "$_ctdb_service_started_file"
211 ctdb_check_tcp_ports()
213 if [ -z "$1" ] ; then
214 echo "INTERNAL ERROR: ctdb_check_tcp_ports - no ports specified"
218 # Set default value for CTDB_TCP_PORT_CHECKS if unset.
219 # If any of these defaults are unsupported then this variable can
220 # be overridden in /etc/sysconfig/ctdb or via a file in
221 # /etc/ctdb/rc.local.d/.
222 : ${CTDB_TCP_PORT_CHECKERS:=ctdb nmap netstat}
224 for _c in $CTDB_TCP_PORT_CHECKERS ; do
225 ctdb_check_tcp_ports_$_c "$@"
228 rm -f "$_ctdb_service_started_file"
232 _ctdb_check_tcp_common
233 if [ ! -f "$_ctdb_service_started_file" ] ; then
234 echo "ERROR: $service_name tcp port $_p is not responding"
236 $ctdb_check_tcp_ports_debug
239 echo "INFO: $service_name tcp port $_p is not responding"
252 echo "INTERNAL ERROR: ctdb_check_ports - no working checkers in CTDB_TCP_PORT_CHECKERS=\"$CTDB_TCP_PORT_CHECKERS\""
257 ctdb_check_tcp_ports_netstat ()
259 _cmd='netstat -l -t -n'
261 if [ $? -eq 127 ] ; then
262 # netstat probably not installed - unlikely?
263 ctdb_check_tcp_ports_debug="$_ns"
267 for _p ; do # process each function argument (port)
268 for _a in '0\.0\.0\.0' '::' ; do
269 _pat="[[:space:]]${_a}:${_p}[[:space:]]+[^[:space:]]+[[:space:]]+LISTEN"
270 if echo "$_ns" | grep -E -q "$_pat" ; then
271 # We matched the port, so process next port
276 # We didn't match the port, so flag an error.
277 ctdb_check_tcp_ports_debug="$_cmd shows this output:
285 ctdb_check_tcp_ports_nmap ()
287 # nmap wants a comma-separated list of ports
290 _ports="${_ports}${_ports:+,}${_p}"
293 _cmd="nmap -n -oG - -PS 127.0.0.1 -p $_ports"
295 _nmap_out=$($_cmd 2>&1)
296 if [ $? -eq 127 ] ; then
297 # nmap probably not installed
298 ctdb_check_tcp_ports_debug="$_nmap_out"
302 # get the port-related output
303 _port_info=$(echo "$_nmap_out" | sed -n -r -e 's@^.*Ports:[[:space:]]@@p')
306 # looking for something like this:
307 # 445/open/tcp//microsoft-ds///
308 # possibly followed by a comma
310 case "$_port_info" in
311 # The info we're after must be either at the beginning of
312 # the string or it must follow a space.
315 # Nope, flag an error...
316 ctdb_check_tcp_ports_debug="$_cmd shows this output:
325 # Use the new "ctdb checktcpport" command to check the port.
326 # This is very cheap.
327 ctdb_check_tcp_ports_ctdb ()
329 for _p ; do # process each function argument (port)
330 _cmd="ctdb checktcpport $_p"
335 ctdb_check_tcp_ports_debug="\"$_cmd\" was able to bind to port"
339 # Couldn't bind, something already listening, next port...
343 ctdb_check_tcp_ports_debug="$_cmd (exited with $_ret) with output:
345 # assume not implemented
353 ######################################################
354 # check a unix socket
355 # usage: ctdb_check_unix_socket SERVICE_NAME <socket_path>
356 ######################################################
357 ctdb_check_unix_socket() {
359 [ -z "$socket_path" ] && return
361 if ! netstat --unix -a -n | grep -q "^unix.*LISTEN.*${socket_path}$"; then
362 echo "ERROR: $service_name socket $socket_path not found"
367 ######################################################
368 # check a command returns zero status
369 # usage: ctdb_check_command SERVICE_NAME <command>
370 ######################################################
371 ctdb_check_command() {
374 [ -z "$wait_cmd" ] && return;
375 $wait_cmd > /dev/null 2>&1 || {
376 echo "ERROR: $service_name - $wait_cmd returned error"
381 ################################################
382 # kill off any TCP connections with the given IP
383 ################################################
384 kill_tcp_connections() {
389 connfile="$CTDB_VARDIR/state/connections.$_IP"
390 netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
391 netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
393 while read dest src; do
394 srcip=`echo $src | sed -e "s/:[^:]*$//"`
395 srcport=`echo $src | sed -e "s/^.*://"`
396 destip=`echo $dest | sed -e "s/:[^:]*$//"`
397 destport=`echo $dest | sed -e "s/^.*://"`
398 echo "Killing TCP connection $srcip:$srcport $destip:$destport"
399 ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
401 # we only do one-way killtcp for CIFS
403 # for all others we do 2-way
405 ctdb killtcp $destip:$destport $srcip:$srcport >/dev/null 2>&1 || _failed=1
408 _killcount=`expr $_killcount + 1`
412 [ $_failed = 0 ] || {
413 echo "Failed to send killtcp control"
416 [ $_killcount -gt 0 ] || {
420 while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
422 _count=`expr $_count + 1`
423 [ $_count -gt 3 ] && {
424 echo "Timed out killing tcp connections for IP $_IP"
428 echo "killed $_killcount TCP connections to released IP $_IP"
431 ##################################################################
432 # kill off the local end for any TCP connections with the given IP
433 ##################################################################
434 kill_tcp_connections_local_only() {
439 connfile="$CTDB_VARDIR/state/connections.$_IP"
440 netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
441 netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
443 while read dest src; do
444 srcip=`echo $src | sed -e "s/:[^:]*$//"`
445 srcport=`echo $src | sed -e "s/^.*://"`
446 destip=`echo $dest | sed -e "s/:[^:]*$//"`
447 destport=`echo $dest | sed -e "s/^.*://"`
448 echo "Killing TCP connection $srcip:$srcport $destip:$destport"
449 ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
450 _killcount=`expr $_killcount + 1`
454 [ $_failed = 0 ] || {
455 echo "Failed to send killtcp control"
458 [ $_killcount -gt 0 ] || {
462 while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
464 _count=`expr $_count + 1`
465 [ $_count -gt 3 ] && {
466 echo "Timed out killing tcp connections for IP $_IP"
470 echo "killed $_killcount TCP connections to released IP $_IP"
473 ##################################################################
474 # tickle any TCP connections with the given IP
475 ##################################################################
476 tickle_tcp_connections() {
481 connfile="$CTDB_VARDIR/state/connections.$_IP"
482 netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
483 netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
485 while read dest src; do
486 srcip=`echo $src | sed -e "s/:[^:]*$//"`
487 srcport=`echo $src | sed -e "s/^.*://"`
488 destip=`echo $dest | sed -e "s/:[^:]*$//"`
489 destport=`echo $dest | sed -e "s/^.*://"`
490 echo "Tickle TCP connection $srcip:$srcport $destip:$destport"
491 ctdb tickle $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
492 echo "Tickle TCP connection $destip:$destport $srcip:$srcport"
493 ctdb tickle $destip:$destport $srcip:$srcport >/dev/null 2>&1 || _failed=1
497 [ $_failed = 0 ] || {
498 echo "Failed to send tickle control"
503 ########################################################
504 # start/stop the nfs service on different platforms
505 ########################################################
508 [ -x /etc/init.d/nfsserver ] && {
511 [ -x /etc/init.d/nfslock ] && {
519 service nfsserver start
522 service nfsserver stop > /dev/null 2>&1
525 echo 0 >/proc/fs/nfsd/threads
526 service nfsserver stop > /dev/null 2>&1
528 service nfsserver start
535 service nfslock start
539 service nfs stop > /dev/null 2>&1
540 service nfslock stop > /dev/null 2>&1
543 echo 0 >/proc/fs/nfsd/threads
544 service nfs stop > /dev/null 2>&1
545 service nfslock stop > /dev/null 2>&1
547 service nfslock start
553 echo "Unknown platform. NFS is not supported with ctdb"
559 ########################################################
560 # start/stop the nfs lockmanager service on different platforms
561 ########################################################
562 startstop_nfslock() {
564 [ -x /etc/init.d/nfsserver ] && {
567 [ -x /etc/init.d/nfslock ] && {
573 # for sles there is no service for lockmanager
574 # so we instead just shutdown/restart nfs
577 service nfsserver start
580 service nfsserver stop > /dev/null 2>&1
583 service nfsserver stop
584 service nfsserver start
591 service nfslock start
594 service nfslock stop > /dev/null 2>&1
598 service nfslock start
603 echo "Unknown platform. NFS locking is not supported with ctdb"
609 # better use delete_ip_from_iface() together with add_ip_to_iface
610 # remove_ip should be removed in future
612 local _ip_maskbits=$1
614 local _ip=`echo "$_ip_maskbits" | cut -d '/' -f1`
615 local _maskbits=`echo "$_ip_maskbits" | cut -d '/' -f2`
617 delete_ip_from_iface "$_iface" "$_ip" "$_maskbits"
626 local _state_dir="$CTDB_VARDIR/state/interface_modify"
627 local _lockfile="$_state_dir/$_iface.flock"
628 local _readd_base="$_state_dir/$_iface.readd.d"
630 mkdir -p $_state_dir || {
632 echo "Failed to mkdir -p $_state_dir - $ret"
636 test -f $_lockfile || {
640 flock --timeout 30 $_lockfile $CTDB_BASE/interface_modify.sh add "$_iface" "$_ip" "$_maskbits" "$_readd_base"
644 delete_ip_from_iface()
649 local _state_dir="$CTDB_VARDIR/state/interface_modify"
650 local _lockfile="$_state_dir/$_iface.flock"
651 local _readd_base="$_state_dir/$_iface.readd.d"
653 mkdir -p $_state_dir || {
655 echo "Failed to mkdir -p $_state_dir - $ret"
659 test -f $_lockfile || {
663 flock --timeout 30 $_lockfile $CTDB_BASE/interface_modify.sh delete "$_iface" "$_ip" "$_maskbits" "$_readd_base"
667 setup_iface_ip_readd_script()
672 local _readd_script=$4
673 local _state_dir="$CTDB_VARDIR/state/interface_modify"
674 local _lockfile="$_state_dir/$_iface.flock"
675 local _readd_base="$_state_dir/$_iface.readd.d"
677 mkdir -p $_state_dir || {
679 echo "Failed to mkdir -p $_state_dir - $ret"
683 test -f $_lockfile || {
687 flock --timeout 30 $_lockfile $CTDB_BASE/interface_modify.sh readd_script "$_iface" "$_ip" "$_maskbits" "$_readd_base" "$_readd_script"
691 ########################################################
692 # some simple logic for counting events - per eventscript
693 # usage: ctdb_counter_init
695 # ctdb_check_counter_limit <limit>
696 # ctdb_check_counter_limit succeeds when count >= <limit>
697 ########################################################
698 _ctdb_counter_common () {
699 _counter_file="$ctdb_fail_dir/$service_name"
700 mkdir -p "${_counter_file%/*}" # dirname
702 ctdb_counter_init () {
707 ctdb_counter_incr () {
711 echo -n 1 >> "$_counter_file"
713 ctdb_check_counter_limit () {
716 _limit="${1:-${service_fail_limit}}"
720 _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
721 if [ $_size -ge $_limit ] ; then
722 echo "ERROR: more than $_limit consecutive failures for $service_name, marking cluster unhealthy"
724 elif [ $_size -gt 0 -a -z "$_quiet" ] ; then
725 echo "WARNING: less than $_limit consecutive failures ($_size) for $service_name, not unhealthy yet"
728 ctdb_check_counter_equal () {
734 _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
735 if [ $_size -eq $_limit ] ; then
741 ########################################################
743 ctdb_spool_dir="/var/spool/ctdb"
744 ctdb_status_dir="$ctdb_spool_dir/status"
745 ctdb_fail_dir="$ctdb_spool_dir/failcount"
746 ctdb_active_dir="$ctdb_spool_dir/active"
750 echo "node is \"$1\", \"${script_name}\" reports problem: $(cat $2)"
755 if [ -r "$ctdb_status_dir/$script_name/unhealthy" ] ; then
756 log_status_cat "unhealthy" "$ctdb_status_dir/$script_name/unhealthy"
758 elif [ -r "$ctdb_status_dir/$script_name/banned" ] ; then
759 log_status_cat "banned" "$ctdb_status_dir/$script_name/banned"
768 d="$ctdb_status_dir/$script_name"
775 for i in "banned" "unhealthy" ; do
782 ctdb_service_needs_reconfigure ()
784 [ -e "$ctdb_status_dir/$service_name/reconfigure" ]
787 ctdb_service_set_reconfigure ()
789 d="$ctdb_status_dir/$service_name"
794 ctdb_service_unset_reconfigure ()
796 rm -f "$ctdb_status_dir/$service_name/reconfigure"
799 ctdb_service_reconfigure ()
801 echo "Reconfiguring service \"$service_name\"..."
802 if [ -n "$service_reconfigure" ] ; then
803 eval $service_reconfigure
805 service "$service_name" restart
807 ctdb_service_unset_reconfigure
811 ctdb_compat_managed_service ()
813 if [ "$1" = "yes" ] ; then
818 is_ctdb_managed_service ()
820 _service_name="${1:-${service_name}}"
822 t=" $CTDB_MANAGED_SERVICES "
824 ctdb_compat_managed_service "$CTDB_MANAGES_VSFTPD" "vsftpd"
825 ctdb_compat_managed_service "$CTDB_MANAGES_SAMBA" "samba"
826 ctdb_compat_managed_service "$CTDB_MANAGES_SCP" "scp"
827 ctdb_compat_managed_service "$CTDB_MANAGES_WINBIND" "winbind"
828 ctdb_compat_managed_service "$CTDB_MANAGES_HTTPD" "httpd"
829 ctdb_compat_managed_service "$CTDB_MANAGES_ISCSI" "iscsi"
830 ctdb_compat_managed_service "$CTDB_MANAGES_CLAMD" "clamd"
831 ctdb_compat_managed_service "$CTDB_MANAGES_NFS" "nfs"
832 ctdb_compat_managed_service "$CTDB_MANAGES_NFS" "nfs-ganesha-gpfs"
834 # Returns 0 if "<space>$_service_name<space>" appears in $t
835 [ "${t#* ${_service_name} }" != "${t}" ]
838 ctdb_start_stop_service ()
840 # Do nothing unless configured to...
841 [ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] || return 0
843 _service_name="${1:-${service_name}}"
845 [ "$event_name" = "monitor" ] || return 0
847 _active="$ctdb_active_dir/$_service_name"
848 if is_ctdb_managed_service "$_service_name"; then
849 if ! [ -e "$_active" ] ; then
850 echo "Starting service $_service_name"
851 ctdb_service_start || exit $?
852 mkdir -p "$ctdb_active_dir"
857 if [ -e "$_active" ] ; then
858 echo "Stopping service $_service_name"
859 ctdb_service_stop || exit $?
866 ctdb_service_start ()
868 if [ -n "$service_start" ] ; then
869 eval $service_start || return $?
871 service "$service_name" start || return $?
879 if [ -n "$service_stop" ] ; then
882 service "$service_name" stop
886 ctdb_standard_event_handler ()
901 ipv4_host_addr_to_net_addr()
906 local HOST0=$(echo $HOST | awk -F . '{print $4}')
907 local HOST1=$(echo $HOST | awk -F . '{print $3}')
908 local HOST2=$(echo $HOST | awk -F . '{print $2}')
909 local HOST3=$(echo $HOST | awk -F . '{print $1}')
911 local HOST_NUM=$(( $HOST0 + $HOST1 * 256 + $HOST2 * (256 ** 2) + $HOST3 * (256 ** 3) ))
913 local MASK_NUM=$(( ( (2**32 - 1) * (2**(32 - $MASKBITS)) ) & (2**32 - 1) ))
915 local NET_NUM=$(( $HOST_NUM & $MASK_NUM))
917 local NET0=$(( $NET_NUM & 255 ))
918 local NET1=$(( ($NET_NUM & (255 * 256)) / 256 ))
919 local NET2=$(( ($NET_NUM & (255 * 256**2)) / 256**2 ))
920 local NET3=$(( ($NET_NUM & (255 * 256**3)) / 256**3 ))
922 echo "$NET3.$NET2.$NET1.$NET0"
925 ipv4_maskbits_to_net_mask()
929 local MASK_NUM=$(( ( (2**32 - 1) * (2**(32 - $MASKBITS)) ) & (2**32 - 1) ))
931 local MASK0=$(( $MASK_NUM & 255 ))
932 local MASK1=$(( ($MASK_NUM & (255 * 256)) / 256 ))
933 local MASK2=$(( ($MASK_NUM & (255 * 256**2)) / 256**2 ))
934 local MASK3=$(( ($MASK_NUM & (255 * 256**3)) / 256**3 ))
936 echo "$MASK3.$MASK2.$MASK1.$MASK0"
944 local N=`echo $ADDR | sed -e 's/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*//'`
945 test -n "$N" && fail=1
947 local ADDR0=$(echo $ADDR | awk -F . '{print $4}')
948 local ADDR1=$(echo $ADDR | awk -F . '{print $3}')
949 local ADDR2=$(echo $ADDR | awk -F . '{print $2}')
950 local ADDR3=$(echo $ADDR | awk -F . '{print $1}')
952 test "$ADDR0" -gt 255 && fail=1
953 test "$ADDR1" -gt 255 && fail=1
954 test "$ADDR2" -gt 255 && fail=1
955 test "$ADDR3" -gt 255 && fail=1
957 test x"$fail" != x"0" && {
958 #echo "IPv4: '$ADDR' is not a valid address"
965 # iptables doesn't like being re-entered, so flock-wrap it.
968 flock -w 30 /var/ctdb/iptables-ctdb.flock /sbin/iptables "$@"
971 ########################################################
973 ########################################################
975 # Temporary directory for tickles.
976 tickledir="$CTDB_VARDIR/state/tickles"
977 mkdir -p "$tickledir"
983 mkdir -p "$tickledir" # Just in case
986 _pnn=$(ctdb pnn) ; _pnn=${_pnn#PNN:}
988 # What public IPs do I hold?
989 _ips=$(ctdb -Y ip | awk -F: -v pnn=$_pnn '$3 == pnn {print $2}')
991 # IPs as a regexp choice
992 _ipschoice="($(echo $_ips | sed -e 's/ /|/g' -e 's/\./\\\\./g'))"
994 # Record connections to our public IPs in a temporary file
995 _my_connections="${tickledir}/${_port}.connections"
996 rm -f "$_my_connections"
998 awk -v destpat="^${_ipschoice}:${_port}\$" \
999 '$1 == "tcp" && $6 == "ESTABLISHED" && $4 ~ destpat {print $5, $4}' |
1000 sort >"$_my_connections"
1002 # Record our current tickles in a temporary file
1003 _my_tickles="${tickledir}/${_port}.tickles"
1004 rm -f "$_my_tickles"
1005 for _i in $_ips ; do
1006 ctdb -Y gettickles $_i $_port |
1007 awk -F: 'NR > 1 { printf "%s:%s %s:%s\n", $2, $3, $4, $5 }'
1009 sort >"$_my_tickles"
1011 # Add tickles for connections that we haven't already got tickles for
1012 comm -23 "$_my_connections" "$_my_tickles" |
1013 while read _src _dst ; do
1014 ctdb addtickle $_src $_dst
1017 # Remove tickles for connections that are no longer there
1018 comm -13 "$_my_connections" "$_my_tickles" |
1019 while read _src _dst ; do
1020 ctdb deltickle $_src $_dst
1023 rm -f "$_my_connections" "$_my_tickles"
1026 ########################################################
1027 # load a site local config file
1028 ########################################################
1030 [ -x $CTDB_BASE/rc.local ] && {
1031 . $CTDB_BASE/rc.local
1034 [ -d $CTDB_BASE/rc.local.d ] && {
1035 for i in $CTDB_BASE/rc.local.d/* ; do
1036 [ -x "$i" ] && . "$i"
1040 script_name="${0##*/}" # basename
1041 service_name="$script_name" # default is just the script name
1042 service_fail_limit=1