try to restart NFS LOCKD if it failed to start
[sahlberg/ctdb.git] / config / functions
old mode 100644 (file)
new mode 100755 (executable)
index 6556b21..9659d48
@@ -162,7 +162,7 @@ ctdb_check_directories_probe() {
                continue
                ;;
            *)
-               [ -d "$d" ] || return 1
+               [ -d "${d}/." ] || return 1
        esac
     done
 }
@@ -231,7 +231,7 @@ kill_tcp_connections() {
     _failed=0
 
     _killcount=0
-    connfile="$CTDB_BASE/state/connections.$_IP"
+    connfile="$CTDB_VARDIR/state/connections.$_IP"
     netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
     netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
 
@@ -281,7 +281,7 @@ kill_tcp_connections_local_only() {
     _failed=0
 
     _killcount=0
-    connfile="$CTDB_BASE/state/connections.$_IP"
+    connfile="$CTDB_VARDIR/state/connections.$_IP"
     netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
     netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
 
@@ -323,7 +323,7 @@ tickle_tcp_connections() {
     _failed=0
 
     _killcount=0
-    connfile="$CTDB_BASE/state/connections.$_IP"
+    connfile="$CTDB_VARDIR/state/connections.$_IP"
     netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
     netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
 
@@ -366,6 +366,9 @@ startstop_nfs() {
                stop)
                        service nfsserver stop > /dev/null 2>&1
                        ;;
+               restart)
+                       service nfsserver restart
+                       ;;
                esac
                ;;
        rhel)
@@ -378,6 +381,10 @@ startstop_nfs() {
                        service nfs stop > /dev/null 2>&1
                        service nfslock stop > /dev/null 2>&1
                        ;;
+               restart)
+                       service nfslock restart
+                       service nfs restart
+                       ;;
                esac
                ;;
        *)
@@ -410,6 +417,10 @@ startstop_nfslock() {
                stop)
                        service nfsserver stop > /dev/null 2>&1
                        ;;
+               restart)
+                       service nfsserver stop
+                       service nfsserver start
+                       ;;
                esac
                ;;
        rhel)
@@ -420,6 +431,10 @@ startstop_nfslock() {
                stop)
                        service nfslock stop > /dev/null 2>&1
                        ;;
+               restart)
+                       service nfslock stop
+                       service nfslock start
+                       ;;
                esac
                ;;
        *)
@@ -446,7 +461,7 @@ add_ip_to_iface()
        local _iface=$1
        local _ip=$2
        local _maskbits=$3
-       local _state_dir="$CTDB_BASE/state/interface_modify"
+       local _state_dir="$CTDB_VARDIR/state/interface_modify"
        local _lockfile="$_state_dir/$_iface.flock"
        local _readd_base="$_state_dir/$_iface.readd.d"
 
@@ -469,7 +484,7 @@ delete_ip_from_iface()
        local _iface=$1
        local _ip=$2
        local _maskbits=$3
-       local _state_dir="$CTDB_BASE/state/interface_modify"
+       local _state_dir="$CTDB_VARDIR/state/interface_modify"
        local _lockfile="$_state_dir/$_iface.flock"
        local _readd_base="$_state_dir/$_iface.readd.d"
 
@@ -493,7 +508,7 @@ setup_iface_ip_readd_script()
        local _ip=$2
        local _maskbits=$3
        local _readd_script=$4
-       local _state_dir="$CTDB_BASE/state/interface_modify"
+       local _state_dir="$CTDB_VARDIR/state/interface_modify"
        local _lockfile="$_state_dir/$_iface.flock"
        local _readd_base="$_state_dir/$_iface.readd.d"
 
@@ -557,7 +572,7 @@ ctdb_active_dir="$ctdb_spool_dir/active"
 
 log_status_cat ()
 {
-    echo "node is \"$1\", problem with \"${script_name}\": $(cat $2)"
+    echo "node is \"$1\", \"${script_name}\" reports problem: $(cat $2)"
 }
 
 ctdb_checkstatus ()
@@ -690,6 +705,7 @@ ctdb_standard_event_handler ()
            exit
            ;;
        setstatus)
+            shift
            ctdb_setstatus "$@"
            exit
            ;;
@@ -760,6 +776,67 @@ ipv4_is_valid_addr()
        return 0;
 }
 
+# iptables doesn't like being re-entered, so flock-wrap it.
+iptables()
+{
+       flock -w 30 /var/ctdb/iptables-ctdb.flock /sbin/iptables "$@"
+}
+
+########################################################
+# tickle handling
+########################################################
+
+# Temporary directory for tickles.
+tickledir="$CTDB_VARDIR/state/tickles"
+mkdir -p "$tickledir"
+
+update_tickles ()
+{
+       _port="$1"
+
+       mkdir -p "$tickledir" # Just in case
+
+       # Who am I?
+       _pnn=$(ctdb pnn) ; _pnn=${_pnn#PNN:}
+
+       # What public IPs do I hold?
+       _ips=$(ctdb -Y ip | awk -F: -v pnn=$_pnn '$3 == pnn {print $2}')
+
+       # IPs as a regexp choice
+       _ipschoice="($(echo $_ips | sed -e 's/ /|/g' -e 's/\./\\\\./g'))"
+
+       # Record connections to our public IPs in a temporary file
+       _my_connections="${tickledir}/${_port}.connections"
+       rm -f "$_my_connections"
+       netstat -tn |
+       awk -v destpat="^${_ipschoice}:${_port}\$" \
+         '$1 == "tcp" && $6 == "ESTABLISHED" && $4 ~ destpat {print $5, $4}' |
+       sort >"$_my_connections"
+
+       # Record our current tickles in a temporary file
+       _my_tickles="${tickledir}/${_port}.tickles"
+       rm -f "$_my_tickles"
+       for _i in $_ips ; do
+               ctdb -Y gettickles $_i $_port | 
+               awk -F: 'NR > 1 { printf "%s:%s %s:%s\n", $2, $3, $4, $5 }'
+       done |
+       sort >"$_my_tickles"
+
+       # Add tickles for connections that we haven't already got tickles for
+       comm -23 "$_my_connections" "$_my_tickles" |
+       while read _src _dst ; do
+               ctdb addtickle $_src $_dst
+       done
+
+       # Remove tickles for connections that are no longer there
+       comm -13 "$_my_connections" "$_my_tickles" |
+       while read _src _dst ; do
+               ctdb deltickle $_src $_dst
+       done
+
+       rm -f "$_my_connections" "$_my_tickles" 
+}
+
 ########################################################
 # load a site local config file
 ########################################################