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 # Use in-tree binaries if running against local daemons.
5 # Otherwise CTDB need to be installed on all nodes.
6 if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
7 # ctdbd_wrapper is in config/ directory
8 PATH="${ctdb_dir}/bin:${ctdb_dir}/config:${PATH}"
10 export CTDB_EVENTD="${hdir}/ctdb_eventd"
11 export CTDB_EVENT_HELPER="${hdir}/ctdb_event"
12 export CTDB_LOCK_HELPER="${hdir}/ctdb_lock_helper"
13 export CTDB_RECOVERY_HELPER="${hdir}/ctdb_recovery_helper"
14 export CTDB_TAKEOVER_HELPER="${hdir}/ctdb_takeover_helper"
15 export CTDB_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
18 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
20 #######################################
22 config_from_environment ()
24 # Override from the environment. This would be easier if env was
25 # guaranteed to quote its output so it could be reused.
28 sed -e 's@=\([^"]\)@="\1@' -e 's@[^"]$@&"@' -e 's@="$@&"@'
31 # If the given IP is hosted then print 2 items: maskbits and iface
42 t=$(ip addr show to "${addr}/${bits}")
50 echo "${TEST_VAR_DIR}/node.${pnn}"
57 local node_dir=$(node_dir "$pnn")
58 echo "${node_dir}/ctdbd.conf"
65 local node_dir=$(node_dir "$pnn")
66 echo "${node_dir}/ctdbd.pid"
73 local node_dir=$(node_dir "$pnn")
74 echo "${node_dir}/ctdbd.socket"
79 local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
80 rm -f $CTDB_NODES $public_addresses_all
82 # If there are (strictly) greater than 2 nodes then we'll randomly
83 # choose a node to have no public addresses.
84 local no_public_ips=-1
85 [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
87 # When running certain tests we add and remove eventscripts, so we
88 # need to be able to modify the events.d/ directory. Therefore,
89 # we use a temporary events.d/ directory under $TEST_VAR_DIR. We
90 # copy the actual test eventscript(s) in there from the original
91 # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
92 local top=$(dirname "$TEST_SCRIPTS_DIR")
93 local events_d="${top}/events.d"
94 mkdir -p "${TEST_VAR_DIR}/events.d"
95 cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
97 local have_all_ips=true
99 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
100 if [ -n "$CTDB_USE_IPV6" ]; then
101 local j=$(printf "%02x" $i)
102 local node_ip="fd00::5357:5f${j}"
103 if have_ip "$node_ip" ; then
104 echo "$node_ip" >>"$CTDB_NODES"
106 echo "ERROR: ${node_ip} not on an interface, please add it"
110 # 2 public addresses on most nodes, just to make things interesting.
111 if [ $(($i - 1)) -ne $no_public_ips ] ; then
112 echo "fc00:10::1:${i}/64 lo" >>"$public_addresses_all"
113 echo "fc00:10::1:$(($i + $TEST_LOCAL_DAEMONS))/64 lo" >>"$public_addresses_all"
117 echo 127.0.0.$j >>"$CTDB_NODES"
118 # 2 public addresses on most nodes, just to make things interesting.
119 if [ $(($i - 1)) -ne $no_public_ips ] ; then
120 echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
121 echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
126 if ! $have_all_ips ; then
131 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
132 local node_dir=$(node_dir "$pnn")
135 local public_addresses_mine="${node_dir}/public_addresses"
136 local public_addresses
138 if [ "$no_public_ips" = $pnn ] ; then
139 echo "Node $no_public_ips will have no public IPs."
140 public_addresses="/dev/null"
142 cp "$public_addresses_all" "$public_addresses_mine"
143 public_addresses="$public_addresses_mine"
146 local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
148 local conf=$(node_conf "$pnn")
149 local socket=$(node_socket "$pnn")
151 local db_dir="${node_dir}/db"
152 mkdir -p "${db_dir}/persistent"
155 CTDB_RECOVERY_LOCK="${TEST_VAR_DIR}/rec.lock"
156 CTDB_NODES="$CTDB_NODES"
157 CTDB_NODE_ADDRESS="${node_ip}"
158 CTDB_EVENT_SCRIPT_DIR="${TEST_VAR_DIR}/events.d"
159 CTDB_LOGGING="file:${node_dir}/log.ctdb"
161 CTDB_DBDIR="${db_dir}"
162 CTDB_DBDIR_PERSISTENT="${db_dir}/persistent"
163 CTDB_DBDIR_STATE="${db_dir}/state"
164 CTDB_PUBLIC_ADDRESSES="${public_addresses}"
165 CTDB_SOCKET="${socket}"
169 # Append any configuration variables set in environment to
170 # configuration file so they affect CTDB after each restart.
171 config_from_environment >>"$conf"
178 local pidfile=$(node_pidfile "$pnn")
179 local conf=$(node_conf "$pnn")
181 # If there is any CTDB configuration in the environment then
182 # append it to the regular configuration in a temporary
183 # configuration file and use it just this once.
185 local env_conf=$(config_from_environment)
186 if [ -n "$env_conf" ] ; then
187 tmp_conf=$(mktemp --tmpdir="$TEST_VAR_DIR")
188 cat "$conf" >"$tmp_conf"
189 echo "$env_conf" >>"$tmp_conf"
193 CTDBD="${VALGRIND} ctdbd --sloppy-start --nopublicipcheck" \
195 ctdbd_wrapper "$pidfile" start
197 if [ -n "$tmp_conf" ] ; then
205 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
208 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
216 local pidfile=$(node_pidfile "$pnn")
217 local conf=$(node_conf "$pnn")
220 ctdbd_wrapper "$pidfile" stop
225 echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
228 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
232 rm -rf "${TEST_VAR_DIR}/test.db"
243 if $TEST_CLEANUP ; then
256 # If this fails to find processes then the tests fails, so
257 # look at full command-line so this will work with valgrind.
258 # Note that the output could be generated with pgrep's -a
259 # option but it doesn't exist in older versions.
260 ps -p $(pgrep -f '\<ctdbd\>' | xargs | sed -e 's| |,|g') -o args ww
264 # onnode will use CTDB_NODES_SOCKETS to help the ctdb tool connection
266 export CTDB_NODES_SOCKETS=""
267 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
268 socket=$(node_socket "$i")
269 CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${socket}"