From: Martin Schwenke Date: Fri, 18 Mar 2022 01:47:10 +0000 (+1100) Subject: ctdb-scripts: Set NFS services to "AUTO" if started by another service X-Git-Tag: tevent-0.13.0~328 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=337ef7c1b417cce94a6f1480f17dae477fadf565;p=thirdparty%2Fsamba.git ctdb-scripts: Set NFS services to "AUTO" if started by another service For example, in Sys-V init "rquotad" is started by the main "nfs" service. At the moment the call-out can't distinguish between this case and "should never be run". Services set to "AUTO" are hand-stopped/started via service_stop()/service_start() on failure via restart_after. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/nfs-linux-kernel-callout b/ctdb/config/nfs-linux-kernel-callout index 82f481343f5..b2aa43cd1b7 100755 --- a/ctdb/config/nfs-linux-kernel-callout +++ b/ctdb/config/nfs-linux-kernel-callout @@ -16,6 +16,12 @@ nfs_exports_file="${CTDB_NFS_EXPORTS_FILE:-/var/lib/nfs/etab}" # test variable only. nfs_distro_style="${CTDB_NFS_DISTRO_STYLE:-systemd-redhat}" +# A value of "AUTO" for any service means that service is usually +# automatically started and stopped by one of the other services. +# Such services will still be restarted by hand on failure, if +# configured to do so. This allows services that should not be +# running to be set to "". + case "$nfs_distro_style" in systemd-*) # Defaults @@ -44,10 +50,10 @@ systemd-*) sysvinit-*) # Defaults nfs_service="nfs" - nfs_lock_service="" - nfs_mountd_service="" - nfs_status_service="" - nfs_rquotad_service="" + nfs_lock_service="AUTO" + nfs_mountd_service="AUTO" + nfs_status_service="AUTO" + nfs_rquotad_service="AUTO" nfs_config="/etc/sysconfig/nfs" nfs_rquotad_config="$nfs_config" @@ -106,33 +112,49 @@ nfs_load_config() fi } +################################################## + +service_is_auto_started() +{ + [ "$1" = "AUTO" ] +} + +service_is_defined() +{ + _service="$1" + + [ -n "$_service" ] && ! service_is_auto_started "$_service" +} + +service_if_defined() +{ + _service="$1" + _action="$2" + + if service_is_defined "$_service"; then + service "$_service" "$_action" + fi +} + ################################################## # Overall NFS service stop and start nfs_service_stop() { - if [ -n "$nfs_rquotad_service" ]; then - service "$nfs_rquotad_service" stop - fi + service_if_defined "$nfs_rquotad_service" stop service "$nfs_service" stop - if [ -n "$nfs_lock_service" ]; then - service "$nfs_lock_service" stop - fi + service_if_defined "$nfs_lock_service" stop } nfs_service_start() { - if [ -n "$nfs_lock_service" ]; then - service "$nfs_lock_service" start - fi + service_if_defined "$nfs_lock_service" start service "$nfs_service" start - if [ -n "$nfs_rquotad_service" ]; then - service "$nfs_rquotad_service" start - fi + service_if_defined "$nfs_rquotad_service" start } ################################################## @@ -162,9 +184,9 @@ service_or_manual_stop() _rpc_service="$1" _system_service="$2" - if [ -n "$_system_service" ]; then + if service_is_defined "$_system_service"; then service "$_system_service" stop - else + elif service_is_auto_started "$_system_service"; then manual_stop "$_rpc_service" fi } @@ -180,7 +202,7 @@ service_stop() pkill -9 nfsd ;; nlockmgr) - if [ -n "$nfs_lock_service" ]; then + if service_is_defined "$nfs_lock_service" ; then service "$nfs_lock_service" stop >/dev/null 2>&1 || true else service "$nfs_service" stop >/dev/null 2>&1 || true @@ -248,9 +270,9 @@ service_or_manual_start() _rpc_service="$1" _system_service="$2" - if [ -n "$_system_service" ]; then + if service_is_defined "$_system_service"; then service "$_system_service" start - else + elif service_is_auto_started "$_system_service"; then manual_start "$_rpc_service" fi } @@ -264,7 +286,7 @@ service_start() nfs_service_start ;; nlockmgr) - if [ -n "$nfs_lock_service" ]; then + if service_is_defined "$nfs_lock_service" ; then service "$nfs_lock_service" start else service "$nfs_service" start