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:-sysvinit-redhat}"
19 case "$nfs_distro_style" in
24 nfs_config="/etc/sysconfig/nfs"
26 case "$nfs_distro_style" in
28 nfs_lock_service="nfslock"
31 nfs_service="nfsserver"
34 nfs_service="nfs-kernel-server"
35 nfs_config="/etc/default/nfs-kernel-server"
48 # Override for unit testing
49 if [ -z "$PROCFS_PATH" ] ; then
53 ##################################################
59 usage: $_c { shutdown | startup }
60 $_c { stop | start } { nfs | nlockmgr }
61 $_c { monitor-list-shares | monitor-post }
68 ##################################################
69 # Basic service stop and start
75 service "$nfs_service" stop
76 if [ -n "$nfs_lock_service" ] ; then
77 service "$nfs_lock_service" stop
81 if [ -n "$nfs_lock_service" ] ; then
82 service "$nfs_lock_service" stop
84 service "$nfs_service" stop
96 if [ -n "$nfs_lock_service" ] ; then
97 service "$nfs_lock_service" start
99 service "$nfs_service" start
102 if [ -n "$nfs_lock_service" ] ; then
103 service "$nfs_lock_service" start
105 service "$nfs_service" start
113 ##################################################
114 # service "stop" and "start" options for restarting
120 echo 0 >"${PROCFS_PATH}/fs/nfsd/threads"
121 basic_stop "nfs" >/dev/null 2>&1 || true
125 basic_stop "nfslock" >/dev/null 2>&1 || true
139 basic_start "nfslock"
146 ##################################################
147 # service init startup and final shutdown
156 basic_stop "nfs" || true
158 _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
164 ##################################################
165 # monitor-post support
167 nfs_check_thread_count ()
169 # Load NFS configuration to get desired number of threads.
170 if [ -r "$nfs_config" ] ; then
174 # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
175 # guess the default from the initscript. However, let's just
176 # assume that those using the default don't care about the number
177 # of threads and that they have switched on this feature in error.
178 _configured_threads="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
179 [ -n "$_configured_threads" ] || return 0
181 _threads_file="${PROCFS_PATH}/fs/nfsd/threads"
183 # nfsd should be running the configured number of threads. If
184 # there are a different number of threads then tell nfsd the
186 read _running_threads <"$_threads_file" || {
187 echo "WARNING: Reading \"${_threads_file}\" unexpectedly failed"
191 # Intentionally not arithmetic comparison - avoids extra errors
192 # when above read fails in an unexpected way...
193 if [ "$_running_threads" != "$_configured_threads" ] ; then
194 echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
195 echo "$_configured_threads" >"$_threads_file"
199 ##################################################
200 # list share directories
202 nfs_monitor_list_shares ()
204 _cache_file="${CTDB_NFS_CALLOUT_STATE_DIR}/list_shares_cache"
205 # -nt operator is well supported in Linux: dash, bash, ksh, ...
206 # shellcheck disable=SC2039
207 if [ ! -r "$nfs_exports_file" ] || [ ! -r "$_cache_file" ] || \
208 [ "$nfs_exports_file" -nt "$_cache_file" ] ; then
209 mkdir -p "$CTDB_NFS_CALLOUT_STATE_DIR"
210 # We could just use the contents of $nfs_exports_file.
211 # However, let's regard that file as internal to NFS and use
212 # exportfs, which is the public API.
213 if ! _exports=$(exportfs -v) ; then
214 echo "WARNING: failed to run exportfs to list NFS shares" >&2
220 sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' |
221 sort -u >"$_cache_file"
227 ##################################################
241 ##################################################
257 nfs_monitor_list_shares
260 nfs_check_thread_count
265 monitor-pre|releaseip|takeip|releaseip-pre|takeip-pre)
266 # Not required/implemented