2 # script to manage nfs in a clustered environment
7 [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0
8 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0
13 PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
17 mkdir -p /etc/ctdb/state/nfs
18 /bin/mkdir -p /etc/ctdb/state/statd/ip
19 ctdb_wait_directories "nfslock" "$STATD_SHARED_DIRECTORY"
22 # wait for all nfs exported directories to become available
23 nfs_dirs=`grep -v '^#' < /etc/exports | cut -d' ' -f1`
24 ctdb_wait_directories "NFS" $nfs_dirs
26 # make sure nfs is stopped before we start it, or it may get a bind error
27 service nfs stop > /dev/null 2>&1
28 service nfslock stop > /dev/null 2>&1
43 echo $ip >> /etc/ctdb/state/statd/restart
45 # having a list of what IPs we have allows statd to do the right
46 # thing via /etc/ctdb/statd-callout
47 /bin/touch /etc/ctdb/state/statd/ip/$ip
56 echo $ip >> /etc/ctdb/state/nfs/restart
58 echo $ip >> /etc/ctdb/state/statd/restart
59 /bin/rm -f /etc/ctdb/state/statd/ip/$ip
64 [ -f /etc/ctdb/state/nfs/restart ] && [ ! -z "$LOCKD_TCPPORT" ] && {
65 # RST all tcp connections used for NLM to ensure that they do
66 # not survive in ESTABLISHED state across a failover/failback
67 # and create an ack storm
68 netstat -tn |egrep "^tcp.*\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:${LOCKD_TCPPORT}\s+.*ESTABLISHED" | awk '{print $4" "$5}' | while read dest src; do
69 srcip=`echo $src | cut -d: -f1`
70 srcport=`echo $src | cut -d: -f2`
71 destip=`echo $dest | cut -d: -f1`
72 destport=`echo $dest | cut -d: -f2`
73 ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1
74 # ctdb killtcp $destip:$destport $srcip:$srcport >/dev/null 2>&1
78 [ -f /etc/ctdb/state/nfs/restart ] && {
79 # RST all tcp connections used for NFS to ensure that they do
80 # not survive in ESTABLISHED state across a failover/failback
81 # and create an ack storm
82 netstat -tn |egrep '^tcp.*\s+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:2049\s+.*ESTABLISHED' | awk '{print $4" "$5}' | while read dest src; do
83 srcip=`echo $src | cut -d: -f1`
84 srcport=`echo $src | cut -d: -f2`
85 destip=`echo $dest | cut -d: -f1`
86 destport=`echo $dest | cut -d: -f2`
87 ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1
88 ctdb killtcp $destip:$destport $srcip:$srcport >/dev/null 2>&1
91 /bin/rm -f /etc/ctdb/state/nfs/restart
93 # if we have taken or released any ips we must send out
94 # statd notifications to recover lost nfs locks
95 [ -x /etc/ctdb/statd-callout ] && [ -f /etc/ctdb/state/statd/restart ] && {
96 /etc/ctdb/statd-callout notify &
99 /bin/rm -f /etc/ctdb/state/statd/restart
103 # check that NFS responds to rpc requests
104 ctdb_check_rpc "NFS" 100003 3
105 ctdb_check_rpc "mount" 100005 1
107 # and that its directories are available
108 nfs_dirs=`grep -v '^#' < /etc/exports | cut -d' ' -f1`
109 ctdb_check_directories "nfs" $nfs_dirs
111 # check that lockd responds to rpc requests
112 ctdb_check_rpc "statd" 100024 1
113 ctdb_check_rpc "lockd" 100021 1
114 ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY