NFS tickles: use addtickle/deltickle instead of shared tickle directory.
[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         /bin/mkdir -p $STATD_SHARED_DIRECTORY
8         startstop_nfs stop
9         startstop_nfs start
10         echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
11 }
12
13 reconfigure_nfs() {
14         # always restart the lockmanager so that we start with a clusterwide
15         # graceperiod when ip addresses has changed
16         [ -x $CTDB_BASE/statd-callout ] && {
17                 $CTDB_BASE/statd-callout notify &
18         } >/dev/null 2>&1
19
20 }
21
22 . $CTDB_BASE/functions
23
24 service_name="nfs"
25 service_start="start_nfs"
26 service_stop="startstop_nfs stop"
27 service_reconfigure="reconfigure_nfs"
28
29 loadconfig
30
31 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0
32
33 ctdb_start_stop_service
34
35 case "$1" in 
36      startup)
37         ctdb_service_start
38         ;;
39
40      shutdown)
41         ctdb_service_stop
42         ;;
43
44      takeip)
45         ctdb_service_set_reconfigure
46         touch $CTDB_BASE/state/statd/ip/$3
47         ;;
48
49      releaseip)
50         ctdb_service_set_reconfigure
51         /bin/rm -f $CTDB_BASE/state/statd/ip/$3
52         ;;
53
54      recovered)
55         # if we have taken or released any ips we must 
56         # restart the lock manager so that we enter a clusterwide grace period
57         if ctdb_service_needs_reconfigure ; then
58             ctdb_service_reconfigure
59         fi
60         ;;
61
62       monitor)
63         if ctdb_service_needs_reconfigure ; then
64             ctdb_service_reconfigure
65             exit 0
66         fi
67
68         update_tickles 2049
69
70         # check that statd responds to rpc requests
71         # if statd is not running we try to restart it
72         rpcinfo -u localhost 100024 1 > /dev/null || {
73                 RPCSTATDOPTS=""
74                 [ -n "$STATD_HOSTNAME" ] && RPCSTATDOPTS="$RPCSTATDOPTS -n $STATD_HOSTNAME"
75                 [ -n "$STATD_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -p $STATD_PORT"
76                 [ -n "$STATD_OUTGOING_PORT" ] && RPCSTATDOPTS="$RPCSTATDOPTS -o $STATD_OUTGOING_PORT"
77                 rpc.statd $RPCSTATDOPTS 
78                 echo "ERROR: STATD is not responding. Trying to restart it. [rpc.statd $RPCSTATDOPTS]"
79         }
80
81
82         # check that NFS responds to rpc requests
83         [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" = "yes" ] || {
84             (ctdb_check_rpc "NFS" 100003 3)
85             [ $? = "0" ] || {
86                 echo "Trying to restart NFS service"
87                 startstop_nfs restart
88                 exit 1
89             }
90         }
91
92         # and that its directories are available
93         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
94             exportfs | grep -v '^#' | grep '^/' |
95             sed -e 's/[[:space:]]\+[^[:space:]]*$//' |
96             ctdb_check_directories
97         } || exit $?
98
99         # check that lockd responds to rpc requests
100         ctdb_check_rpc "lockd" 100021 1
101         echo "$STATD_SHARED_DIRECTORY" | ctdb_check_directories "statd" || \
102             exit $?
103
104         # mount needs special handling since it is sometimes not started
105         # correctly on RHEL5
106         rpcinfo -u localhost 100005 1 > /dev/null || {
107                 echo "ERROR: MOUNTD is not running. Trying to restart it."
108                 RPCMOUNTDOPTS=""
109                 [ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
110                 killall -q -9 rpc.mountd
111                 rpc.mountd $RPCMOUNTDOPTS &
112                 exit 1
113         }
114         # rquotad needs special handling since it is sometimes not started
115         # correctly on RHEL5
116         # this is not a critical service so we dont flag the node as unhealthy
117         rpcinfo -u localhost 100011 1 > /dev/null || {
118                 echo "ERROR: RQUOTAD is not running. Trying to restart it."
119                 RPCRQUOTADOPTS=""
120                 [ -n "$RQUOTAD_PORT" ] && RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT"
121                 killall -q -9 rpc.rquotad
122                 rpc.rquotad $RPCRQUOTADOPTS &
123         }
124         ;;
125
126     *)
127         ctdb_standard_event_handler "$@"
128         ;;
129 esac
130
131 exit 0