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         # always restart the lockmanager so that we start with a clusterwide
59         # graceperiod when ip addresses has changed
60         [ -x $CTDB_BASE/statd-callout ] && {
61                 $CTDB_BASE/statd-callout notify &
62         } >/dev/null 2>&1
63
64         /bin/rm -f $CTDB_BASE/state/statd/restart
65         ;;
66
67       monitor)
68         # check that NFS responds to rpc requests
69         ctdb_check_rpc "NFS" 100003 3
70
71         # and that its directories are available
72         nfs_dirs=`grep -v '^#' < /etc/exports | cut -d' ' -f1`
73         ctdb_check_directories "nfs" $nfs_dirs
74
75         # check that lockd responds to rpc requests
76         ctdb_check_rpc "statd" 100024 1
77         ctdb_check_rpc "lockd" 100021 1
78         ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY
79
80         # mount needs special handling since it is sometimes not started
81         # correctly on RHEL5
82         rpcinfo -u localhost 100005 1 > /dev/null || {
83                 echo "`date` ERROR: MOUNTD is not running. Trying to restart it."
84                 RPCMOUNTDOPTS=""
85                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
86                 killall -q -9 rpc.mountd
87                 rpc.mountd $RPCMOUNTDOPTS &
88                 exit 1
89         }
90         ;;
91
92 esac
93
94 exit 0