TMP: add a ctdb snapshot of current ctdb master (git://git.samba.org/ctdb.git) to...
[obnox/samba/samba-obnox.git] / ctdb / config / events.d / 60.nfs
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 . $CTDB_BASE/functions
5
6 service_name="nfs"
7 service_start ()
8 {
9     startstop_nfs stop
10     startstop_nfs start
11     set_proc "sys/net/ipv4/tcp_tw_recycle" 1
12 }
13 service_stop ()
14 {
15     startstop_nfs stop
16 }
17 service_reconfigure ()
18 {
19     startstop_nfs restart
20
21     # if the ips have been reallocated, we must restart the lockmanager
22     # across all nodes and ping all statd listeners
23     [ -x $CTDB_BASE/statd-callout ] && {
24         $CTDB_BASE/statd-callout notify &
25     } >/dev/null 2>&1
26 }
27
28 loadconfig
29
30 [ "$NFS_SERVER_MODE" != "GANESHA" ] || exit 0
31
32 ctdb_setup_service_state_dir
33
34 statd_update_trigger="$service_state_dir/update-trigger"
35 # We want this file to always exist.  The corner case is when
36 # auto-start/stop is switched off, NFS is added as a managed service
37 # some time after ctdbd is started and someone else starts the NFS
38 # service for us.  In this case this file might not otherwise exist
39 # when we get to a monitor event.
40 touch "$statd_update_trigger"
41
42 ctdb_start_stop_service
43
44 is_ctdb_managed_service || exit 0
45
46 ctdb_service_check_reconfigure
47
48 case "$1" in 
49      init)
50         # read statd from persistent database
51         ;;
52      startup)
53         ctdb_service_start
54         ;;
55
56      shutdown)
57         ctdb_service_stop
58         ;;
59
60      takeip)
61         ctdb_service_set_reconfigure
62         ;;
63
64      releaseip)
65         ctdb_service_set_reconfigure
66         ;;
67
68       monitor)
69         # Check that directories for shares actually exist.
70         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
71             exportfs -v | grep '^/' | 
72             sed -r -e 's@[[:space:]]+[^[:space:]()]+\([^[:space:]()]+\)$@@' | 
73             sort -u | 
74             ctdb_check_directories 
75         } || exit $?
76
77         update_tickles 2049
78
79         # check that statd responds to rpc requests
80         # if statd is not running we try to restart it
81         # we only do this IF we have a rpc.statd command.
82         # For platforms where rpc.statd does not exist, we skip
83         # the check completely
84         p="rpc.statd"
85         which $p >/dev/null 2>/dev/null && \
86             nfs_check_rpc_service "statd" \
87                 -ge 6 "verbose unhealthy" \
88                 -eq 4 "verbose restart" \
89                 -eq 2 "restart:bs"
90
91         # check that NFS responds to rpc requests
92         if [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" != "yes" ] ; then
93             nfs_check_rpc_service "knfsd" \
94                 -ge 6 "verbose unhealthy" \
95                 -eq 4 "verbose restart" \
96                 -eq 2 "restart:bs"
97         fi
98
99         # check that lockd responds to rpc requests
100         nfs_check_rpc_service "lockd" \
101             -ge 15 "verbose restart unhealthy" \
102             -eq 10 "restart:bs"
103
104         # mountd is sometimes not started correctly on RHEL5
105         nfs_check_rpc_service "mountd" \
106             -ge 10 "verbose restart:b unhealthy" \
107             -eq 5 "restart:b"
108
109         # rquotad is sometimes not started correctly on RHEL5
110         # not a critical service so we dont flag the node as unhealthy
111         nfs_check_rpc_service "rquotad" \
112             -gt 0 "verbose restart:b"
113
114         # once every 600 seconds, update the statd state database for which
115         # clients need notifications
116         LAST_UPDATE=`stat --printf="%Y" "$statd_update_trigger"`
117         CURRENT_TIME=`date +"%s"`
118         [ $CURRENT_TIME -ge $(($LAST_UPDATE + 600)) ] && {
119             touch "$statd_update_trigger"
120             $CTDB_BASE/statd-callout updatelocal &
121             $CTDB_BASE/statd-callout updateremote &
122         }
123         ;;
124
125     *)
126         ctdb_standard_event_handler "$@"
127         ;;
128 esac
129
130 exit 0