c4e798e2ca9ba4a202c49fe13c5650368a2259de
[samba.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 nfs_check_thread_count ()
30 {
31     [ "$CTDB_MONITOR_NFS_THREAD_COUNT" = "yes" ] || return 0
32
33     # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
34     # guess the default from the initscript.  However, let's just
35     # assume that those using the default don't care about the number
36     # of threads and that they have switched on this feature in error.
37     _configured_threads="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
38     [ -n "$_configured_threads" ] || return 0
39
40     # nfsd should be running the configured number of threads.  If
41     # there are a different number of threads then tell nfsd the
42     # correct number.  
43     _running_threads=$(get_proc "fs/nfsd/threads")
44     # Intentionally not arithmetic comparison - avoids extra errors
45     # when get_proc() fails...
46     if [ "$_running_threads" != "$_configured_threads" ] ; then
47         echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
48         set_proc "fs/nfsd/threads" "$_configured_threads"
49     fi
50 }
51
52 loadconfig
53
54 [ "${CTDB_NFS_SERVER_MODE:-${NFS_SERVER_MODE}}" != "ganesha" ] || exit 0
55
56 ctdb_setup_service_state_dir
57
58 ctdb_start_stop_service
59
60 is_ctdb_managed_service || exit 0
61
62 ctdb_service_check_reconfigure
63
64 case "$1" in 
65      init)
66         # read statd from persistent database
67         ;;
68      startup)
69         ctdb_service_start
70         ;;
71
72      shutdown)
73         ctdb_service_stop
74         ;;
75
76      takeip)
77         ctdb_service_set_reconfigure
78         ;;
79
80      releaseip)
81         ctdb_service_set_reconfigure
82         ;;
83
84       monitor)
85         # Check that directories for shares actually exist.
86         [ "$CTDB_NFS_SKIP_SHARE_CHECK" = "yes" ] || {
87             exportfs -v | grep '^/' | 
88             sed -r -e 's@[[:space:]]+[^[:space:]()]+\([^[:space:]()]+\)$@@' | 
89             sort -u | 
90             ctdb_check_directories 
91         } || exit $?
92
93         update_tickles 2049
94
95         nfs_check_rpc_services
96
97         nfs_check_thread_count
98         ;;
99
100     *)
101         ctdb_standard_event_handler "$@"
102         ;;
103 esac
104
105 exit 0