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