update the "uptime" command to indicate the "time since last" is the time since the...
[ctdb.git] / 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 . $CTDB_BASE/functions
7 loadconfig ctdb
8 loadconfig nfs
9
10 cmd="$1"
11 shift
12
13 [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0
14 [ -z "$NFS_TICKLE_SHARED_DIRECTORY" ] && exit 0
15
16 case $cmd in 
17      startup)
18         mkdir -p $CTDB_BASE/state/nfstickle
19         mkdir -p $NFS_TICKLE_SHARED_DIRECTORY/`hostname`
20         # we rely on fast tcp wait1 recycling
21         echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
22         exit 0
23         ;;
24         
25      takeip)
26         iface=$1
27         ip=$2
28         # first send a grat arp, to ensure the client knows the updated
29         # mac address for this IP
30         ctdb gratiousarp $ip $iface
31         # send tickle acks for all the connections the old server had
32         for f in $NFS_TICKLE_SHARED_DIRECTORY/*/$ip; do
33                 [ -f $f ] && cat $f | while read dest; do
34                         dip=`echo $dest | cut -d: -f1`
35                         dport=`echo $dest | cut -d: -f2`
36                         # send three, in case of lost packets
37                         echo "Sending NFS tickle ack for $ip to $dip:$dport"
38                         for i in `seq 1 3`; do
39                                 ctdb tickle $dip:$dport $ip:2049
40                         done
41                 done
42         done
43         exit 0
44         ;;
45
46      releaseip)
47         exit 0
48         ;;
49
50      recovered)
51         exit 0
52         ;;
53
54      shutdown)
55         exit 0
56         ;;
57
58      monitor)
59 # always create these direcotries since NFS might be enabled at runtime
60         # and we dont want to restart ctdbd
61         mkdir -p $CTDB_BASE/state/nfstickle
62         mkdir -p $NFS_TICKLE_SHARED_DIRECTORY/`hostname`
63
64         mydir=$NFS_TICKLE_SHARED_DIRECTORY/`hostname`
65         rm -f $mydir/*
66         # record our connections to shared storage
67         netstat -tn |egrep '^tcp[[:space:]]+[0-9]+[[:space:]]+[0-9]+[[:space:]]+[0-9\.]+:2049.*ESTABLISHED' |
68                 awk '{print $4" "$5}' | 
69                 while read dest src; do
70                         ip=`echo $dest | cut -d: -f1`
71                         echo $src >> $mydir/$ip
72                 done
73         exit 0
74         ;;
75
76 esac
77
78 # ignore unknown commands
79 exit 0