[SCM] CTDB repository - branch master updated - ctdb-1.13-273-g3a3dae4

Amitay Isaacs amitay at samba.org
Tue Oct 2 19:25:09 MDT 2012


The branch, master has been updated
       via  3a3dae4cb5ec8b4b8381a4013adda25b87641f3a (commit)
       via  34535ae64420926b9a3bf7d453fed4e6f4c90115 (commit)
      from  043ef77086797a703aec436a26a05c56a1bcbf2b (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 3a3dae4cb5ec8b4b8381a4013adda25b87641f3a
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Sep 3 15:37:01 2012 +1000

    eventscripts: Auto-start/stop services in background
    
    If $CTDB_SERVICE_AUTOSTARTSTOP="yes" then service start/stop is done
    in the background with logging.
    
    Fix some unit tests for samba and winbind.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 34535ae64420926b9a3bf7d453fed4e6f4c90115
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Aug 16 14:41:11 2012 +1000

    Eventscripts: split 50.samba into 49.winbind and 50.samba
    
    winbind and samba can be separately managed.  This makes the service
    starting and stopping code way too complicated, and even adds a small
    amount of complexity to the monitoring code.  The sensible option is
    to split this eventscript in two.
    
    There are two potentially backward incompatible changes here:
    
    * Functionality has been removed that allowed 50.samba to manage
      winbind when CTDB_MANAGES_WINBIND was unset but the smb.conf
      "security" parameter was set to "ADS" or "DOMAIN".
    
      Maintaining this functionality would have required moving the
      testparm-related code to the functions file, deciding where the
      cache file should go, and then calling it from both 49.winbind and
      50.samba.  This feature wasn't of great value and asking
      administrators to set an extra variable in exchange for code
      simplicity seems like a reasonable deal.
    
    * External code will need to be changed if it calls 50.samba directly
      with winbind-related expectations.  This is fairly obvious!
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 Makefile.in                                        |    1 +
 config/events.d/49.winbind                         |   75 ++++++++
 config/events.d/50.samba                           |  195 +++++--------------
 config/functions                                   |   28 +++-
 packaging/RPM/ctdb.spec.in                         |    1 +
 ...pd.monitor.001.sh => 49.winbind.monitor.001.sh} |    2 +-
 tests/eventscripts/49.winbind.monitor.050.sh       |   17 ++
 ...ba.monitor.051.sh => 49.winbind.monitor.051.sh} |   14 +-
 ...ba.monitor.101.sh => 49.winbind.monitor.101.sh} |    2 +-
 ...ba.monitor.102.sh => 49.winbind.monitor.102.sh} |    2 +-
 tests/eventscripts/50.samba.monitor.050.sh         |   11 +-
 tests/eventscripts/50.samba.monitor.051.sh         |   12 +-
 tests/eventscripts/scripts/local.sh                |   69 ++++++--
 tests/scripts/unit.sh                              |    2 +-
 14 files changed, 248 insertions(+), 183 deletions(-)
 create mode 100755 config/events.d/49.winbind
 copy tests/eventscripts/{40.vsftpd.monitor.001.sh => 49.winbind.monitor.001.sh} (83%)
 create mode 100755 tests/eventscripts/49.winbind.monitor.050.sh
 copy tests/eventscripts/{50.samba.monitor.051.sh => 49.winbind.monitor.051.sh} (53%)
 copy tests/eventscripts/{50.samba.monitor.101.sh => 49.winbind.monitor.101.sh} (86%)
 rename tests/eventscripts/{50.samba.monitor.102.sh => 49.winbind.monitor.102.sh} (91%)


Changeset truncated at 500 lines:

diff --git a/Makefile.in b/Makefile.in
index cbb987a..48cb57c 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -341,6 +341,7 @@ install: all $(PMDA_INSTALL)
 	${INSTALLCMD} -m 755 config/events.d/40.vsftpd $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 644 config/events.d/40.fs_use $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/41.httpd $(DESTDIR)$(etcdir)/ctdb/events.d
