cope with non-standard install dirs in event scripts
[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         ctdb_wait_directories "nfslock" "$STATD_SHARED_DIRECTORY"
21
22
23         # wait for all nfs exported directories to become available
24         nfs_dirs=`grep -v '^#' < /etc/exports | cut -d' ' -f1`
25         ctdb_wait_directories "NFS" $nfs_dirs
26
27         # make sure nfs is stopped before we start it, or it may get a bind error
28         service nfs stop > /dev/null 2>&1
29         service nfslock stop > /dev/null 2>&1
30
31         service nfslock start
32         service nfs start
33         ;;
34
35      shutdown)
36         service nfs stop
37         service nfslock stop
38         exit 0
39         ;;
40
41      takeip)
42         ip=$2
43
44         echo $ip >> $CTDB_BASE/state/statd/restart
45
46         # having a list of what IPs we have allows statd to do the right 
47         # thing via $CTDB_BASE/statd-callout
48         /bin/touch $CTDB_BASE/state/statd/ip/$ip
49         exit 0
50         ;;
51
52      releaseip)
53         iface=$1
54         ip=$2
55         maskbits=$3
56
57         echo $ip >> $CTDB_BASE/state/statd/restart
58         /bin/rm -f $CTDB_BASE/state/statd/ip/$ip
59         exit 0
60         ;;
61
62      recovered)
63         # always restart the lockmanager so that we start with a clusterwide
64         # graceperiod when ip addresses has changed
65         [ -x $CTDB_BASE/statd-callout ] && {
66                 $CTDB_BASE/statd-callout notify &
67         } >/dev/null 2>&1
68
69         /bin/rm -f $CTDB_BASE/state/statd/restart
70         ;;
71
72       monitor)
73         # check that NFS responds to rpc requests
74         ctdb_check_rpc "NFS" 100003 3
75         ctdb_check_rpc "mount" 100005 1
76
77         # and that its directories are available
78         nfs_dirs=`grep -v '^#' < /etc/exports | cut -d' ' -f1`
79         ctdb_check_directories "nfs" $nfs_dirs
80
81         # check that lockd responds to rpc requests
82         ctdb_check_rpc "statd" 100024 1
83         ctdb_check_rpc "lockd" 100021 1
84         ctdb_check_directories "statd" $STATD_SHARED_DIRECTORY
85         ;;
86
87 esac
88
89 exit 0