merge from tridge
[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 nfs
6
7 [ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0
8 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0
9
10 cmd="$1"
11 shift
12
13 PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
14
15 case $cmd in 
16      startup)
17         /bin/mkdir -p $CTDB_BASE/state/nfs
18         /bin/mkdir -p $CTDB_BASE/state/statd/ip
19         /bin/mkdir -p $STATD_SHARED_DIRECTORY
20
21         # make sure nfs is stopped before we start it, or it may get a bind error
22         service nfs stop > /dev/null 2>&1
23         service nfslock stop > /dev/null 2>&1
24
25         service nfslock start
26         service nfs start
27         ;;
28
29      shutdown)
30         # shutting down nfs can take a while so put it in the background
31         service nfs stop &
32         service nfslock 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         /bin/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 NFS responds to rpc requests
72         ctdb_check_rpc "NFS" 100003 3
73
74         # and that its directories are available
75         nfs_dirs=$(grep -v '^#' < /etc/exports | awk {'print $1;'})
76         ctdb_check_directories "nfs" $nfs_dirs
77
78         # check that lockd responds to rpc requests
79         ctdb_check_rpc "statd" 100024 1
80         ctdb_check_rpc "lockd" 100021 1
81         ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY
82
83         # mount needs special handling since it is sometimes not started
84         # correctly on RHEL5
85         rpcinfo -u localhost 100005 1 > /dev/null || {
86                 echo "`date` ERROR: MOUNTD is not running. Trying to restart it."
87                 RPCMOUNTDOPTS=""
88                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
89                 killall -q -9 rpc.mountd
90                 rpc.mountd $RPCMOUNTDOPTS &
91                 exit 1
92         }
93         ;;
94
95 esac
96
97 exit 0