ctdb-tests: Be more efficient about starting/stopping local daemons
[samba.git] / ctdb / tests / simple / scripts / local_daemons.bash
index a47080574a9f6d0ce8b68bfe22f28744bbc32ccc..04597e9f1b3bd1eba785fbd52802b0985ec9460e 100644 (file)
@@ -1,19 +1,13 @@
 # If we're not running on a real cluster then we need a local copy of
 # ctdb (and other stuff) in $PATH and we will use local daemons.
 
-# Use in-tree binaries if running against local daemons.
-# Otherwise CTDB need to be installed on all nodes.
-if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
-       # ctdbd_wrapper is in config/ directory
-       PATH="${ctdb_dir}/bin:${ctdb_dir}/config:${PATH}"
-       hdir="${ctdb_dir}/bin"
-       export CTDB_EVENTD="${hdir}/ctdb_eventd"
-       export CTDB_EVENT_HELPER="${hdir}/ctdb_event"
-       export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
-       export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
-       export CTDB_TAKEOVER_HELPER="${hdir}/ctdb_takeover_helper"
-       export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
-fi
+hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
+export CTDB_EVENTD="${hdir}/ctdb-eventd"
+export CTDB_EVENT_HELPER="${hdir}/ctdb-event"
+export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
+export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
+export CTDB_TAKEOVER_HELPER="${hdir}/ctdb_takeover_helper"
+export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
 
 if [ -n "$TEST_SOCKET_WRAPPER_SO_PATH" ] ; then
        export LD_PRELOAD="$TEST_SOCKET_WRAPPER_SO_PATH"
@@ -94,9 +88,11 @@ setup_ctdb ()
 {
        local no_public_addresses=false
        local no_event_scripts=false
+       local disable_failover=false
        case "$1" in
        --no-public-addresses) no_public_addresses=true ;;
        --no-event-scripts)    no_event_scripts=true    ;;
+       --disable-failover)    disable_failover=true    ;;
        esac
 
        nodes_file="${SIMPLE_TESTS_VAR_DIR}/nodes"
@@ -154,8 +150,11 @@ setup_ctdb ()
        persistent database directory = ${db_dir}/persistent
        state database directory = ${db_dir}/state
 
+[failover]
+       disabled = ${disable_failover}
+
 [event]
-       debug script = ${CTDB_BASE}/debug-hung-script.sh
+       debug script = debug-hung-script.sh
 EOF
        done
 }
@@ -164,37 +163,28 @@ start_ctdb_1 ()
 {
        local pnn="$1"
 
-       CTDBD="${VALGRIND} ctdbd" \
-            onnode "$pnn" ctdbd_wrapper start
+       onnode "$pnn" $VALGRIND ctdbd
 }
 
-daemons_start ()
+ctdb_start_all ()
 {
-    echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
+       echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
 
-    local pnn
-    for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
-       start_ctdb_1 "$pnn"
-    done
+       onnode all $VALGRIND ctdbd
 }
 
 stop_ctdb_1 ()
 {
        local pnn="$1"
 
-       onnode "$pnn" ctdbd_wrapper stop
+       onnode "$pnn" $CTDB shutdown
 }
 
-daemons_stop ()
+ctdb_stop_all ()
 {
-    echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
+       echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
 
-    local pnn
-    for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
-       stop_ctdb_1 "$pnn"
-    done
-
-    rm -rf "${SIMPLE_TESTS_VAR_DIR}/test.db"
+       onnode -p all $CTDB shutdown
 }
 
 restart_ctdb_1 ()
@@ -203,31 +193,6 @@ restart_ctdb_1 ()
        start_ctdb_1 "$1"
 }
 
-maybe_stop_ctdb ()
-{
-    daemons_stop
-}
-
-ctdb_stop_all ()
-{
-       daemons_stop
-}
-
-_ctdb_start_all ()
-{
-       daemons_start
-}
-
-ps_ctdbd ()
-{
-       # If this fails to find processes then the tests fails, so
-       # look at full command-line so this will work with valgrind.
-       # Note that the output could be generated with pgrep's -a
-       # option but it doesn't exist in older versions.
-       ps -p $(pgrep -f '\<ctdbd\>' | xargs | sed -e 's| |,|g') -o args ww
-       echo
-}
-
 # onnode will use CTDB_BASES to help the ctdb tool connection to each
 # daemon
 export CTDB_BASES=""