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"
16 export CTDB_NODES
="${TEST_VAR_DIR}/nodes.txt"
18 #######################################
22 echo "Attempting to politely shutdown daemons..."
23 onnode
1 $CTDB shutdown
-n all || true
25 echo "Sleeping for a while..."
28 local pat
="ctdbd --socket=${TEST_VAR_DIR}/.* --nlist .* --nopublicipcheck"
29 if pgrep
-f "$pat" >/dev
/null
; then
30 echo "Killing remaining daemons..."
33 if pgrep
-f "$pat" >/dev
/null
; then
34 echo "Once more with feeling.."
39 rm -rf "${TEST_VAR_DIR}/test.db"
44 mkdir
-p "${TEST_VAR_DIR}/test.db/persistent"
46 local public_addresses_all
="${TEST_VAR_DIR}/public_addresses_all"
47 local no_public_addresses
="${TEST_VAR_DIR}/no_public_addresses.txt"
48 rm -f $CTDB_NODES $public_addresses_all $no_public_addresses
50 # If there are (strictly) greater than 2 nodes then we'll randomly
51 # choose a node to have no public addresses.
52 local no_public_ips
=-1
53 [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips
=$
(($RANDOM % $TEST_LOCAL_DAEMONS))
54 echo "$no_public_ips" >$no_public_addresses
56 # When running certain tests we add and remove eventscripts, so we
57 # need to be able to modify the events.d/ directory. Therefore,
58 # we use a temporary events.d/ directory under $TEST_VAR_DIR. We
59 # copy the actual test eventscript(s) in there from the original
60 # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
61 local top
=$
(dirname "$TEST_SCRIPTS_DIR")
62 local events_d
="${top}/events.d"
63 mkdir
-p "${TEST_VAR_DIR}/events.d"
64 cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
67 for i
in $
(seq 1 $TEST_LOCAL_DAEMONS) ; do
68 if [ "${CTDB_USE_IPV6}x" != "x" ]; then
69 echo ::$i >>"$CTDB_NODES"
70 ip addr add
::$i/128 dev lo
72 echo 127.0.0.
$i >>"$CTDB_NODES"
73 # 2 public addresses on most nodes, just to make things interesting.
74 if [ $
(($i - 1)) -ne $no_public_ips ] ; then
75 echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
76 echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
85 shift # "$@" gets passed to ctdbd
87 local public_addresses_all
="${TEST_VAR_DIR}/public_addresses_all"
88 local public_addresses_mine
="${TEST_VAR_DIR}/public_addresses.${pnn}"
89 local no_public_addresses
="${TEST_VAR_DIR}/no_public_addresses.txt"
91 local no_public_ips
=-1
92 [ -r $no_public_addresses ] && read no_public_ips
<$no_public_addresses
94 if [ "$no_public_ips" = $pnn ] ; then
95 echo "Node $no_public_ips will have no public IPs."
98 local node_ip
=$
(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
99 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 --logfile=${TEST_VAR_DIR}/daemon.${pnn}.log -d 3 --log-ringbuf-size=10000 --dbdir=${TEST_VAR_DIR}/test.db --dbdir-persistent=${TEST_VAR_DIR}/test.db/persistent --dbdir-state=${TEST_VAR_DIR}/test.db/state"
101 if [ $pnn -eq $no_public_ips ] ; then
102 ctdb_options
="$ctdb_options --public-addresses=/dev/null"
104 cp "$public_addresses_all" "$public_addresses_mine"
105 ctdb_options
="$ctdb_options --public-addresses=$public_addresses_mine"
108 # We'll use "pkill -f" to kill the daemons with
109 # "--socket=.* --nlist .* --nopublicipcheck" as context.
110 $VALGRIND ctdbd
--socket="${TEST_VAR_DIR}/sock.$pnn" $ctdb_options "$@" ||
return 1
115 # "$@" gets passed to ctdbd
117 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
119 for i
in $
(seq 0 $
(($TEST_LOCAL_DAEMONS - 1))) ; do
120 daemons_start_1
$i "$@"
126 if $TEST_CLEANUP ; then