+	${INSTALLCMD} -m 755 config/events.d/49.winbind $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/50.samba $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/60.nfs $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/60.ganesha $(DESTDIR)$(etcdir)/ctdb/events.d
diff --git a/config/events.d/49.winbind b/config/events.d/49.winbind
new file mode 100755
index 0000000..b67951b
--- /dev/null
+++ b/config/events.d/49.winbind
@@ -0,0 +1,75 @@
+#!/bin/sh
+# ctdb event script for winbind
+
+. $CTDB_BASE/functions
+
+detect_init_style
+
+CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
+
+service_name="winbind"
+
+loadconfig
+
+ctdb_setup_service_state_dir
+
+service_start ()
+{
+    service "$CTDB_SERVICE_WINBIND" stop >/dev/null 2>&1
+    killall -0 -q winbindd && {
+	sleep 1
+        # make absolutely sure winbindd is dead
+	killall -q -9 winbindd
+    }
+
+    service "$CTDB_SERVICE_WINBIND" start || \
+	die "Failed to start winbind"
+}
+
+service_stop ()
+{
+    service "$CTDB_SERVICE_WINBIND" stop
+}
+
+service_reconfigure ()
+{
+    # winbind automatically reloads config - no restart needed.
+    :
+}
+
+###########################
+
+ctdb_start_stop_service
+
+is_ctdb_managed_service || exit 0
+
+ctdb_service_check_reconfigure
+
+###########################
+
+case "$1" in 
+     startup)
+	ctdb_service_start
+	;;
+	
+     shutdown)
+	ctdb_service_stop
+	;;
+
+     monitor)
+	ctdb_check_command "winbind" "wbinfo -p"
+	;;
+
+     takeip|releaseip)
+	iface=$2
+	ip=$3
+	maskbits=$4
+
+	smbcontrol winbindd ip-dropped $ip >/dev/null 2>/dev/null
+	;;
+    *)
+	ctdb_standard_event_handler "$@"
+	;;
+esac
+
+exit 0
diff --git a/config/events.d/50.samba b/config/events.d/50.samba
index bf143bf..4d9f121 100755
--- a/config/events.d/50.samba
+++ b/config/events.d/50.samba
@@ -9,18 +9,15 @@ case $CTDB_INIT_STYLE in
 	suse)
 		CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
 		CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb}
-		CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
 		;;
 	debian)
 		CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-samba}
 		CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
-		CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
 		;;
 	*)
-		# should not happen, but for now use redhat style as default:
+		# Use redhat style as default:
 		CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
 		CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
-		CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
 		;;
 esac
 
