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 _ctdb_check_tcp_common
229 rm -f "$_ctdb_service_started_file"
233 _ctdb_check_tcp_common
234 if [ ! -f "$_ctdb_service_started_file" ] ; then
235 echo "ERROR: $service_name tcp port $_p is not responding"
237 $ctdb_check_tcp_ports_debug
240 echo "INFO: $service_name tcp port $_p is not responding"
253 echo "INTERNAL ERROR: ctdb_check_ports - no working checkers in CTDB_TCP_PORT_CHECKERS=\"$CTDB_TCP_PORT_CHECKERS\""
258 ctdb_check_tcp_ports_netstat ()
260 _cmd='netstat -l -t -n'
262 if [ $? -eq 127 ] ; then
263 # netstat probably not installed - unlikely?
264 ctdb_check_tcp_ports_debug="$_ns"
268 for _p ; do # process each function argument (port)
269 for _a in '0\.0\.0\.0' '::' ; do
270 _pat="[[:space:]]${_a}:${_p}[[:space:]]+[^[:space:]]+[[:space:]]+LISTEN"
271 if echo "$_ns" | grep -E -q "$_pat" ; then
272 # We matched the port, so process next port
277 # We didn't match the port, so flag an error.
278 ctdb_check_tcp_ports_debug="$_cmd shows this output:
286 ctdb_check_tcp_ports_nmap ()
288 # nmap wants a comma-separated list of ports
291 _ports="${_ports}${_ports:+,}${_p}"
294 _cmd="nmap -n -oG - -PS 127.0.0.1 -p $_ports"
296 _nmap_out=$($_cmd 2>&1)
297 if [ $? -eq 127 ] ; then
298 # nmap probably not installed
299 ctdb_check_tcp_ports_debug="$_nmap_out"
303 # get the port-related output
304 _port_info=$(echo "$_nmap_out" | sed -n -r -e 's@^.*Ports:[[:space:]]@@p')
307 # looking for something like this:
308 # 445/open/tcp//microsoft-ds///
309 # possibly followed by a comma
311 case "$_port_info" in
312 # The info we're after must be either at the beginning of
313 # the string or it must follow a space.
316 # Nope, flag an error...
317 ctdb_check_tcp_ports_debug="$_cmd shows this output:
326 # Use the new "ctdb checktcpport" command to check the port.
327 # This is very cheap.
328 ctdb_check_tcp_ports_ctdb ()
330 for _p ; do # process each function argument (port)
331 _cmd="ctdb checktcpport $_p"
336 ctdb_check_tcp_ports_debug="\"$_cmd\" was able to bind to port"
340 # Couldn't bind, something already listening, next port...
344 ctdb_check_tcp_ports_debug="$_cmd (exited with $_ret) with output:
346 # assume not implemented
354 ######################################################
355 # check a unix socket
356 # usage: ctdb_check_unix_socket SERVICE_NAME <socket_path>
357 ######################################################
358 ctdb_check_unix_socket() {
360 [ -z "$socket_path" ] && return
362 if ! netstat --unix -a -n | grep -q "^unix.*LISTEN.*${socket_path}$"; then
363 echo "ERROR: $service_name socket $socket_path not found"
368 ######################################################
369 # check a command returns zero status
370 # usage: ctdb_check_command SERVICE_NAME <command>
371 ######################################################
372 ctdb_check_command() {
375 [ -z "$wait_cmd" ] && return;
376 $wait_cmd > /dev/null 2>&1 || {
377 echo "ERROR: $service_name - $wait_cmd returned error"
382 ################################################
383 # kill off any TCP connections with the given IP
384 ################################################
385 kill_tcp_connections() {
390 connfile="$CTDB_VARDIR/state/connections.$_IP"
391 netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
392 netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
394 while read dest src; do
395 srcip=`echo $src | sed -e "s/:[^:]*$//"`
396 srcport=`echo $src | sed -e "s/^.*://"`
397 destip=`echo $dest | sed -e "s/:[^:]*$//"`
398 destport=`echo $dest | sed -e "s/^.*://"`
399 echo "Killing TCP connection $srcip:$srcport $destip:$destport"
400 ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
402 # we only do one-way killtcp for CIFS
404 # for all others we do 2-way
406 ctdb killtcp $destip:$destport $srcip:$srcport >/dev/null 2>&1 || _failed=1
409 _killcount=`expr $_killcount + 1`
413 [ $_failed = 0 ] || {
414 echo "Failed to send killtcp control"
417 [ $_killcount -gt 0 ] || {
421 while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
423 _count=`expr $_count + 1`
424 [ $_count -gt 3 ] && {
425 echo "Timed out killing tcp connections for IP $_IP"
429 echo "killed $_killcount TCP connections to released IP $_IP"
432 ##################################################################
433 # kill off the local end for any TCP connections with the given IP
434 ##################################################################
435 kill_tcp_connections_local_only() {
440 connfile="$CTDB_VARDIR/state/connections.$_IP"
441 netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
442 netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
444 while read dest src; do
445 srcip=`echo $src | sed -e "s/:[^:]*$//"`
446 srcport=`echo $src | sed -e "s/^.*://"`
447 destip=`echo $dest | sed -e "s/:[^:]*$//"`
448 destport=`echo $dest | sed -e "s/^.*://"`
449 echo "Killing TCP connection $srcip:$srcport $destip:$destport"
450 ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
451 _killcount=`expr $_killcount + 1`
455 [ $_failed = 0 ] || {
456 echo "Failed to send killtcp control"
459 [ $_killcount -gt 0 ] || {
463 while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
465 _count=`expr $_count + 1`
466 [ $_count -gt 3 ] && {
467 echo "Timed out killing tcp connections for IP $_IP"
471 echo "killed $_killcount TCP connections to released IP $_IP"
474 ##################################################################
475 # tickle any TCP connections with the given IP
476 ##################################################################
477 tickle_tcp_connections() {
482 connfile="$CTDB_VARDIR/state/connections.$_IP"
483 netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
484 netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
486 while read dest src; do
487 srcip=`echo $src | sed -e "s/:[^:]*$//"`
488 srcport=`echo $src | sed -e "s/^.*://"`
489 destip=`echo $dest | sed -e "s/:[^:]*$//"`
490 destport=`echo $dest | sed -e "s/^.*://"`
491 echo "Tickle TCP connection $srcip:$srcport $destip:$destport"
492 ctdb tickle $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
493 echo "Tickle TCP connection $destip:$destport $srcip:$srcport"
494 ctdb tickle $destip:$destport $srcip:$srcport >/dev/null 2>&1 || _failed=1
498 [ $_failed = 0 ] || {
499 echo "Failed to send tickle control"
504 ########################################################
505 # start/stop the nfs service on different platforms
506 ########################################################
509 [ -x /etc/init.d/nfsserver ] && {
512 [ -x /etc/init.d/nfslock ] && {
520 service nfsserver start
523 service nfsserver stop > /dev/null 2>&1
526 echo 0 >/proc/fs/nfsd/threads
527 service nfsserver stop > /dev/null 2>&1
529 service nfsserver start
536 service nfslock start
540 service nfs stop > /dev/null 2>&1
541 service nfslock stop > /dev/null 2>&1
544 echo 0 >/proc/fs/nfsd/threads
545 service nfs stop > /dev/null 2>&1
546 service nfslock stop > /dev/null 2>&1
548 service nfslock start
554 echo "Unknown platform. NFS is not supported with ctdb"
560 ########################################################
561 # start/stop the nfs lockmanager service on different platforms
562 ########################################################
563 startstop_nfslock() {
565 [ -x /etc/init.d/nfsserver ] && {
568 [ -x /etc/init.d/nfslock ] && {
574 # for sles there is no service for lockmanager
575 # so we instead just shutdown/restart nfs
578 service nfsserver start
581 service nfsserver stop > /dev/null 2>&1
584 service nfsserver stop
585 service nfsserver start
592 service nfslock start
595 service nfslock stop > /dev/null 2>&1
599 service nfslock start
604 echo "Unknown platform. NFS locking is not supported with ctdb"
610 # better use delete_ip_from_iface() together with add_ip_to_iface
611 # remove_ip should be removed in future
613 local _ip_maskbits=$1
615 local _ip=`echo "$_ip_maskbits" | cut -d '/' -f1`
616 local _maskbits=`echo "$_ip_maskbits" | cut -d '/' -f2`
618 delete_ip_from_iface "$_iface" "$_ip" "$_maskbits"
627 local _state_dir="$CTDB_VARDIR/state/interface_modify"
628 local _lockfile="$_state_dir/$_iface.flock"
629 local _readd_base="$_state_dir/$_iface.readd.d"
631 mkdir -p $_state_dir || {
633 echo "Failed to mkdir -p $_state_dir - $ret"
637 test -f $_lockfile || {
641 flock --timeout 30 $_lockfile $CTDB_BASE/interface_modify.sh add "$_iface" "$_ip" "$_maskbits" "$_readd_base"
645 delete_ip_from_iface()
650 local _state_dir="$CTDB_VARDIR/state/interface_modify"
651 local _lockfile="$_state_dir/$_iface.flock"
652 local _readd_base="$_state_dir/$_iface.readd.d"
654 mkdir -p $_state_dir || {
656 echo "Failed to mkdir -p $_state_dir - $ret"
660 test -f $_lockfile || {
664 flock --timeout 30 $_lockfile $CTDB_BASE/interface_modify.sh delete "$_iface" "$_ip" "$_maskbits" "$_readd_base"
668 setup_iface_ip_readd_script()
673 local _readd_script=$4
674 local _state_dir="$CTDB_VARDIR/state/interface_modify"
675 local _lockfile="$_state_dir/$_iface.flock"
676 local _readd_base="$_state_dir/$_iface.readd.d"
678 mkdir -p $_state_dir || {
680 echo "Failed to mkdir -p $_state_dir - $ret"
684 test -f $_lockfile || {
688 flock --timeout 30 $_lockfile $CTDB_BASE/interface_modify.sh readd_script "$_iface" "$_ip" "$_maskbits" "$_readd_base" "$_readd_script"
692 ########################################################
693 # some simple logic for counting events - per eventscript
694 # usage: ctdb_counter_init
696 # ctdb_check_counter_limit <limit>
697 # ctdb_check_counter_limit succeeds when count >= <limit>
698 ########################################################
699 _ctdb_counter_common () {
700 _counter_file="$ctdb_fail_dir/$service_name"
701 mkdir -p "${_counter_file%/*}" # dirname
703 ctdb_counter_init () {
708 ctdb_counter_incr () {
712 echo -n 1 >> "$_counter_file"
714 ctdb_check_counter_limit () {
717 _limit="${1:-${service_fail_limit}}"
721 _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
722 if [ $_size -ge $_limit ] ; then
723 echo "ERROR: more than $_limit consecutive failures for $service_name, marking cluster unhealthy"
725 elif [ $_size -gt 0 -a -z "$_quiet" ] ; then
726 echo "WARNING: less than $_limit consecutive failures ($_size) for $service_name, not unhealthy yet"
729 ctdb_check_counter_equal () {
735 _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
736 if [ $_size -eq $_limit ] ; then
742 ########################################################
744 ctdb_spool_dir="/var/spool/ctdb"
745 ctdb_status_dir="$ctdb_spool_dir/status"
746 ctdb_fail_dir="$ctdb_spool_dir/failcount"
747 ctdb_active_dir="$ctdb_spool_dir/active"
751 echo "node is \"$1\", \"${script_name}\" reports problem: $(cat $2)"
756 if [ -r "$ctdb_status_dir/$script_name/unhealthy" ] ; then
757 log_status_cat "unhealthy" "$ctdb_status_dir/$script_name/unhealthy"
759 elif [ -r "$ctdb_status_dir/$script_name/banned" ] ; then
760 log_status_cat "banned" "$ctdb_status_dir/$script_name/banned"
769 d="$ctdb_status_dir/$script_name"
776 for i in "banned" "unhealthy" ; do
783 ctdb_service_needs_reconfigure ()
785 [ -e "$ctdb_status_dir/$service_name/reconfigure" ]
788 ctdb_service_set_reconfigure ()
790 d="$ctdb_status_dir/$service_name"
795 ctdb_service_unset_reconfigure ()
797 rm -f "$ctdb_status_dir/$service_name/reconfigure"
800 ctdb_service_reconfigure ()
802 echo "Reconfiguring service \"$service_name\"..."
803 if [ -n "$service_reconfigure" ] ; then
804 eval $service_reconfigure
806 service "$service_name" restart
808 ctdb_service_unset_reconfigure
812 ctdb_compat_managed_service ()
814 if [ "$1" = "yes" ] ; then
819 is_ctdb_managed_service ()
821 _service_name="${1:-${service_name}}"
823 t=" $CTDB_MANAGED_SERVICES "
825 ctdb_compat_managed_service "$CTDB_MANAGES_VSFTPD" "vsftpd"
826 ctdb_compat_managed_service "$CTDB_MANAGES_SAMBA" "samba"
827 ctdb_compat_managed_service "$CTDB_MANAGES_SCP" "scp"
828 ctdb_compat_managed_service "$CTDB_MANAGES_WINBIND" "winbind"
829 ctdb_compat_managed_service "$CTDB_MANAGES_HTTPD" "httpd"
830 ctdb_compat_managed_service "$CTDB_MANAGES_ISCSI" "iscsi"
831 ctdb_compat_managed_service "$CTDB_MANAGES_CLAMD" "clamd"
832 ctdb_compat_managed_service "$CTDB_MANAGES_NFS" "nfs"
833 ctdb_compat_managed_service "$CTDB_MANAGES_NFS" "nfs-ganesha-gpfs"
835 # Returns 0 if "<space>$_service_name<space>" appears in $t
836 [ "${t#* ${_service_name} }" != "${t}" ]
839 ctdb_start_stop_service ()
841 # Do nothing unless configured to...
842 [ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] || return 0
844 _service_name="${1:-${service_name}}"
846 [ "$event_name" = "monitor" ] || return 0
848 _active="$ctdb_active_dir/$_service_name"
849 if is_ctdb_managed_service "$_service_name"; then
850 if ! [ -e "$_active" ] ; then
851 echo "Starting service $_service_name"
852 ctdb_service_start || exit $?
853 mkdir -p "$ctdb_active_dir"
858 if [ -e "$_active" ] ; then
859 echo "Stopping service $_service_name"
860 ctdb_service_stop || exit $?
867 ctdb_service_start ()
869 if [ -n "$service_start" ] ; then
870 eval $service_start || return $?
872 service "$service_name" start || return $?
880 if [ -n "$service_stop" ] ; then
883 service "$service_name" stop
887 ctdb_standard_event_handler ()
902 ipv4_host_addr_to_net_addr()
907 local HOST0=$(echo $HOST | awk -F . '{print $4}')
908 local HOST1=$(echo $HOST | awk -F . '{print $3}')
909 local HOST2=$(echo $HOST | awk -F . '{print $2}')
910 local HOST3=$(echo $HOST | awk -F . '{print $1}')
912 local HOST_NUM=$(( $HOST0 + $HOST1 * 256 + $HOST2 * (256 ** 2) + $HOST3 * (256 ** 3) ))
914 local MASK_NUM=$(( ( (2**32 - 1) * (2**(32 - $MASKBITS)) ) & (2**32 - 1) ))
916 local NET_NUM=$(( $HOST_NUM & $MASK_NUM))
918 local NET0=$(( $NET_NUM & 255 ))
919 local NET1=$(( ($NET_NUM & (255 * 256)) / 256 ))
920 local NET2=$(( ($NET_NUM & (255 * 256**2)) / 256**2 ))
921 local NET3=$(( ($NET_NUM & (255 * 256**3)) / 256**3 ))
923 echo "$NET3.$NET2.$NET1.$NET0"
926 ipv4_maskbits_to_net_mask()
930 local MASK_NUM=$(( ( (2**32 - 1) * (2**(32 - $MASKBITS)) ) & (2**32 - 1) ))
932 local MASK0=$(( $MASK_NUM & 255 ))
933 local MASK1=$(( ($MASK_NUM & (255 * 256)) / 256 ))
934 local MASK2=$(( ($MASK_NUM & (255 * 256**2)) / 256**2 ))
935 local MASK3=$(( ($MASK_NUM & (255 * 256**3)) / 256**3 ))
937 echo "$MASK3.$MASK2.$MASK1.$MASK0"
945 local N=`echo $ADDR | sed -e 's/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*//'`
946 test -n "$N" && fail=1
948 local ADDR0=$(echo $ADDR | awk -F . '{print $4}')
949 local ADDR1=$(echo $ADDR | awk -F . '{print $3}')
950 local ADDR2=$(echo $ADDR | awk -F . '{print $2}')
951 local ADDR3=$(echo $ADDR | awk -F . '{print $1}')
953 test "$ADDR0" -gt 255 && fail=1
954 test "$ADDR1" -gt 255 && fail=1
955 test "$ADDR2" -gt 255 && fail=1
956 test "$ADDR3" -gt 255 && fail=1
958 test x"$fail" != x"0" && {
959 #echo "IPv4: '$ADDR' is not a valid address"
966 # iptables doesn't like being re-entered, so flock-wrap it.
969 flock -w 30 /var/ctdb/iptables-ctdb.flock /sbin/iptables "$@"
972 ########################################################
974 ########################################################
976 # Temporary directory for tickles.
977 tickledir="$CTDB_VARDIR/state/tickles"
978 mkdir -p "$tickledir"
984 mkdir -p "$tickledir" # Just in case
987 _pnn=$(ctdb pnn) ; _pnn=${_pnn#PNN:}
989 # What public IPs do I hold?
990 _ips=$(ctdb -Y ip | awk -F: -v pnn=$_pnn '$3 == pnn {print $2}')
992 # IPs as a regexp choice
993 _ipschoice="($(echo $_ips | sed -e 's/ /|/g' -e 's/\./\\\\./g'))"
995 # Record connections to our public IPs in a temporary file
996 _my_connections="${tickledir}/${_port}.connections"
997 rm -f "$_my_connections"
999 awk -v destpat="^${_ipschoice}:${_port}\$" \
1000 '$1 == "tcp" && $6 == "ESTABLISHED" && $4 ~ destpat {print $5, $4}' |
1001 sort >"$_my_connections"
1003 # Record our current tickles in a temporary file
1004 _my_tickles="${tickledir}/${_port}.tickles"
1005 rm -f "$_my_tickles"
1006 for _i in $_ips ; do
1007 ctdb -Y gettickles $_i $_port |
1008 awk -F: 'NR > 1 { printf "%s:%s %s:%s\n", $2, $3, $4, $5 }'
1010 sort >"$_my_tickles"
1012 # Add tickles for connections that we haven't already got tickles for
1013 comm -23 "$_my_connections" "$_my_tickles" |
1014 while read _src _dst ; do
1015 ctdb addtickle $_src $_dst
1018 # Remove tickles for connections that are no longer there
1019 comm -13 "$_my_connections" "$_my_tickles" |
1020 while read _src _dst ; do
1021 ctdb deltickle $_src $_dst
1024 rm -f "$_my_connections" "$_my_tickles"
1027 ########################################################
1028 # load a site local config file
1029 ########################################################
1031 [ -x $CTDB_BASE/rc.local ] && {
1032 . $CTDB_BASE/rc.local
1035 [ -d $CTDB_BASE/rc.local.d ] && {
1036 for i in $CTDB_BASE/rc.local.d/* ; do
1037 [ -x "$i" ] && . "$i"
1041 script_name="${0##*/}" # basename
1042 service_name="$script_name" # default is just the script name
1043 service_fail_limit=1