ctdb-scripts: Simplify the names of NFS fail counter files
[samba.git] / ctdb / config / events.d / 60.nfs
index 189e2f6203f2e6131894ab81aa148541c532bc5b..f630a3d861ef080866f33489392a018be45d8531 100755 (executable)
@@ -7,8 +7,10 @@
 . "${CTDB_BASE}/functions"
 
 service_name="nfs"
+
 loadconfig
-ctdb_setup_service_state_dir
+
+ctdb_setup_state_dir "service" "$service_name"
 
 ######################################################################
 
@@ -34,6 +36,8 @@ nfs_check_services ()
 
     # Files must end with .check - avoids editor backups, RPM fu, ...
     for _f in "$_dir"/[0-9][0-9].*.check ; do
+       [ -r "$_f" ] || continue
+
        _t="${_f%.check}"
        _progname="${_t##*/[0-9][0-9].}"
 
@@ -115,8 +119,6 @@ nfs_check_service ()
            esac
        done
 
-       _service_name="nfs_${_progname}"
-
        _ok=false
        if [ -n "$service_check_cmd" ] ; then
            # Using eval means variables can contain semicolon separated commands
@@ -136,24 +138,24 @@ nfs_check_service ()
 
        if $_ok ; then
            if [ $unhealthy_after -ne 1 -o $restart_every -ne 0 ] ; then
-               ctdb_counter_init "$_service_name"
+               ctdb_counter_init "$_progname"
            fi
            exit 0
        fi
 
-       ctdb_counter_incr "$_service_name"
-       _failcount=$(ctdb_counter_get "$_service_name")
+       ctdb_counter_incr "$_progname"
+       _failcount=$(ctdb_counter_get "$_progname")
 
        _unhealthy=false
-       if [ $unhealthy_after -gt 0 ] ; then
-           if [ $_failcount -ge $unhealthy_after ] ; then
+       if [ "$unhealthy_after" -gt 0 ] ; then
+           if [ "$_failcount" -ge "$unhealthy_after" ] ; then
                _unhealthy=true
                echo "ERROR: $_err"
            fi
        fi
 
-       if [ $restart_every -gt 0 ] ; then
-           if [ $(($_failcount % $restart_every)) -eq 0 ] ; then
+       if [ "$restart_every" -gt 0 ] ; then
+           if [ $((_failcount % restart_every)) -eq 0 ] ; then
                if ! $_unhealthy ; then
                    echo "WARNING: $_err"
                fi
@@ -205,6 +207,8 @@ ctdb_check_rpc ()
            _localhost="${CTDB_RPCINFO_LOCALHOST:-127.0.0.1}"
     esac
 
+    # $_version is not quoted because it is optional
+    # shellcheck disable=SC2086
     if ! ctdb_check_rpc_out=$(rpcinfo -T "$_family" "$_localhost" \
                                      "$_progname" $_version 2>&1) ; then
        ctdb_check_rpc_out="$_progname failed RPC check:
@@ -243,33 +247,37 @@ nfs_update_lock_info ()
 
 ######################################################################
 
-nfs_callout_init
-
-ctdb_start_stop_service
+# script_state_dir set by ctdb_setup_state_dir()
+# shellcheck disable=SC2154
+nfs_callout_init "$script_state_dir"
 
 is_ctdb_managed_service || exit 0
 
-ctdb_service_check_reconfigure
-
 case "$1" in
 startup)
-       nfs_callout "$@"
+       nfs_callout "$@" || exit $?
        ;;
 
 shutdown)
-        nfs_callout "$@"
+       nfs_callout "$@" || exit $?
        ;;
 
 takeip)
-       nfs_callout "$@"
+       nfs_callout "$@" || exit $?
        ctdb_service_set_reconfigure
        ;;
 
 releaseip)
-       nfs_callout "$@"
+       nfs_callout "$@" || exit $?
        ctdb_service_set_reconfigure
        ;;
 
+ipreallocated)
+       if ctdb_service_needs_reconfigure ; then
+               ctdb_service_reconfigure
+       fi
+       ;;
+
 monitor)
        nfs_callout "monitor-pre" || exit $?