eventscripts: 60.nfs uses nfs_check_rpc_services() to check NFS RPC services
[nivanova/samba-autobuild/.git] / ctdb / config / events.d / 60.nfs
1 #!/bin/sh
2 # script to manage nfs in a clustered environment
3
4 [ -n "$CTDB_BASE" ] || \
5     export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
6
7 . $CTDB_BASE/functions
8
9 service_name="nfs"
10 service_start ()
11 {
12     startstop_nfs stop
13     startstop_nfs start
14     set_proc "sys/net/ipv4/tcp_tw_recycle" 1
15 }
16 service_stop ()
17 {
18     startstop_nfs stop
19 }
20 service_reconfigure ()
21 {
22     # if the ips have been reallocated, we must restart the lockmanager
23     # across all nodes and ping all statd listeners
24     [ -x $CTDB_BASE/statd-callout ] && {
25         $CTDB_BASE/statd-callout notify &
26     } >/dev/null 2>&1
27 }
28
29 loadconfig
30
31 [ "$NFS_SERVER_MODE" != "ganesha" ] || exit 0
32
33 ctdb_setup_service_state_dir
34
35 statd_update_trigger="$service_state_dir/update-trigger"
36 # We want this file to always exist.  The corner case is when
37 # auto-start/stop is switched off, NFS is added as a managed service
38 # some time after ctdbd is started and someone else starts the NFS
39 # service for us.  In this case this file might not otherwise exist
40 # when we get to a monitor event.
41 touch "$statd_update_trigger"
42
43 ctdb_start_stop_service
44
45 is_ctdb_managed_service || exit 0
46
47 ctdb_service_check_reconfigure
48
49 case "$1" in 
50      init)
51         # read statd from persistent database
52         ;;
53      startup)
54         ctdb_service_start
55         ;;
56
57      shutdown)
58         ctdb_service_stop
59         ;;
60
61      takeip)
62         ctdb_service_set_reconfigure
63         ;;
64
65      releaseip)
66         ctdb_service_set_reconfigure
67         ;;
68
69       monitor)
70         # Check that directories for shares actually exist.
71         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
72             exportfs -v | grep '^/' | 
73             sed -r -e 's@[[:space:]]+[^[:space:]()]+\([^[:space:]()]+\)$@@' | 
74             sort -u | 
75             ctdb_check_directories 
76         } || exit $?
77
78         update_tickles 2049
79
80         nfs_check_rpc_services
81
82         # once every 600 seconds, update the statd state database for which
83         # clients need notifications
84         LAST_UPDATE=`stat --printf="%Y" "$statd_update_trigger"`
85         CURRENT_TIME=`date +"%s"`
86         [ $CURRENT_TIME -ge $(($LAST_UPDATE + 600)) ] && {
87             touch "$statd_update_trigger"
88             $CTDB_BASE/statd-callout updatelocal &
89             $CTDB_BASE/statd-callout updateremote &
90         }
91         ;;
92
93     *)
94         ctdb_standard_event_handler "$@"
95         ;;
96 esac
97
98 exit 0