2 # script to manage nfs in a clustered environment
4 [ -n "$CTDB_BASE" ] || \
5 export CTDB_BASE
=$
(cd -P $
(dirname "$0") ; dirname "$PWD")
11 ctdb_setup_service_state_dir
13 ######################################################################
15 if [ -z "$CTDB_NFS_CALLOUT" ] ; then
16 CTDB_NFS_CALLOUT
="${CTDB_BASE}/nfs-linux-kernel-callout"
18 # Always export, for statd callout
19 export CTDB_NFS_CALLOUT
21 # If the callout wants to use this then it must create it
22 export CTDB_NFS_CALLOUT_STATE_DIR
="${service_state_dir}/callout-state"
24 nfs_callout_cache
="${service_state_dir}/nfs_callout_cache"
25 nfs_callout_cache_callout
="${nfs_callout_cache}/CTDB_NFS_CALLOUT"
26 nfs_callout_cache_ops
="${nfs_callout_cache}/ops"
28 nfs_callout_register
()
30 mkdir
-p "$nfs_callout_cache_ops"
31 rm -f "$nfs_callout_cache_ops"/*
33 echo "$CTDB_NFS_CALLOUT" >"$nfs_callout_cache_callout"
35 _t
=$
(eval "$CTDB_NFS_CALLOUT" "register")
36 if [ -n "$_t" ] ; then
38 while IFS
="" read _op
; do
39 touch "${nfs_callout_cache_ops}/${_op}"
42 touch "${nfs_callout_cache_ops}/ALL"
48 # Re-run registration if $CTDB_NFS_CALLOUT has changed
50 if [ -r "$nfs_callout_cache_callout" ] ; then
51 read _prev
<"$nfs_callout_cache_callout"
53 if [ "$CTDB_NFS_CALLOUT" != "$_prev" ] ; then
57 # Run the operation if it is registered...
58 if [ -e "${nfs_callout_cache_ops}/${1}" ] || \
59 [ -e "${nfs_callout_cache_ops}/ALL" ]; then
60 eval "$CTDB_NFS_CALLOUT" "$@"
64 service_reconfigure
()
66 # Restart lock manager, notify clients
67 if [ -x "${CTDB_BASE}/statd-callout" ] ; then
68 "${CTDB_BASE}/statd-callout" notify
&
72 ######################################################################
74 ######################################################
75 # Check the health of NFS services
77 # Use .check files in given directory.
78 # Default is "${CTDB_BASE}/nfs-checks.d/"
79 ######################################################
82 _dir
="${1:-${CTDB_NFS_CHECKS_DIR:-${CTDB_BASE}/nfs-checks.d}}"
84 # Files must end with .check - avoids editor backups, RPM fu, ...
85 for _f
in "$_dir"/[0-9][0-9].
*.check
; do
87 _progname
="${_t##*/[0-9][0-9].}"
89 nfs_check_service
"$_progname" <"$_f"
93 ######################################################
94 # Check the health of an NFS service
96 # $1 - progname, passed to rpcinfo (looked up in /etc/rpc)
98 # Reads variables from stdin
102 # * family - "tcp" or "udp" or space separated list
103 # default: tcp, not used with "service_check_cmd"
104 # * version - optional, RPC service version number
105 # default is to omit to check for any version,
106 # not used with "service_check_cmd"
107 # * unhealthy_after - number of check fails before unhealthy
109 # * restart_every - number of check fails before restart
110 # default: 0, meaning no restart
111 # * service_stop_cmd - command to stop service
112 # default: no default, must be provided if
114 # * service_start_cmd - command to start service
115 # default: no default, must be provided if
117 # * service_check_cmd - command to check health of service
118 # default is to check RPC service using rpcinfo
119 # * service_debug_cmd - command to debug a service after trying to stop it;
120 # for example, it can be useful to print stack
121 # traces of threads that have not exited, since
122 # they may be stuck doing I/O;
123 # no default, see also function program_stack_traces()
125 # Quoting in values is not preserved
127 ######################################################
133 # Subshell to restrict scope variables...
145 # Eval line-by-line. Expands variable references in values.
146 # Also allows variable name checking, which seems useful.
147 while read _line
; do
149 \
#*|"") : ;; # Ignore comments, blank lines
152 unhealthy_after
=*|restart_every
=*|\
153 service_stop_cmd
=*|service_start_cmd
=*|\
154 service_check_cmd
=*|service_debug_cmd
=*)
159 echo "ERROR: Unknown variable for ${_progname}: ${_line}"
164 _service_name
="nfs_${_progname}"
167 if [ -n "$service_check_cmd" ] ; then
168 # Using eval means variables can contain semicolon separated commands
169 if eval "$service_check_cmd" ; then
173 if nfs_check_rpcinfo \
174 "$_progname" "$version" "$family" >/dev
/null
; then
180 if [ $unhealthy_after -ne 1 -o $restart_every -ne 0 ] ; then
181 ctdb_counter_init
"$_service_name"
186 ctdb_counter_incr
"$_service_name"
187 _failcount
=$
(ctdb_counter_get
"$_service_name")
190 if [ $unhealthy_after -gt 0 ] ; then
191 if [ $_failcount -ge $unhealthy_after ] ; then
193 echo "ERROR: $ctdb_check_rpc_out"
197 if [ $restart_every -gt 0 ] ; then
198 if [ $
(($_failcount % $restart_every)) -eq 0 ] ; then
199 if ! $_unhealthy ; then
200 echo "WARNING: $ctdb_check_rpc_out"
206 if $_unhealthy ; then
214 # Uses: stop_service, start_service, debug_stuck_threads
215 nfs_restart_service
()
217 if [ -z "$service_stop_cmd" -o -z "$service_start_cmd" ] ; then
218 die
"ERROR: Can not restart service \"${_progname}\" without corresponding service_start_cmd/service_stop_cmd settings"
221 echo "Trying to restart service \"${_progname}\"..."
222 # Using eval means variables can contain semicolon separated commands
223 eval "$service_stop_cmd"
224 if [ -n "$service_debug_cmd" ] ; then
225 eval "$service_debug_cmd"
227 background_with_logging
eval "$service_start_cmd"
230 ######################################################
231 # Check an RPC service with rpcinfo
232 ######################################################
235 _progname
="$1" # passed to rpcinfo (looked up in /etc/rpc)
236 _version
="$2" # optional, not passed if empty/unset
237 _family
="${3:-tcp}" # optional, default is "tcp"
241 _localhost
="${CTDB_RPCINFO_LOCALHOST6:-::1}"
244 _localhost
="${CTDB_RPCINFO_LOCALHOST:-127.0.0.1}"
247 if ! ctdb_check_rpc_out
=$
(rpcinfo
-T $_family $_localhost \
248 $_progname $_version 2>&1) ; then
249 ctdb_check_rpc_out
="$_progname failed RPC check:
251 echo "$ctdb_check_rpc_out"
258 _progname
="$1" # passed to rpcinfo (looked up in /etc/rpc)
259 _versions
="$2" # optional, space separated, not passed if empty/unset
260 _families
="${3:-tcp}" # optional, space separated, default is "tcp"
262 for _family
in $_families ; do
263 if [ -n "$_versions" ] ; then
264 for _version
in $_versions ; do
265 ctdb_check_rpc
$_progname $_version $_family ||
return $?
268 ctdb_check_rpc
$_progname "" $_family ||
return $?
273 ##################################################################
274 # use statd-callout to update NFS lock info
275 ##################################################################
276 nfs_update_lock_info
()
278 if [ -x "$CTDB_BASE/statd-callout" ] ; then
279 "$CTDB_BASE/statd-callout" update
283 ######################################################################
285 ctdb_start_stop_service
287 is_ctdb_managed_service ||
exit 0
289 ctdb_service_check_reconfigure
302 ctdb_service_set_reconfigure
307 ctdb_service_set_reconfigure
311 nfs_callout
"monitor-pre" ||
exit $?
313 # Check that directories for shares actually exist
314 if [ "$CTDB_NFS_SKIP_SHARE_CHECK" != "yes" ] ; then
315 nfs_callout
"monitor-list-shares" | ctdb_check_directories || \
324 nfs_callout
"monitor-post" ||
exit $?
328 ctdb_standard_event_handler
"$@"