diff options
-rwxr-xr-x | ctdb/config/functions | 28 | ||||
-rwxr-xr-x | ctdb/tests/eventscripts/49.winbind.monitor.050.sh | 10 | ||||
-rwxr-xr-x | ctdb/tests/eventscripts/49.winbind.monitor.051.sh | 10 | ||||
-rwxr-xr-x | ctdb/tests/eventscripts/50.samba.monitor.050.sh | 10 | ||||
-rwxr-xr-x | ctdb/tests/eventscripts/50.samba.monitor.051.sh | 10 | ||||
-rw-r--r-- | ctdb/tests/eventscripts/scripts/local.sh | 20 | ||||
-rw-r--r-- | ctdb/tests/scripts/unit.sh | 2 |
7 files changed, 65 insertions, 25 deletions
diff --git a/ctdb/config/functions b/ctdb/config/functions index a07aa8ee93..e2a9b03c84 100755 --- a/ctdb/config/functions +++ b/ctdb/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/ctdb/tests/eventscripts/49.winbind.monitor.050.sh b/ctdb/tests/eventscripts/49.winbind.monitor.050.sh index 448c2049aa..d0d55f079c 100755 --- a/ctdb/tests/eventscripts/49.winbind.monitor.050.sh +++ b/ctdb/tests/eventscripts/49.winbind.monitor.050.sh @@ -9,9 +9,9 @@ setup_winbind "down" export CTDB_SERVICE_AUTOSTARTSTOP="yes" export CTDB_MANAGED_SERVICES="foo winbind bar" -ok <<EOF -Starting service "winbind" - now managed -Starting winbind: OK -EOF - +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/ctdb/tests/eventscripts/49.winbind.monitor.051.sh b/ctdb/tests/eventscripts/49.winbind.monitor.051.sh index 52f9fa2a9a..1d68068e30 100755 --- a/ctdb/tests/eventscripts/49.winbind.monitor.051.sh +++ b/ctdb/tests/eventscripts/49.winbind.monitor.051.sh @@ -10,9 +10,9 @@ export CTDB_SERVICE_AUTOSTARTSTOP="yes" export CTDB_MANAGED_SERVICES="foo" unset CTDB_MANAGES_WINBIND -ok <<EOF -Stopping service "winbind" - no longer managed -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/ctdb/tests/eventscripts/50.samba.monitor.050.sh b/ctdb/tests/eventscripts/50.samba.monitor.050.sh index e465add0b8..db66f66e3a 100755 --- a/ctdb/tests/eventscripts/50.samba.monitor.050.sh +++ b/ctdb/tests/eventscripts/50.samba.monitor.050.sh @@ -9,9 +9,9 @@ setup_samba "down" export CTDB_SERVICE_AUTOSTARTSTOP="yes" export CTDB_MANAGED_SERVICES="foo samba winbind bar" -ok <<EOF -Starting service "samba" - now managed -Starting smb: OK -EOF - +ok 'Starting service "samba" - now managed' simple_test + +# This depends on output in the log file from the above test +ok 'Starting smb: OK' +check_ctdb_logfile diff --git a/ctdb/tests/eventscripts/50.samba.monitor.051.sh b/ctdb/tests/eventscripts/50.samba.monitor.051.sh index b61046c53d..1a9ab22a10 100755 --- a/ctdb/tests/eventscripts/50.samba.monitor.051.sh +++ b/ctdb/tests/eventscripts/50.samba.monitor.051.sh @@ -10,9 +10,9 @@ export CTDB_SERVICE_AUTOSTARTSTOP="yes" export CTDB_MANAGED_SERVICES="foo" unset CTDB_MANAGES_SAMBA -ok <<EOF -Stopping service "samba" - no longer managed -Stopping smb: OK -EOF - +ok 'Stopping service "samba" - no longer managed' simple_test + +# This depends on output in the log file from the above test +ok 'Stopping smb: OK' +check_ctdb_logfile diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh index e572a5dba7..56d09fa980 100644 --- a/ctdb/tests/eventscripts/scripts/local.sh +++ b/ctdb/tests/eventscripts/scripts/local.sh @@ -23,6 +23,9 @@ fi mkdir -p "$EVENTSCRIPTS_TESTS_VAR_DIR" export CTDB_VARDIR="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb" +export CTDB_LOGFILE="${EVENTSCRIPTS_TESTS_VAR_DIR}/log.ctdb" +touch "$CTDB_LOGFILE" || die "Unable to create CTDB_LOGFILE=$CTDB_LOGFILE" + if [ -d "${TEST_SUBDIR}/etc" ] ; then cp -a "${TEST_SUBDIR}/etc" "$EVENTSCRIPTS_TESTS_VAR_DIR" export CTDB_ETCDIR="${EVENTSCRIPTS_TESTS_VAR_DIR}/etc" @@ -763,7 +766,7 @@ simple_test_event () $_passed || return 1 event="$1" ; shift - echo "##################################################" + echo "==================================================" simple_test "$@" } @@ -773,13 +776,26 @@ simple_test_command () : ${_passed:=true} $_passed || return 1 - echo "##################################################" + echo "==================================================" echo "Running command \"$*\"" _out=$("$@" 2>&1) result_check } +check_ctdb_logfile () +{ + # If something has previously failed then don't continue. + : ${_passed:=true} + $_passed || return 1 + + echo "==================================================" + echo "Checking CTDB_LOGFILE=\"${CTDB_LOGFILE}\"" + _out=$(cat "$CTDB_LOGFILE" 2>&1) + + result_check +} + # Run an eventscript iteratively. # - 1st argument is the number of iterations. # - 2nd argument is something to eval to do setup for every iteration. diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh index 6f92d6cb16..b27df45e76 100644 --- a/ctdb/tests/scripts/unit.sh +++ b/ctdb/tests/scripts/unit.sh @@ -49,7 +49,7 @@ result_print () if [ -n "$_extra_header" ] ; then cat <<EOF -================================================== +################################################## $_extra_header EOF fi |