@@ -32,89 +29,40 @@ ctdb_setup_service_state_dir
 
 service_start ()
 {
-	# If set then we force-start the relevant service.
-	_service_name="$1"
-
-	# make sure samba is not already started
-	if [ "$_service_name" = "samba" ] || \
-	    is_ctdb_managed_service "samba" ; then
-		service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
-		if [ -n "$CTDB_SERVICE_NMB" ] ; then
-		    service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
-		fi
-		killall -0 -q smbd && {
-		    sleep 1
-		    # make absolutely sure samba is dead
-		    killall -q -9 smbd
-		}
-
-		killall -0 -q nmbd && {
-		    sleep 1
-		    # make absolutely sure samba is dead
-		    killall -q -9 nmbd
-		}
-	fi
-
-	# make sure winbind is not already started
-	if [ "$_service_name" = "winbind" ] || \
-	    check_ctdb_manages_winbind ; then
-		service "$CTDB_SERVICE_WINBIND" stop > /dev/null 2>&1
-		killall -0 -q winbindd && {
-		    sleep 1
-          	    # make absolutely sure winbindd is dead
-		    killall -q -9 winbindd
-		}
+    # make sure samba is not already started
+    service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
+    if [ -n "$CTDB_SERVICE_NMB" ] ; then
+	service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
+    fi
+    killall -0 -q smbd && {
+	sleep 1
+	# make absolutely sure samba is dead
+	killall -q -9 smbd
+    }
+    killall -0 -q nmbd && {
+	sleep 1
+	# make absolutely sure samba is dead
+	killall -q -9 nmbd
+    }
 
-	fi
+    # start Samba service. Start it reniced, as under very heavy load
+    # the number of smbd processes will mean that it leaves few cycles
+    # for anything else
+    net serverid wipe
 
-	# start the winbind service
-	if [ "$_service_name" = "winbind" ] || \
-	    check_ctdb_manages_winbind ; then
-		service "$CTDB_SERVICE_WINBIND" start || {
-		    echo failed to start winbind
-		    exit 1
-		}
-	fi
+    if [ -n "$CTDB_SERVICE_NMB" ] ; then
+	nice_service "$CTDB_SERVICE_NMB" start || die "Failed to start nmbd"
+    fi
 
-	# start Samba service. Start it reniced, as under very heavy load 
-	# the number of smbd processes will mean that it leaves few cycles for
-	# anything else
-	if [ "$_service_name" = "samba" ] || \
-	    is_ctdb_managed_service "samba" ; then
-		net serverid wipe
-
-		if [ -n "$CTDB_SERVICE_NMB" ] ; then
-		    nice_service "$CTDB_SERVICE_NMB" start || {
-			echo failed to start nmbd
-			exit 1
-		    }
-		fi
-		nice_service "$CTDB_SERVICE_SMB" start || {
-			echo failed to start samba
-			exit 1
-		}
-	fi
+    nice_service "$CTDB_SERVICE_SMB" start || die "Failed to start samba"
 }
 
 service_stop ()
 {
-	# If set then we force-stop the relevant service.
-	_service_name="$1"
-
-	# shutdown Samba when ctdb goes down
-	if [ "$_service_name" = "samba" ] || \
-	    is_ctdb_managed_service "samba" ; then
-		service "$CTDB_SERVICE_SMB" stop
-		if [ -n "$CTDB_SERVICE_NMB" ] ; then
-		    service "$CTDB_SERVICE_NMB" stop
-		fi
-	fi
-
-	# stop the winbind service
-	if [ "$_service_name" = "winbind" ] || \
-	    check_ctdb_manages_winbind ; then
-		service "$CTDB_SERVICE_WINBIND" stop
-	fi
+    service "$CTDB_SERVICE_SMB" stop
+    if [ -n "$CTDB_SERVICE_NMB" ] ; then
+	service "$CTDB_SERVICE_NMB" stop
+    fi
 }
 
 service_reconfigure ()
@@ -148,7 +96,7 @@ testparm_background_update() {
     # otherwise do a background update
     (
 	tmpfile="${smbconf_cache}.$$"
-	testparm -s > $tmpfile 2> /dev/null &
+	testparm -v -s > $tmpfile 2> /dev/null &
 	# remember the pid of the teamparm process
 	pid="$!"
 	# give it 10 seconds to run
@@ -195,30 +143,7 @@ testparm_cat() {
     [ -f $smbconf_cache ] || {
 	testparm_foreground_update
     }
-    testparm -s "$smbconf_cache" "$@" 2>/dev/null
-}
-
-# function to see if ctdb manages winbind - this overrides with extra
-# logic if $CTDB_MANAGES_WINBIND is not set or null.
-check_ctdb_manages_winbind() {
-    if is_ctdb_managed_service "winbind" ; then
-	return 0
-    elif [ -n "$CTDB_MANAGES_WINBIND" ] ; then
-	# If this variable is set we want to respect it.  We return
-	# false here because we know it is not set to "yes" - if it
-	# were then the 1st "if" above would have succeeded.
-	return 1
-    else
-	_secmode=`testparm_cat --parameter-name=security`
-	case "$_secmode" in
-	    ADS|DOMAIN)
-		return 0
-		;;
-	    *)
-		return 1
-		;;
-	esac
-    fi
+    testparm -v -s "$smbconf_cache" "$@" 2>/dev/null
 }
 
 list_samba_shares ()
