Add a variable CTDB_NFS_SKIP_SHARE_CHECK to sysconfig that can disable the check...
[sahlberg/ctdb.git] / config / events.d / 60.nfs
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 . $CTDB_BASE/functions
5 loadconfig ctdb
6 loadconfig nfs
7
8 [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0
9 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0
10
11 cmd="$1"
12 shift
13
14 PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
15
16
17
18 case $cmd in 
19      startup)
20         /bin/mkdir -p $CTDB_BASE/state/nfs
21         /bin/mkdir -p $CTDB_BASE/state/statd/ip
22         /bin/mkdir -p $STATD_SHARED_DIRECTORY
23
24         /bin/rm -f $CTDB_BASE/state/statd/statd.restart >/dev/null 2>/dev/null
25
26         # make sure nfs is stopped before we start it, or it may get a bind error
27         startstop_nfs stop
28         startstop_nfs start
29         ;;
30
31      shutdown)
32         startstop_nfs stop
33         exit 0
34         ;;
35
36      takeip)
37         ip=$2
38
39         echo $ip >> $CTDB_BASE/state/statd/restart
40
41         # having a list of what IPs we have allows statd to do the right 
42         # thing via $CTDB_BASE/statd-callout
43         touch $CTDB_BASE/state/statd/ip/$ip
44         exit 0
45         ;;
46
47      releaseip)
48         iface=$1
49         ip=$2
50         maskbits=$3
51
52         echo $ip >> $CTDB_BASE/state/statd/restart
53         /bin/rm -f $CTDB_BASE/state/statd/ip/$ip
54         exit 0
55         ;;
56
57      recovered)
58         # if no IPs have changed then don't need to restart statd 
59         [ -f $CTDB_BASE/state/statd/restart ] || exit 0;
60
61         # always restart the lockmanager so that we start with a clusterwide
62         # graceperiod when ip addresses has changed
63         [ -x $CTDB_BASE/statd-callout ] && {
64                 $CTDB_BASE/statd-callout notify &
65         } >/dev/null 2>&1
66
67         /bin/rm -f $CTDB_BASE/state/statd/restart
68         ;;
69
70       monitor)
71         # check that statd responds to rpc requests
72         # if statd is not running we try to restart it once and wait
73         # for the next monitoring event to verify if it is running or not
74         # if it still fails we fail and mark the node as UNHEALTHY
75         if [ -f $CTDB_BASE/state/statd/statd.restart ]; then
76                 # statd was restarted, see if it came up ok
77                 rpcinfo -u localhost 100024 1 > /dev/null || {
78                         echo "ERROR: Failed to restart STATD"
79                         exit 1
80                 }
81                 echo "STATD successfully restarted."
82                 /bin/rm -f $CTDB_BASE/state/statd/statd.restart
83         else
84                 rpcinfo -u localhost 100024 1 > /dev/null || {
85                         RPCSTATDOPTS=""
86                         [ -n "$STATD_HOSTNAME" ] && RPCSTATDOPTS="$RPCSTATDOPTS -n $STATD_HOSTNAME"
87                         [ -n "$STATD_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -p $STATD_PORT"
88                         [ -n "$STATD_OUTGOING_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -o $STATD_OUTGOING_PORT"
89                         rpc.statd $RPCSTATDOPTS 
90                         echo "ERROR: STATD is not responding. Trying to restart it. [rpc.statd $RPCSTATDOPTS]"
91                         touch $CTDB_BASE/state/statd/statd.restart
92                 }
93         fi
94
95
96
97         # check that NFS responds to rpc requests
98         ctdb_check_rpc "NFS" 100003 3
99
100         # and that its directories are available
101         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
102             nfs_dirs=$(exportfs | grep -v '^#' | grep '^/' | awk {'print $1;'})
103             ctdb_check_directories "nfs" $nfs_dirs
104         }
105
106         # check that lockd responds to rpc requests
107         ctdb_check_rpc "lockd" 100021 1
108         ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY
109
110         # mount needs special handling since it is sometimes not started
111         # correctly on RHEL5
112         rpcinfo -u localhost 100005 1 > /dev/null || {
113                 echo "ERROR: MOUNTD is not running. Trying to restart it."
114                 RPCMOUNTDOPTS=""
115                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
116                 killall -q -9 rpc.mountd
117                 rpc.mountd $RPCMOUNTDOPTS &
118                 exit 1
119         }
120         ;;
121
122 esac
123
124 exit 0