summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2012-09-03 15:37:01 +1000
committerAmitay Isaacs <amitay@gmail.com>2012-10-03 08:48:23 +1000
commit2d719e5c84e3f898a992e97992c94a2ffb94e3a0 (patch)
tree405ce959a78faa6f6b9a97ebb95b8bf188366f0e
parentf3ae31e74135c242ad45262596ee6d1d5ac035f5 (diff)
downloadsamba-2d719e5c84e3f898a992e97992c94a2ffb94e3a0.tar.gz
samba-2d719e5c84e3f898a992e97992c94a2ffb94e3a0.tar.xz
samba-2d719e5c84e3f898a992e97992c94a2ffb94e3a0.zip
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@meltin.net> (This used to be ctdb commit 3a3dae4cb5ec8b4b8381a4013adda25b87641f3a)
-rwxr-xr-xctdb/config/functions28
-rwxr-xr-xctdb/tests/eventscripts/49.winbind.monitor.050.sh10
-rwxr-xr-xctdb/tests/eventscripts/49.winbind.monitor.051.sh10
-rwxr-xr-xctdb/tests/eventscripts/50.samba.monitor.050.sh10
-rwxr-xr-xctdb/tests/eventscripts/50.samba.monitor.051.sh10
-rw-r--r--ctdb/tests/eventscripts/scripts/local.sh20
-rw-r--r--ctdb/tests/scripts/unit.sh2
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