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 # As above, edit the default value below. CTDB_SYS_ETCDIR is a
21 etc_dir
="${CTDB_SYS_ETCDIR:-/etc}"
23 # A value of "AUTO" for any service means that service is usually
24 # automatically started and stopped by one of the other services.
25 # Such services will still be restarted by hand on failure, if
26 # configured to do so. This allows services that should not be
27 # running to be set to "".
29 case "$nfs_distro_style" in
32 nfs_service
="nfs-server"
33 nfs_lock_service
="rpc-statd"
34 nfs_mountd_service
="nfs-mountd"
35 nfs_status_service
="rpc-statd"
36 nfs_rquotad_service
="rpc-rquotad"
37 nfs_config
="${etc_dir}/sysconfig/nfs"
38 nfs_rquotad_config
="" # Not use with systemd, restart via service
40 case "$nfs_distro_style" in
45 nfs_rquotad_service
="quotarpc"
57 nfs_lock_service
="AUTO"
58 nfs_mountd_service
="AUTO"
59 nfs_status_service
="AUTO"
60 nfs_rquotad_service
="AUTO"
61 nfs_config
="${etc_dir}/sysconfig/nfs"
62 nfs_rquotad_config
="$nfs_config"
64 case "$nfs_distro_style" in
66 nfs_lock_service
="nfslock"
69 nfs_service
="nfsserver"
72 nfs_service
="nfs-kernel-server"
73 nfs_config
="${etc_dir}/default/nfs-kernel-server"
74 nfs_rquotad_config
="${etc_dir}/default/quota"
89 # Override for unit testing
90 if [ -z "$PROCFS_PATH" ]; then
94 ##################################################
100 usage: $_c { shutdown | startup }
101 $_c { stop | start } { nfs | nlockmgr }
102 $_c { monitor-list-shares | monitor-post }
108 ##################################################
112 _config
="${1:-${nfs_config}}"
114 if [ -r "$_config" ]; then
119 ##################################################
121 service_is_auto_started
()
130 [ -n "$_service" ] && ! service_is_auto_started
"$_service"
138 if service_is_defined
"$_service"; then
139 service
"$_service" "$_action"
143 ##################################################
144 # Overall NFS service stop and start
148 service_if_defined
"$nfs_rquotad_service" stop
150 service
"$nfs_service" stop
152 service_if_defined
"$nfs_lock_service" stop
157 service_if_defined
"$nfs_lock_service" start
159 service
"$nfs_service" start
161 service_if_defined
"$nfs_rquotad_service" start
164 ##################################################
165 # service "stop" and "start" options for restarting
171 killall
-q -9 rpc.mountd
174 killall
-q -9 rpc.rquotad
177 killall
-q -9 rpc.statd
180 echo "$0: Internal error - invalid call to manual_stop()"
186 service_or_manual_stop
()
191 if service_is_defined
"$_system_service"; then
192 service
"$_system_service" stop
193 elif service_is_auto_started
"$_system_service"; then
194 manual_stop
"$_rpc_service"
202 case "$_rpc_service" in
204 echo 0 >"${PROCFS_PATH}/fs/nfsd/threads"
205 nfs_service_stop
>/dev
/null
2>&1 || true
209 if service_is_defined
"$nfs_lock_service" ; then
210 service
"$nfs_lock_service" stop
>/dev
/null
2>&1 || true
212 service
"$nfs_service" stop
>/dev
/null
2>&1 || true
216 service_or_manual_stop
"$_rpc_service" "$nfs_mountd_service"
219 service_or_manual_stop
"$_rpc_service" "$nfs_rquotad_service"
222 service_or_manual_stop
"$_rpc_service" "$nfs_status_service"
235 if [ -z "$RPCMOUNTDOPTS" ]; then
236 RPCMOUNTDOPTS
="${MOUNTD_PORT:+-p }$MOUNTD_PORT"
238 # shellcheck disable=SC2086
239 rpc.mountd
$RPCMOUNTDOPTS
242 nfs_load_config
"$nfs_rquotad_config"
243 if [ -z "$RPCRQUOTADOPTS" ]; then
244 RPCRQUOTADOPTS
="${RQUOTAD_PORT:+-p }$RQUOTAD_PORT"
246 # shellcheck disable=SC2086
247 rpc.rquotad
$RPCRQUOTADOPTS
251 # Red Hat uses STATDARG, Debian uses STATDOPTS
252 opts
="${STATDARG:-${STATDOPTS:-''}}"
253 if [ -z "$opts" ]; then
254 # shellcheck disable=SC2086
256 ${STATD_HA_CALLOUT:+-H} $STATD_HA_CALLOUT \
257 ${STATD_HOSTNAME:+-n} $STATD_HOSTNAME \
258 ${STATD_PORT:+-p} $STATD_PORT \
259 ${STATD_OUTGOING_PORT:+-o} $STATD_OUTGOING_PORT
262 # shellcheck disable=SC2086
266 echo "$0: Internal error - invalid call to manual_start()"
272 service_or_manual_start
()
277 if service_is_defined
"$_system_service"; then
278 service
"$_system_service" start
279 elif service_is_auto_started
"$_system_service"; then
280 manual_start
"$_rpc_service"
288 case "$_rpc_service" in
293 if service_is_defined
"$nfs_lock_service" ; then
294 service
"$nfs_lock_service" start
296 service
"$nfs_service" start
300 service_or_manual_start
"$_rpc_service" "$nfs_mountd_service"
303 service_or_manual_start
"$_rpc_service" "$nfs_rquotad_service"
306 service_or_manual_start
"$_rpc_service" "$nfs_status_service"
314 ##################################################
315 # service init startup and final shutdown
324 nfs_service_stop || true
326 _f
="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
327 if [ -f "$_f" ]; then
332 ##################################################
333 # monitor-post support
335 nfs_check_thread_count
()
337 # Load NFS configuration to get desired number of threads.
340 # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
341 # guess the default from the initscript. However, let's just
342 # assume that those using the default don't care about the number
343 # of threads and that they have switched on this feature in error.
344 _configured_threads
="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
345 if [ -z "$_configured_threads" ] && type nfsconf
>/dev
/null
2>&1; then
346 _configured_threads
=$
(nfsconf
--get nfsd threads
) || true
348 [ -n "$_configured_threads" ] ||
return 0
350 _threads_file
="${PROCFS_PATH}/fs/nfsd/threads"
352 # nfsd should be running the configured number of threads. If
353 # there are a different number of threads then tell nfsd the
355 read -r _running_threads
<"$_threads_file" ||
{
356 echo "WARNING: Reading \"${_threads_file}\" unexpectedly failed"
360 # Intentionally not arithmetic comparison - avoids extra errors
361 # when above read fails in an unexpected way...
362 if [ "$_running_threads" != "$_configured_threads" ]; then
363 echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
364 echo "$_configured_threads" >"$_threads_file"
368 ##################################################
369 # list share directories
371 nfs_monitor_list_shares
()
373 _cache_file
="${CTDB_NFS_CALLOUT_STATE_DIR}/list_shares_cache"
374 # -nt operator is well supported in Linux: dash, bash, ksh, ...
375 # shellcheck disable=SC2039,SC3013
376 if [ ! -r "$nfs_exports_file" ] ||
[ ! -r "$_cache_file" ] ||
377 [ "$nfs_exports_file" -nt "$_cache_file" ]; then
378 mkdir
-p "$CTDB_NFS_CALLOUT_STATE_DIR"
379 # We could just use the contents of $nfs_exports_file.
380 # However, let's regard that file as internal to NFS and use
381 # exportfs, which is the public API.
382 if ! _exports
=$
(exportfs
-v); then
383 echo "WARNING: failed to run exportfs to list NFS shares" >&2
389 sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' |
390 sort -u >"$_cache_file"
396 ##################################################
410 ##################################################
426 nfs_monitor_list_shares
429 nfs_check_thread_count
434 monitor-pre | releaseip | takeip | releaseip-pre | takeip-pre
)
435 # Not required/implemented