6 # NFS exports file. Some code below keeps a cache of output derived
7 # from exportfs(8). When this file is updated the cache is invalid
8 # and needs to be regenerated.
10 # To change the file, edit the default value below. Do not set
11 # CTDB_NFS_EXPORTS_FILE - it isn't a configuration variable, just a
13 nfs_exports_file="${CTDB_NFS_EXPORTS_FILE:-/var/lib/nfs/etab}"
15 # As above, edit the default value below. CTDB_NFS_DISTRO_STYLE is a
17 nfs_distro_style="${CTDB_NFS_DISTRO_STYLE:-systemd-redhat}"
19 case "$nfs_distro_style" in
22 nfs_service="nfs-server"
23 nfs_lock_service="rpc-statd"
24 nfs_mountd_service="nfs-mountd"
25 nfs_status_service="rpc-statd"
26 nfs_rquotad_service="rpc-rquotad"
27 nfs_config="/etc/sysconfig/nfs"
28 nfs_rquotad_config="" # Not use with systemd, restart via service
30 case "$nfs_distro_style" in
35 nfs_rquotad_service="quotarpc"
49 nfs_rquotad_service=""
50 nfs_config="/etc/sysconfig/nfs"
51 nfs_rquotad_config="$nfs_config"
53 case "$nfs_distro_style" in
55 nfs_lock_service="nfslock"
58 nfs_service="nfsserver"
61 nfs_service="nfs-kernel-server"
62 nfs_config="/etc/default/nfs-kernel-server"
63 nfs_rquotad_config="/etc/default/quota"
76 # Override for unit testing
77 if [ -z "$PROCFS_PATH" ] ; then
81 ##################################################
87 usage: $_c { shutdown | startup }
88 $_c { stop | start } { nfs | nlockmgr }
89 $_c { monitor-list-shares | monitor-post }
95 ##################################################
99 _config="${1:-${nfs_config}}"
101 if [ -r "$_config" ] ; then
106 ##################################################
107 # Basic service stop and start
113 if [ -n "$nfs_rquotad_service" ] ; then
114 service "$nfs_rquotad_service" stop
117 service "$nfs_service" stop
119 if [ -n "$nfs_lock_service" ] ; then
120 service "$nfs_lock_service" stop
124 if [ -n "$nfs_lock_service" ] ; then
125 service "$nfs_lock_service" stop
127 service "$nfs_service" stop
139 if [ -n "$nfs_lock_service" ] ; then
140 service "$nfs_lock_service" start
143 service "$nfs_service" start
145 if [ -n "$nfs_rquotad_service" ] ; then
146 service "$nfs_rquotad_service" start
150 if [ -n "$nfs_lock_service" ] ; then
151 service "$nfs_lock_service" start
153 service "$nfs_service" start
161 ##################################################
162 # service "stop" and "start" options for restarting
168 echo 0 >"${PROCFS_PATH}/fs/nfsd/threads"
169 basic_stop "nfs" >/dev/null 2>&1 || true
173 basic_stop "nfslock" >/dev/null 2>&1 || true
176 if [ -n "$nfs_mountd_service" ] ; then
177 service "$nfs_mountd_service" stop
181 # Default to stopping by hand
182 killall -q -9 rpc.mountd
185 if [ -n "$nfs_rquotad_service" ] ; then
186 service "$nfs_rquotad_service" stop
190 # Default to stopping by hand
191 killall -q -9 rpc.rquotad
194 if [ -n "$nfs_status_service" ] ; then
195 service "$nfs_status_service" stop
199 # Default to stopping by hand
200 killall -q -9 rpc.statd
214 basic_start "nfslock"
217 if [ -n "$nfs_mountd_service" ] ; then
218 service "$nfs_mountd_service" start
222 # Default to starting by hand
224 if [ -z "$RPCMOUNTDOPTS" ] ; then
225 RPCMOUNTDOPTS="${MOUNTD_PORT:+-p }$MOUNTD_PORT"
227 # shellcheck disable=SC2086
228 rpc.mountd $RPCMOUNTDOPTS
231 if [ -n "$nfs_rquotad_service" ] ; then
232 service "$nfs_rquotad_service" start
236 # Default to starting by hand
237 nfs_load_config "$nfs_rquotad_config"
238 if [ -z "$RPCRQUOTADOPTS" ] ; then
239 RPCRQUOTADOPTS="${RQUOTAD_PORT:+-p }$RQUOTAD_PORT"
241 # shellcheck disable=SC2086
242 rpc.rquotad $RPCRQUOTADOPTS
245 if [ -n "$nfs_status_service" ] ; then
246 service "$nfs_status_service" start
250 # Default to starting by hand
252 # Red Hat uses STATDARG, Debian uses STATDOPTS
253 opts="${STATDARG:-${STATDOPTS:-''}}"
254 if [ -z "$opts" ] ; then
255 # shellcheck disable=SC2086
257 ${STATD_HA_CALLOUT:+-H} $STATD_HA_CALLOUT \
258 ${STATD_HOSTNAME:+-n} $STATD_HOSTNAME \
259 ${STATD_PORT:+-p} $STATD_PORT \
260 ${STATD_OUTGOING_PORT:+-o} $STATD_OUTGOING_PORT
263 # shellcheck disable=SC2086
271 ##################################################
272 # service init startup and final shutdown
281 basic_stop "nfs" || true
283 _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
284 if [ -f "$_f" ] ; then
289 ##################################################
290 # monitor-post support
292 nfs_check_thread_count ()
294 # Load NFS configuration to get desired number of threads.
297 # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
298 # guess the default from the initscript. However, let's just
299 # assume that those using the default don't care about the number
300 # of threads and that they have switched on this feature in error.
301 _configured_threads="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
302 if [ -z "$_configured_threads" ] && type nfsconf >/dev/null 2>&1 ; then
303 _configured_threads=$(nfsconf --get nfsd threads) || true
305 [ -n "$_configured_threads" ] || return 0
307 _threads_file="${PROCFS_PATH}/fs/nfsd/threads"
309 # nfsd should be running the configured number of threads. If
310 # there are a different number of threads then tell nfsd the
312 read _running_threads <"$_threads_file" || {
313 echo "WARNING: Reading \"${_threads_file}\" unexpectedly failed"
317 # Intentionally not arithmetic comparison - avoids extra errors
318 # when above read fails in an unexpected way...
319 if [ "$_running_threads" != "$_configured_threads" ] ; then
320 echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
321 echo "$_configured_threads" >"$_threads_file"
325 ##################################################
326 # list share directories
328 nfs_monitor_list_shares ()
330 _cache_file="${CTDB_NFS_CALLOUT_STATE_DIR}/list_shares_cache"
331 # -nt operator is well supported in Linux: dash, bash, ksh, ...
332 # shellcheck disable=SC2039
333 if [ ! -r "$nfs_exports_file" ] || [ ! -r "$_cache_file" ] || \
334 [ "$nfs_exports_file" -nt "$_cache_file" ] ; then
335 mkdir -p "$CTDB_NFS_CALLOUT_STATE_DIR"
336 # We could just use the contents of $nfs_exports_file.
337 # However, let's regard that file as internal to NFS and use
338 # exportfs, which is the public API.
339 if ! _exports=$(exportfs -v) ; then
340 echo "WARNING: failed to run exportfs to list NFS shares" >&2
346 sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' |
347 sort -u >"$_cache_file"
353 ##################################################
367 ##################################################
383 nfs_monitor_list_shares
386 nfs_check_thread_count
391 monitor-pre|releaseip|takeip|releaseip-pre|takeip-pre)
392 # Not required/implemented