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 # ctdbd_wrapper is in config/ directory
13 PATH="${ctdb_dir}/bin:${ctdb_dir}/config:${PATH}"
14 hdir="${ctdb_dir}/bin"
15 export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
16 export CTDB_EVENT_HELPER="${hdir}/ctdb_event_helper"
17 export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
18 export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
21 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
23 #######################################
27 echo "Attempting to politely shutdown daemons..."
28 onnode -q all $CTDB shutdown || true
30 echo "Sleeping for a while..."
33 local pat="ctdbd --sloppy-start --nopublicipcheck"
34 if pgrep -f "$pat" >/dev/null ; then
35 echo "Killing remaining daemons..."
38 if pgrep -f "$pat" >/dev/null ; then
39 echo "Once more with feeling.."
44 rm -rf "${TEST_VAR_DIR}/test.db"
49 mkdir -p "${TEST_VAR_DIR}/test.db/persistent"
51 local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
52 local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
53 rm -f $CTDB_NODES $public_addresses_all $no_public_addresses
55 # If there are (strictly) greater than 2 nodes then we'll randomly
56 # choose a node to have no public addresses.
57 local no_public_ips=-1
58 [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
59 echo "$no_public_ips" >$no_public_addresses
61 # When running certain tests we add and remove eventscripts, so we
62 # need to be able to modify the events.d/ directory. Therefore,
63 # we use a temporary events.d/ directory under $TEST_VAR_DIR. We
64 # copy the actual test eventscript(s) in there from the original
65 # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
66 local top=$(dirname "$TEST_SCRIPTS_DIR")
67 local events_d="${top}/events.d"
68 mkdir -p "${TEST_VAR_DIR}/events.d"
69 cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
72 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
73 if [ "${CTDB_USE_IPV6}x" != "x" ]; then
74 j=$((printf "%02x" $i))
75 echo "fd00::5357:5f${j}" >>"$CTDB_NODES"
76 # FIXME: need to add addresses to lo as root before running :-(
77 # ip addr add "fc00:10::${i}/64" dev lo
78 # 2 public addresses on most nodes, just to make things interesting.
79 if [ $(($i - 1)) -ne $no_public_ips ] ; then
80 echo "fc00:10::1:${i}/64 lo" >>"$public_addresses_all"
81 echo "fc00:10::1:$(($i + $TEST_LOCAL_DAEMONS))/64 lo" >>"$public_addresses_all"
85 echo 127.0.0.$j >>"$CTDB_NODES"
86 # 2 public addresses on most nodes, just to make things interesting.
87 if [ $(($i - 1)) -ne $no_public_ips ] ; then
88 echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
89 echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
98 shift # "$@" gets passed to ctdbd
100 local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
101 local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"
102 local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
103 local public_addresses
105 local no_public_ips=-1
106 [ -r $no_public_addresses ] && read no_public_ips <$no_public_addresses
108 if [ "$no_public_ips" = $pnn ] ; then
109 echo "Node $no_public_ips will have no public IPs."
110 public_addresses="/dev/null"
112 cp "$public_addresses_all" "$public_addresses_mine"
113 public_addresses="$public_addresses_mine"
116 local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
118 local pidfile="${TEST_VAR_DIR}/ctdbd.${pnn}.pid"
119 local conf="${TEST_VAR_DIR}/ctdbd.${pnn}.conf"
121 CTDB_RECOVERY_LOCK="${TEST_VAR_DIR}/rec.lock"
122 CTDB_NODES="$CTDB_NODES"
123 CTDB_NODE_ADDRESS="${node_ip}"
124 CTDB_EVENT_SCRIPT_DIR="${TEST_VAR_DIR}/events.d"
125 CTDB_LOGGING="file:${TEST_VAR_DIR}/daemon.${pnn}.log"
127 CTDB_DBDIR="${TEST_VAR_DIR}/test.db"
128 CTDB_DBDIR_PERSISTENT="${TEST_VAR_DIR}/test.db/persistent"
129 CTDB_DBDIR_STATE="${TEST_VAR_DIR}/test.db/state"
130 CTDB_PUBLIC_ADDRESSES="${public_addresses}"
131 CTDB_SOCKET="${TEST_VAR_DIR}/sock.$pnn"
135 # Override from the environment. This would be easier if env was
136 # guaranteed to quote its output so it could be reused.
139 sed -e 's@=\([^"]\)@="\1@' -e 's@[^"]$@&"@' -e 's@="$@&"@' >>"$conf"
141 # We'll use "pkill -f" to kill the daemons with
142 # "ctdbd --sloppy-start --nopublicipcheck" as context.
143 CTDBD="${VALGRIND} ctdbd --sloppy-start --nopublicipcheck" \
145 ctdbd_wrapper "$pidfile" start
150 # "$@" gets passed to ctdbd
152 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
154 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
155 daemons_start_1 $i "$@"
161 if $TEST_CLEANUP ; then