2 # script to manage nfs in a clustered environment
5 /bin/mkdir -p $CTDB_VARDIR/state/nfs
6 /bin/mkdir -p $CTDB_VARDIR/state/statd/ip
9 echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
12 . $CTDB_BASE/functions
15 service_start="start_nfs"
16 service_stop="startstop_nfs stop"
17 service_reconfigure="startstop_nfs restart"
19 nfs_check_thread_count ()
21 [ "$CTDB_MONITOR_NFS_THREAD_COUNT" = "yes" ] || return 0
23 # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
24 # guess the default from the initscript. However, let's just
25 # assume that those using the default don't care about the number
26 # of threads and that they have switched on this feature in error.
27 _configured_threads="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
28 [ -n "$_configured_threads" ] || return 0
30 # nfsd should be running the configured number of threads. If
31 # there are a different number of threads then tell nfsd the
33 _running_threads=$(get_proc "fs/nfsd/threads")
34 # Intentionally not arithmetic comparison - avoids extra errors
35 # when get_proc() fails...
36 if [ "$_running_threads" != "$_configured_threads" ] ; then
37 echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
38 set_proc "fs/nfsd/threads" "$_configured_threads"
44 [ "$NFS_SERVER_MODE" != "GANESHA" ] || exit 0
46 ctdb_start_stop_service
48 is_ctdb_managed_service || exit 0
52 # read statd from persistent database
56 mkdir -p $CTDB_VARDIR/state/statd
57 touch $CTDB_VARDIR/state/statd/update-trigger
65 ctdb_service_set_reconfigure
69 ctdb_service_set_reconfigure
73 if ctdb_service_needs_reconfigure ; then
74 ctdb_service_reconfigure
80 # check that statd responds to rpc requests
81 # if statd is not running we try to restart it
82 # we only do this IF we have a rpc.statd command.
83 # For platforms where rpc.statd does not exist, we skip
84 # the check completely
86 which $p >/dev/null 2>/dev/null && {
87 if ctdb_check_rpc "STATD" 100024 1 >/dev/null ; then
88 (service_name="nfs_statd"; ctdb_counter_init)
91 cmd="${cmd}${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
92 cmd="${cmd}${STATD_PORT:+ -p }${STATD_PORT}"
93 cmd="${cmd}${STATD_OUTGOING_PORT:+ -o }${STATD_OUTGOING_PORT}"
95 service_name="nfs_statd"
97 ctdb_check_counter_limit 10 quiet >/dev/null
99 echo "$ctdb_check_rpc_out"
100 echo "Trying to restart STATD [$cmd]"
106 # check that NFS responds to rpc requests
107 if [ "$CTDB_NFS_SKIP_KNFSD_ALIVE_CHECK" != "yes" ] ; then
108 if ctdb_check_rpc "NFS" 100003 3 >/dev/null ; then
109 ctdb_counter_init "nfs_knfsd"
111 ctdb_counter_incr "nfs_knfsd"
113 if ! ctdb_check_counter "quiet" % 10 "nfs_knfsd" ; then
114 echo "Trying to restart NFS service"
115 startstop_nfs restart >/dev/null 2>&1 &
118 ctdb_check_counter "error" -ge 2 "nfs_knfsd"
122 # check that lockd responds to rpc requests
123 if ctdb_check_rpc "LOCKD" 100021 1 >/dev/null ; then
124 (service_name="lockd"; ctdb_counter_init)
130 ctdb_check_counter_equal 10 || {
131 echo "Trying to restart NFS lock service"
132 startstop_nfs restart >/dev/null 2>&1 &
133 startstop_nfslock restart >/dev/null 2>&1 &
137 ctdb_check_counter_limit 15 quiet >/dev/null
139 echo "$ctdb_check_rpc_out"
140 echo "Trying to restart NFS lock service"
141 startstop_nfs restart
142 startstop_nfslock restart
147 # mount needs special handling since it is sometimes not started
149 if ctdb_check_rpc "MOUNTD" 100005 1 >/dev/null ; then
150 (service_name="nfs_mountd"; ctdb_counter_init)
153 service_name="nfs_mountd"
156 ctdb_check_counter_equal 5 || {
158 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
159 echo "Trying to restart MOUNTD [${cmd}]"
165 ctdb_check_counter_limit 10 quiet >/dev/null
167 echo "$ctdb_check_rpc_out"
169 cmd="${p}${MOUNTD_PORT:+ -p }${MOUNTD_PORT}"
170 echo "Trying to restart MOUNTD [${cmd}]"
178 # rquotad needs special handling since it is sometimes not started
180 # this is not a critical service so we dont flag the node as unhealthy
181 ctdb_check_rpc "RQUOTAD" 100011 1 || {
183 cmd="${p}${RQUOTAD_PORT:+ -p }${RQUOTAD_PORT}"
184 echo "Trying to restart RQUOTAD [${cmd}]"
189 nfs_check_thread_count
191 # once every 600 seconds, update the statd state database for which
192 # clients need notifications
193 LAST_UPDATE=`stat --printf="%Y" $CTDB_VARDIR/state/statd/update-trigger 2>/dev/null`
194 CURRENT_TIME=`date +"%s"`
195 [ $CURRENT_TIME -ge $(($LAST_UPDATE + 600)) ] && {
196 mkdir -p $CTDB_VARDIR/state/statd
197 touch $CTDB_VARDIR/state/statd/update-trigger
198 $CTDB_BASE/statd-callout updatelocal &
199 $CTDB_BASE/statd-callout updateremote &
204 # if the ips have been reallocated, we must restart the lockmanager
205 # across all nodes and ping all statd listeners
206 [ -x $CTDB_BASE/statd-callout ] && {
207 $CTDB_BASE/statd-callout notify &
211 ctdb_standard_event_handler "$@"