1 # If we're not running on a real cluster then we need a local copy of
2 # ctdb (and other stuff) in $PATH and we will use local daemons.
4 export CTDB_NODES_SOCKETS=""
5 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
6 CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${TEST_VAR_DIR}/sock.${i}"
9 # Use in-tree binaries if running against local daemons.
10 # Otherwise CTDB need to be installed on all nodes.
11 if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
12 PATH="${ctdb_dir}/bin:${PATH}"
13 export CTDB_LOCK_HELPER="${ctdb_dir}/bin/ctdb_lock_helper"
14 export CTDB_EVENT_HELPER="${ctdb_dir}/bin/ctdb_event_helper"
15 export CTDB_RECOVERY_HELPER="${ctdb_dir}/bin/ctdb_recovery_helper"
18 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
20 #######################################
24 echo "Attempting to politely shutdown daemons..."
25 onnode -q all $CTDB shutdown || true
27 echo "Sleeping for a while..."
30 local pat="ctdbd --socket=${TEST_VAR_DIR}/.* --nlist .* --nopublicipcheck"
31 if pgrep -f "$pat" >/dev/null ; then
32 echo "Killing remaining daemons..."
35 if pgrep -f "$pat" >/dev/null ; then
36 echo "Once more with feeling.."
41 rm -rf "${TEST_VAR_DIR}/test.db"
46 mkdir -p "${TEST_VAR_DIR}/test.db/persistent"
48 local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
49 local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
50 rm -f $CTDB_NODES $public_addresses_all $no_public_addresses
52 # If there are (strictly) greater than 2 nodes then we'll randomly
53 # choose a node to have no public addresses.
54 local no_public_ips=-1
55 [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
56 echo "$no_public_ips" >$no_public_addresses
58 # When running certain tests we add and remove eventscripts, so we
59 # need to be able to modify the events.d/ directory. Therefore,
60 # we use a temporary events.d/ directory under $TEST_VAR_DIR. We
61 # copy the actual test eventscript(s) in there from the original
62 # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
63 local top=$(dirname "$TEST_SCRIPTS_DIR")
64 local events_d="${top}/events.d"
65 mkdir -p "${TEST_VAR_DIR}/events.d"
66 cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
69 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
70 if [ "${CTDB_USE_IPV6}x" != "x" ]; then
71 j=$((printf "%02x" $i))
72 echo "fd00::5357:5f${j}" >>"$CTDB_NODES"
73 # FIXME: need to add addresses to lo as root before running :-(
74 # ip addr add "fc00:10::${i}/64" dev lo
75 # 2 public addresses on most nodes, just to make things interesting.
76 if [ $(($i - 1)) -ne $no_public_ips ] ; then
77 echo "fc00:10::1:${i}/64 lo" >>"$public_addresses_all"
78 echo "fc00:10::1:$(($i + $TEST_LOCAL_DAEMONS))/64 lo" >>"$public_addresses_all"
82 echo 127.0.0.$j >>"$CTDB_NODES"
83 # 2 public addresses on most nodes, just to make things interesting.
84 if [ $(($i - 1)) -ne $no_public_ips ] ; then
85 echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
86 echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
95 shift # "$@" gets passed to ctdbd
97 local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
98 local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"
99 local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
100 local public_addresses
102 local no_public_ips=-1
103 [ -r $no_public_addresses ] && read no_public_ips <$no_public_addresses
105 if [ "$no_public_ips" = $pnn ] ; then
106 echo "Node $no_public_ips will have no public IPs."
107 public_addresses="/dev/null"
109 cp "$public_addresses_all" "$public_addresses_mine"
110 public_addresses="$public_addresses_mine"
113 local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
114 local ctdb_options="--sloppy-start --reclock=${TEST_VAR_DIR}/rec.lock --nlist $CTDB_NODES --nopublicipcheck --listen=${node_ip} --event-script-dir=${TEST_VAR_DIR}/events.d --logging=file:${TEST_VAR_DIR}/daemon.${pnn}.log -d 3 --dbdir=${TEST_VAR_DIR}/test.db --dbdir-persistent=${TEST_VAR_DIR}/test.db/persistent --dbdir-state=${TEST_VAR_DIR}/test.db/state --nosetsched --public-addresses=${public_addresses}"
116 # We'll use "pkill -f" to kill the daemons with
117 # "--socket=.* --nlist .* --nopublicipcheck" as context.
118 $VALGRIND ctdbd --socket="${TEST_VAR_DIR}/sock.$pnn" $ctdb_options "$@" ||return 1
123 # "$@" gets passed to ctdbd
125 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
127 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
128 daemons_start_1 $i "$@"
134 if $TEST_CLEANUP ; then