From 2d719e5c84e3f898a992e97992c94a2ffb94e3a0 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 3 Sep 2012 15:37:01 +1000 Subject: 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 (This used to be ctdb commit 3a3dae4cb5ec8b4b8381a4013adda25b87641f3a) --- ctdb/config/functions | 28 +++++++++++++++++++++-- ctdb/tests/eventscripts/49.winbind.monitor.050.sh | 10 ++++---- ctdb/tests/eventscripts/49.winbind.monitor.051.sh | 10 ++++---- ctdb/tests/eventscripts/50.samba.monitor.050.sh | 10 ++++---- ctdb/tests/eventscripts/50.samba.monitor.051.sh | 10 ++++---- ctdb/tests/eventscripts/scripts/local.sh | 20 ++++++++++++++-- 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 >"$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 <&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 <