change the signature to ctdb_sys_have_ip() to also return:
[vlendec/samba-autobuild/.git] / ctdb / config / events.d / 61.nfstickle
1 #!/bin/sh
2 # ctdb event script for NFS tickle acks
3
4 PATH=/bin:/usr/bin:$PATH
5
6 . /etc/ctdb/functions
7 loadconfig nfs
8
9 cmd="$1"
10 shift
11
12 [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0
13 [ -z "$NFS_TICKLE_SHARED_DIRECTORY" ] && exit 0
14
15 case $cmd in 
16      startup)
17         mkdir -p /etc/ctdb/state/nfstickle
18         mkdir -p $NFS_TICKLE_SHARED_DIRECTORY/`hostname`
19         # we rely on fast tcp wait1 recycling
20         echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
21         exit 0
22         ;;
23         
24      takeip)
25         iface=$1
26         ip=$2
27         shopt -s nullglob
28         # send tickle acks for all the connections the old server had
29         for f in $NFS_TICKLE_SHARED_DIRECTORY/*/$ip; do
30                 cat $f | while read dest; do
31                         dip=`echo $dest | cut -d: -f1`
32                         dport=`echo $dest | cut -d: -f2`
33                         # send three, in case of lost packets
34                         echo "`date` Sending NFS tickle ack for $ip to $dip:$dport"
35                         for i in `seq 1 3`; do
36                                 ctdb tickle $dip:$dport $ip:2049
37                         done
38                 done
39         done
40         exit 0
41         ;;
42
43      releaseip)
44         exit 0
45         ;;
46
47      recovered)
48         exit 0
49         ;;
50
51      shutdown)
52         exit 0
53         ;;
54
55      monitor)
56         mydir=$NFS_TICKLE_SHARED_DIRECTORY/`hostname`
57         rm -f $mydir/*
58         # record our connections to shared storage
59         netstat -tn |egrep '^tcp\s+[0-9]+\s+[0-9]+\s+[0-9\.]+:2049.*ESTABLISHED' |
60                 awk '{print $4" "$5}' | 
61                 while read dest src; do
62                         ip=`echo $dest | cut -d: -f1`
63                         echo $src >> $mydir/$ip
64                 done
65         exit 0
66         ;;
67
68 esac
69
70 # ignore unknown commands
71 exit 0