ctdb-scripts: Stop/start mount/rquotad/status via NFS call-out
authorMartin Schwenke <martin@meltin.net>
Wed, 20 Mar 2019 06:35:44 +0000 (17:35 +1100)
committerMartin Schwenke <martins@samba.org>
Sun, 31 Mar 2019 10:45:20 +0000 (10:45 +0000)
When an NFS check restarts a failed service by hand then systemd will
be unable to stop or start this service again because (at least) the
PID file will be wrong.  Do this via the NFS Linux kernel call-out
instead.  Allow the call-out to use the services instead of doing
manual restarts.  Add variables for mount, status and rquotad services
to support this.

Adding systemd NFS services to the call-out will follow.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13860

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@samba.org>
ctdb/config/nfs-checks.d/10.status.check
ctdb/config/nfs-checks.d/40.mountd.check
ctdb/config/nfs-checks.d/50.rquotad.check
ctdb/config/nfs-linux-kernel-callout

index dfa5c59..b8ce1e0 100644 (file)
@@ -2,6 +2,6 @@
 version="1"
 restart_every=2
 unhealthy_after=6
-service_stop_cmd="killall -q -9 rpc.statd"
-service_start_cmd="rpc.statd ${STATD_HA_CALLOUT:+-H} $STATD_HA_CALLOUT ${STATD_HOSTNAME:+-n} $STATD_HOSTNAME ${STATD_PORT:+-p} $STATD_PORT ${STATD_OUTGOING_PORT:+-o} $STATD_OUTGOING_PORT"
+service_stop_cmd="$CTDB_NFS_CALLOUT stop status"
+service_start_cmd="$CTDB_NFS_CALLOUT start status"
 service_debug_cmd="program_stack_traces rpc.statd 5"
index 56b3fd2..bfe4c27 100644 (file)
@@ -2,6 +2,6 @@
 version="1"
 restart_every=2
 unhealthy_after=6
-service_stop_cmd="killall -q -9 rpc.mountd"
-service_start_cmd="rpc.mountd $RPCMOUNTDOPTS ${MOUNTD_PORT:+-p} $MOUNTD_PORT"
+service_stop_cmd="$CTDB_NFS_CALLOUT stop mountd"
+service_start_cmd="$CTDB_NFS_CALLOUT start mountd"
 service_debug_cmd="program_stack_traces rpc.mountd 5"
index b7bd9d2..98bd8d9 100644 (file)
@@ -2,6 +2,6 @@
 version="1"
 restart_every=2
 unhealthy_after=6
-service_stop_cmd="killall -q -9 rpc.rquotad"
-service_start_cmd="rpc.rquotad ${RQUOTAD_PORT:+-p} $RQUOTAD_PORT"
+service_stop_cmd="$CTDB_NFS_CALLOUT stop rquotad"
+service_start_cmd="$CTDB_NFS_CALLOUT start rquotad"
 service_debug_cmd="program_stack_traces rpc.rquotad 5"
index ca7e2b8..74f7f0a 100755 (executable)
@@ -21,7 +21,11 @@ sysvinit-*)
        # Defaults
        nfs_service="nfs"
        nfs_lock_service=""
+       nfs_mountd_service=""
+       nfs_status_service=""
+       nfs_rquotad_service=""
        nfs_config="/etc/sysconfig/nfs"
+       nfs_rquotad_config="$nfs_config"
 
        case "$nfs_distro_style" in
        *-redhat)
@@ -33,6 +37,7 @@ sysvinit-*)
        *-debian)
                nfs_service="nfs-kernel-server"
                nfs_config="/etc/default/nfs-kernel-server"
+               nfs_rquotad_config="/etc/default/quota"
                ;;
        *)
                echo "Internal error"
@@ -134,6 +139,33 @@ service_stop ()
        nlockmgr)
                basic_stop "nfslock" >/dev/null 2>&1 || true
                ;;
+       mountd)
+               if [ -n "$nfs_mountd_service" ] ; then
+                       service "$nfs_mountd_service" stop
+                       return
+               fi
+
+               # Default to stopping by hand
+               killall -q -9 rpc.mountd
+               ;;
+       rquotad)
+               if [ -n "$nfs_rquotad_service" ] ; then
+                       service "$nfs_rquotad_service" stop
+                       return
+               fi
+
+               # Default to stopping by hand
+               killall -q -9 rpc.rquotad
+               ;;
+       status)
+               if [ -n "$nfs_status_service" ] ; then
+                       service "$nfs_status_service" stop
+                       return
+               fi
+
+               # Default to stopping by hand
+               killall -q -9 rpc.statd
+               ;;
        *)
                usage
        esac
@@ -148,6 +180,56 @@ service_start ()
        nlockmgr)
                basic_start "nfslock"
                ;;
+       mountd)
+               if [ -n "$nfs_mountd_service" ] ; then
+                       service "$nfs_mountd_service" start
+                       return
+               fi
+
+               # Default to starting by hand
+               nfs_load_config
+               if [ -z "$RPCMOUNTDOPTS" ] ; then
+                       RPCMOUNTDOPTS="${MOUNTD_PORT:+-p }$MOUNTD_PORT"
+               fi
+               # shellcheck disable=SC2086
+               rpc.mountd $RPCMOUNTDOPTS
+               ;;
+       rquotad)
+               if [ -n "$nfs_rquotad_service" ] ; then
+                       service "$nfs_rquotad_service" start
+                       return
+               fi
+
+               # Default to starting by hand
+               nfs_load_config "$nfs_rquotad_config"
+               if [ -z "$RPCRQUOTADOPTS" ] ; then
+                       RPCRQUOTADOPTS="${RQUOTAD_PORT:+-p }$RQUOTAD_PORT"
+               fi
+               # shellcheck disable=SC2086
+               rpc.rquotad $RPCRQUOTADOPTS
+               ;;
+       status)
+               if [ -n "$nfs_status_service" ] ; then
+                       service "$nfs_status_service" start
+                       return
+               fi
+
+               # Default to starting by hand
+               nfs_load_config
+               # Red Hat uses STATDARG, Debian uses STATDOPTS
+               opts="${STATDARG:-${STATDOPTS:-''}}"
+               if [ -z "$opts" ] ; then
+                       # shellcheck disable=SC2086
+                       set -- \
+                           ${STATD_HA_CALLOUT:+-H} $STATD_HA_CALLOUT \
+                           ${STATD_HOSTNAME:+-n} $STATD_HOSTNAME \
+                           ${STATD_PORT:+-p} $STATD_PORT \
+                           ${STATD_OUTGOING_PORT:+-o} $STATD_OUTGOING_PORT
+                       opts="$*"
+               fi
+               # shellcheck disable=SC2086
+               rpc.statd $opts
+               ;;
        *)
                usage
        esac