pylibsmb: Add smb2 create tag strings
[Samba.git] / ctdb / config / nfs-linux-kernel-callout
blobf2f3e3824d00ed105ad9f19d10881103c4051b4f
1 #!/bin/sh
3 # Exit on 1st error
4 set -e
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
12 # hook for testing.
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
16 # test variable only.
17 nfs_distro_style="${CTDB_NFS_DISTRO_STYLE:-systemd-redhat}"
19 # As above, edit the default value below. CTDB_SYS_ETCDIR is a
20 # test variable only.
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
30 systemd-*)
31 # Defaults
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
41 *-redhat | *-suse)
42 : # Defaults only
44 *-debian)
45 nfs_rquotad_service="quotarpc"
48 echo "Internal error"
49 exit 1
51 esac
54 sysvinit-*)
55 # Defaults
56 nfs_service="nfs"
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
65 *-redhat)
66 nfs_lock_service="nfslock"
68 *-suse)
69 nfs_service="nfsserver"
71 *-debian)
72 nfs_service="nfs-kernel-server"
73 nfs_config="${etc_dir}/default/nfs-kernel-server"
74 nfs_rquotad_config="${etc_dir}/default/quota"
77 echo "Internal error"
78 exit 1
80 esac
84 echo "Internal error"
85 exit 1
87 esac
89 # Override for unit testing
90 if [ -z "$PROCFS_PATH" ]; then
91 PROCFS_PATH="/proc"
94 ##################################################
96 usage()
98 _c=$(basename "$0")
99 cat <<EOF
100 usage: $_c { shutdown | startup }
101 $_c { stop | start } { nfs | nlockmgr }
102 $_c { monitor-list-shares | monitor-post }
103 $_c { register }
105 exit 1
108 ##################################################
110 nfs_load_config()
112 _config="${1:-${nfs_config}}"
114 if [ -r "$_config" ]; then
115 . "$_config"
119 ##################################################
121 service_is_auto_started()
123 [ "$1" = "AUTO" ]
126 service_is_defined()
128 _service="$1"
130 [ -n "$_service" ] && ! service_is_auto_started "$_service"
133 service_if_defined()
135 _service="$1"
136 _action="$2"
138 if service_is_defined "$_service"; then
139 service "$_service" "$_action"
143 ##################################################
144 # Overall NFS service stop and start
146 nfs_service_stop()
148 service_if_defined "$nfs_rquotad_service" stop
150 service "$nfs_service" stop
152 service_if_defined "$nfs_lock_service" stop
155 nfs_service_start()
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
167 manual_stop()
169 case "$1" in
170 mountd)
171 killall -q -9 rpc.mountd
173 rquotad)
174 killall -q -9 rpc.rquotad
176 status)
177 killall -q -9 rpc.statd
180 echo "$0: Internal error - invalid call to manual_stop()"
181 exit 1
183 esac
186 service_or_manual_stop()
188 _rpc_service="$1"
189 _system_service="$2"
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"
198 service_stop()
200 _rpc_service="$1"
202 case "$_rpc_service" in
203 nfs)
204 echo 0 >"${PROCFS_PATH}/fs/nfsd/threads"
205 nfs_service_stop >/dev/null 2>&1 || true
206 pkill -9 nfsd
208 nlockmgr)
209 if service_is_defined "$nfs_lock_service" ; then
210 service "$nfs_lock_service" stop >/dev/null 2>&1 || true
211 else
212 service "$nfs_service" stop >/dev/null 2>&1 || true
215 mountd)
216 service_or_manual_stop "$_rpc_service" "$nfs_mountd_service"
218 rquotad)
219 service_or_manual_stop "$_rpc_service" "$nfs_rquotad_service"
221 status)
222 service_or_manual_stop "$_rpc_service" "$nfs_status_service"
225 usage
227 esac
230 manual_start()
232 case "$1" in
233 mountd)
234 nfs_load_config
235 if [ -z "$RPCMOUNTDOPTS" ]; then
236 RPCMOUNTDOPTS="${MOUNTD_PORT:+-p }$MOUNTD_PORT"
238 # shellcheck disable=SC2086
239 rpc.mountd $RPCMOUNTDOPTS
241 rquotad)
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
249 status)
250 nfs_load_config
251 # Red Hat uses STATDARG, Debian uses STATDOPTS
252 opts="${STATDARG:-${STATDOPTS:-''}}"
253 if [ -z "$opts" ]; then
254 # shellcheck disable=SC2086
255 set -- \
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
260 opts="$*"
262 # shellcheck disable=SC2086
263 rpc.statd $opts
266 echo "$0: Internal error - invalid call to manual_start()"
267 exit 1
269 esac
272 service_or_manual_start()
274 _rpc_service="$1"
275 _system_service="$2"
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"
284 service_start()
286 _rpc_service="$1"
288 case "$_rpc_service" in
289 nfs)
290 nfs_service_start
292 nlockmgr)
293 if service_is_defined "$nfs_lock_service" ; then
294 service "$nfs_lock_service" start
295 else
296 service "$nfs_service" start
299 mountd)
300 service_or_manual_start "$_rpc_service" "$nfs_mountd_service"
302 rquotad)
303 service_or_manual_start "$_rpc_service" "$nfs_rquotad_service"
305 status)
306 service_or_manual_start "$_rpc_service" "$nfs_status_service"
309 usage
311 esac
314 ##################################################
315 # service init startup and final shutdown
317 nfs_shutdown()
319 nfs_service_stop
322 nfs_startup()
324 nfs_service_stop || true
325 nfs_service_start
326 _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
327 if [ -f "$_f" ]; then
328 echo 1 >"$_f"
332 ##################################################
333 # monitor-post support
335 nfs_check_thread_count()
337 # Load NFS configuration to get desired number of threads.
338 nfs_load_config
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
354 # correct number.
355 read -r _running_threads <"$_threads_file" || {
356 echo "WARNING: Reading \"${_threads_file}\" unexpectedly failed"
357 exit 0
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
384 return
387 echo "$_exports" |
388 grep '^/' |
389 sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' |
390 sort -u >"$_cache_file"
393 cat "$_cache_file"
396 ##################################################
398 nfs_register()
400 cat <<EOF
401 shutdown
402 startup
403 stop
404 start
405 monitor-list-shares
406 monitor-post
410 ##################################################
412 case "$1" in
413 shutdown)
414 nfs_shutdown
416 startup)
417 nfs_startup
419 stop)
420 service_stop "$2"
422 start)
423 service_start "$2"
425 monitor-list-shares)
426 nfs_monitor_list_shares
428 monitor-post)
429 nfs_check_thread_count
431 register)
432 nfs_register
434 monitor-pre | releaseip | takeip | releaseip-pre | takeip-pre)
435 # Not required/implemented
439 usage
441 esac