Remove the dependency on the underlying cluster filesystem for handling
[metze/ctdb/wip.git] / config / events.d / 60.nfs
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 start_nfs() {
5         /bin/mkdir -p $CTDB_BASE/state/nfs
6         /bin/mkdir -p $CTDB_BASE/state/statd/ip
7         startstop_nfs stop
8         startstop_nfs start
9 }
10
11 . $CTDB_BASE/functions
12
13 service_name="nfs"
14 service_start="start_nfs"
15 service_stop="startstop_nfs stop"
16
17 loadconfig
18
19 ctdb_start_stop_service
20
21 echo XX 60.nfs   $@
22
23 case "$1" in 
24      init)
25         # read statd from persistent database
26         ;;
27      startup)
28         ctdb_service_start
29         touch $CTDB_BASE/state/statd/update-trigger
30         ;;
31
32      shutdown)
33         ctdb_service_stop
34         ;;
35
36      takeip)
37         ctdb_service_set_reconfigure
38         ;;
39
40      releaseip)
41         ctdb_service_set_reconfigure
42         ;;
43
44       monitor)
45         if ctdb_service_needs_reconfigure ; then
46             ctdb_service_reconfigure
47             exit 0
48         fi
49
50         # check that statd responds to rpc requests
51         # if statd is not running we try to restart it
52         rpcinfo -u localhost 100024 1 > /dev/null || {
53                 RPCSTATDOPTS=""
54                 [ -n "$STATD_HOSTNAME" ] && RPCSTATDOPTS="$RPCSTATDOPTS -n $STATD_HOSTNAME"
55                 [ -n "$STATD_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -p $STATD_PORT"
56                 [ -n "$STATD_OUTGOING_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -o $STATD_OUTGOING_PORT"
57                 rpc.statd $RPCSTATDOPTS 
58                 echo "ERROR: STATD is not responding. Trying to restart it. [rpc.statd $RPCSTATDOPTS]"
59         }
60
61
62         # check that NFS responds to rpc requests
63         [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
64             (ctdb_check_rpc "NFS" 100003 3)
65             [ $? = "0" ] || {
66                 echo "Trying to restart NFS service"
67                 startstop_nfs restart
68                 exit 1
69             }
70         }
71
72         # and that its directories are available
73         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
74             exportfs | grep -v '^#' | grep '^/' |
75             sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
76             ctdb_check_directories
77         } || exit $?
78
79         # check that lockd responds to rpc requests
80         ctdb_check_rpc "lockd" 100021 1
81
82         # mount needs special handling since it is sometimes not started
83         # correctly on RHEL5
84         rpcinfo -u localhost 100005 1 > /dev/null || {
85                 echo "ERROR: MOUNTD is not running. Trying to restart it."
86                 RPCMOUNTDOPTS=""
87                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
88                 killall -q -9 rpc.mountd
89                 rpc.mountd $RPCMOUNTDOPTS &
90                 exit 1
91         }
92         # rquotad needs special handling since it is sometimes not started
93         # correctly on RHEL5
94         # this is not a critical service so we dont flag the node as unhealthy
95         rpcinfo -u localhost 100011 1 > /dev/null || {
96                 echo "ERROR: RQUOTAD is not running. Trying to restart it."
97                 RPCRQUOTADOPTS=""
98                 [ -n "$RQUOTAD_PORT" ] && RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT"
99                 killall -q -9 rpc.rquotad
100                 rpc.rquotad $RPCRQUOTADOPTS &
101         }
102
103         # once every 60 seconds, update the statd state database for which
104         # clients need notifications
105         LAST_UPDATE=`stat --printf="%Y" $CTDB_BASE/state/statd/update-trigger`
106         CURRENT_TIME=`date +"%s"`
107         expr "$CURRENT_TIME" ">" "(" "$LAST_UPDATE" "+" "60" ")" >/dev/null 2>/dev/null
108         [ $? = "0" ] && {
109             touch $CTDB_BASE/state/statd/update-trigger
110             $CTDB_BASE/statd-callout updatelocal &
111             $CTDB_BASE/statd-callout updateremote &
112         }
113         ;;
114
115     ipreallocated)
116         # if the ips have been reallocated, we must restart the lockmanager
117         # across all nodes and ping all statd listeners
118         [ -x $CTDB_BASE/statd-callout ] && {
119                 $CTDB_BASE/statd-callout notify &
120         } >/dev/null 2>&1
121         ;;
122     *)
123         ctdb_standard_event_handler "$@"
124         ;;
125 esac
126
127 exit 0