@@ -241,9 +166,10 @@ periodic_cleanup() {
 ###########################
 
 ctdb_start_stop_service
-ctdb_start_stop_service "winbind"
 
-is_ctdb_managed_service || is_ctdb_managed_service "winbind" || exit 0
+is_ctdb_managed_service || exit 0
+
+ctdb_service_check_reconfigure
 
 ###########################
 
@@ -269,46 +195,29 @@ case "$1" in
 		touch "$periodic_cleanup_file"
 	}
 
-	is_ctdb_managed_service "samba" && {
-		[ "$CTDB_SAMBA_SKIP_SHARE_CHECK" = "yes" ] || {
-			testparm_background_update
-
-			testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && {
-			    testparm_foreground_update
-			    testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && {
-				echo "ERROR: testparm shows smb.conf is not clean"
-				exit 1
-			    }
-			}
-			
-			list_samba_shares |
-			ctdb_check_directories_probe || {
-			    testparm_foreground_update
-			    list_samba_shares |
-			    ctdb_check_directories
-			} || exit $?
-		}
+	if [ "$CTDB_SAMBA_SKIP_SHARE_CHECK" != "yes" ] ; then
+	    testparm_background_update
 
-		smb_ports="$CTDB_SAMBA_CHECK_PORTS"
-		[ -z "$smb_ports" ] && {
-			smb_ports=`testparm_cat --parameter-name="smb ports"`
-		}
-		ctdb_check_tcp_ports $smb_ports || exit $?
-	}
+	    testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && {
+		testparm_foreground_update
+		testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && \
+		    die "ERROR: testparm shows smb.conf is not clean"
+	    }
+			
+	    list_samba_shares | ctdb_check_directories_probe || {
+		testparm_foreground_update
+		list_samba_shares |
+		ctdb_check_directories
+	    } || exit $?
+	fi
 
-	# check winbind is OK
-	check_ctdb_manages_winbind && {
-		ctdb_check_command "winbind" "wbinfo -p"
-	}
+	smb_ports="$CTDB_SAMBA_CHECK_PORTS"
+	if [ -z "$smb_ports" ] ; then
+	    smb_ports=`testparm_cat --parameter-name="smb ports"`
+	fi
+	ctdb_check_tcp_ports $smb_ports || exit $?
 	;;
 
-     takeip|releaseip)
-	iface=$2
-	ip=$3
-	maskbits=$4
-
-	smbcontrol winbindd ip-dropped $ip >/dev/null 2>/dev/null
-	;;
     *)
 	ctdb_standard_event_handler "$@"
 	;;
diff --git a/config/functions b/config/functions
index a07aa8e..e2a9b03 100755
--- a/config/functions
+++ b/config/functions
@@ -95,6 +95,30 @@ die ()
     exit $_rc
 }
 
+# When things are run in the background in an eventscript then logging
+# output might get lost.  This is the "solution".  :-)
+background_with_logging ()
+{
+    _using_syslog=false
+    if [ "$CTDB_SYSLOG" = "yes" -o -z "$CTDB_LOGFILE" ] ; then
+	_using_syslog=true
+    fi
+    case "$CTDB_OPTIONS" in
+	*--syslog*) _using_syslog=true ;;
+    esac
+
+    (
+	"$@" 2>&1 </dev/null |
+	if $_using_syslog ; then
+	    logger -t "ctdbd: ${script_name}&"
+	else
+	    cat >>"$CTDB_LOGFILE"
+	fi
+    )&
+
+    return 0
+}
+
 ##############################################################
 # check number of args for different events
 ctdb_check_args ()
@@ -1272,13 +1296,13 @@ ctdb_start_stop_service ()
     if is_ctdb_managed_service "$_service_name" ; then
 	if ! is_ctdb_previously_managed_service "$_service_name" ; then
 	    echo "Starting service \"$_service_name\" - now managed"
-	    ctdb_service_start "$_service_name"
+	    background_with_logging ctdb_service_start "$_service_name"
 	    exit $?
 	fi
     else
 	if is_ctdb_previously_managed_service "$_service_name" ; then
 	    echo "Stopping service \"$_service_name\" - no longer managed"
