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}"
17 nfs_lock_service
="nfslock"
18 nfs_config
="/etc/sysconfig/nfs"
21 #nfs_service="nfsserver"
23 #nfs_config="/etc/sysconfig/nfs"
26 #nfs_service="nfs-kernel-server"
28 #nfs_config="/etc/default/nfs-kernel-server"
30 # Override for unit testing
31 if [ -z "$PROCFS_PATH" ] ; then
35 ##################################################
41 usage: $_c { shutdown | startup }
42 $_c { stop | start } { nfs | nlockmgr }
43 $_c { monitor-list-shares | monitor-post }
50 ##################################################
51 # Basic service stop and start
57 service
"$nfs_service" stop
58 if [ -n "$nfs_lock_service" ] ; then
59 service
"$nfs_lock_service" stop
63 if [ -n "$nfs_lock_service" ] ; then
64 service
"$nfs_lock_service" stop
66 service
"$nfs_service" stop
78 if [ -n "$nfs_lock_service" ] ; then
79 service
"$nfs_lock_service" start
81 service
"$nfs_service" start
84 if [ -n "$nfs_lock_service" ] ; then
85 service
"$nfs_lock_service" start
87 service
"$nfs_service" start
95 ##################################################
96 # service "stop" and "start" options for restarting
102 echo 0 >"${PROCFS_PATH}/fs/nfsd/threads"
103 basic_stop
"nfs" >/dev
/null
2>&1 || true
107 basic_stop
"nfslock" >/dev
/null
2>&1 || true
121 basic_start
"nfslock"
128 ##################################################
129 # service init startup and final shutdown
138 basic_stop
"nfs" || true
140 _f
="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
146 ##################################################
147 # monitor-post support
149 nfs_check_thread_count
()
151 # Load NFS configuration to get desired number of threads.
152 if [ -r "$nfs_config" ] ; then
156 # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
157 # guess the default from the initscript. However, let's just
158 # assume that those using the default don't care about the number
159 # of threads and that they have switched on this feature in error.
160 _configured_threads
="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
161 [ -n "$_configured_threads" ] ||
return 0
163 _threads_file
="${PROCFS_PATH}/fs/nfsd/threads"
165 # nfsd should be running the configured number of threads. If
166 # there are a different number of threads then tell nfsd the
168 read _running_threads
<"$_threads_file" ||
{
169 echo "WARNING: Reading \"${_threads_file}\" unexpectedly failed"
173 # Intentionally not arithmetic comparison - avoids extra errors
174 # when above read fails in an unexpected way...
175 if [ "$_running_threads" != "$_configured_threads" ] ; then
176 echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
177 echo "$_configured_threads" >"$_threads_file"
181 ##################################################
182 # list share directories
184 nfs_monitor_list_shares
()
186 _cache_file
="${CTDB_NFS_CALLOUT_STATE_DIR}/list_shares_cache"
187 # -nt operator is well supported in Linux: dash, bash, ksh, ...
188 # shellcheck disable=SC2039
189 if [ ! -r "$nfs_exports_file" ] ||
[ ! -r "$_cache_file" ] || \
190 [ "$nfs_exports_file" -nt "$_cache_file" ] ; then
191 mkdir
-p "$CTDB_NFS_CALLOUT_STATE_DIR"
192 # We could just use the contents of $nfs_exports_file.
193 # However, let's regard that file as internal to NFS and use
194 # exportfs, which is the public API.
195 if ! _exports
=$
(exportfs
-v) ; then
196 echo "WARNING: failed to run exportfs to list NFS shares" >&2
202 sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' |
203 sort -u >"$_cache_file"
209 ##################################################
223 ##################################################
239 nfs_monitor_list_shares
242 nfs_check_thread_count
247 monitor-pre|releaseip|takeip|releaseip-pre|takeip-pre
)
248 # Not required/implemented