-	    ctdb_service_stop "$_service_name"
+	    background_with_logging ctdb_service_stop "$_service_name"
 	    exit $?
 	fi
     fi
diff --git a/packaging/RPM/ctdb.spec.in b/packaging/RPM/ctdb.spec.in
index 381739c..6a6398b 100644
--- a/packaging/RPM/ctdb.spec.in
+++ b/packaging/RPM/ctdb.spec.in
@@ -139,6 +139,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_sysconfdir}/ctdb/events.d/40.fs_use
 %{_sysconfdir}/ctdb/events.d/40.vsftpd
 %{_sysconfdir}/ctdb/events.d/41.httpd
+%{_sysconfdir}/ctdb/events.d/49.winbind
 %{_sysconfdir}/ctdb/events.d/50.samba
 %{_sysconfdir}/ctdb/events.d/60.nfs
 %{_sysconfdir}/ctdb/events.d/60.ganesha
diff --git a/tests/eventscripts/40.vsftpd.monitor.001.sh b/tests/eventscripts/49.winbind.monitor.001.sh
similarity index 83%
copy from tests/eventscripts/40.vsftpd.monitor.001.sh
copy to tests/eventscripts/49.winbind.monitor.001.sh
index fdad12a..94253d8 100755
--- a/tests/eventscripts/40.vsftpd.monitor.001.sh
+++ b/tests/eventscripts/49.winbind.monitor.001.sh
@@ -4,7 +4,7 @@
 
 define_test "not managed, check no-op"
 
-setup_vsftpd "down"
+setup_winbind "down"
 
 ok_null
 
diff --git a/tests/eventscripts/49.winbind.monitor.050.sh b/tests/eventscripts/49.winbind.monitor.050.sh
new file mode 100755
index 0000000..d0d55f0
--- /dev/null
+++ b/tests/eventscripts/49.winbind.monitor.050.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "auto-start, simple"
+
+setup_winbind "down"
+
+export CTDB_SERVICE_AUTOSTARTSTOP="yes"
+export CTDB_MANAGED_SERVICES="foo winbind bar"
+
+ok 'Starting service "winbind" - now managed'
+simple_test
+
+# This depends on output in the log file from the above test
+ok 'Starting winbind: OK'
+check_ctdb_logfile
diff --git a/tests/eventscripts/50.samba.monitor.051.sh b/tests/eventscripts/49.winbind.monitor.051.sh
similarity index 53%
copy from tests/eventscripts/50.samba.monitor.051.sh
copy to tests/eventscripts/49.winbind.monitor.051.sh
index 4a66269..1d68068 100755
--- a/tests/eventscripts/50.samba.monitor.051.sh
+++ b/tests/eventscripts/49.winbind.monitor.051.sh
@@ -4,17 +4,15 @@
 
 define_test "auto-stop, simple"
 
-setup_samba
+setup_winbind
 
 export CTDB_SERVICE_AUTOSTARTSTOP="yes"
 export CTDB_MANAGED_SERVICES="foo"
-unset CTDB_MANAGES_SAMBA
 unset CTDB_MANAGES_WINBIND
 
-ok <<EOF
-Stopping service "samba" - no longer managed
-Stopping smb: OK
-Stopping winbind: OK
-EOF
-
+ok 'Stopping service "winbind" - no longer managed'
 simple_test
+
+# This depends on output in the log file from the above test
+ok 'Stopping winbind: OK'
+check_ctdb_logfile
diff --git a/tests/eventscripts/50.samba.monitor.101.sh b/tests/eventscripts/49.winbind.monitor.101.sh
similarity index 86%
copy from tests/eventscripts/50.samba.monitor.101.sh
copy to tests/eventscripts/49.winbind.monitor.101.sh
index cf3b53a..ec2952b 100755
--- a/tests/eventscripts/50.samba.monitor.101.sh
+++ b/tests/eventscripts/49.winbind.monitor.101.sh
@@ -4,7 +4,7 @@
 
 define_test "all OK"
 
-setup_samba
+setup_winbind


-- 
CTDB repository


More information about the samba-cvs mailing list