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_CLUSTER_MUTEX_HELPER="${hdir}/ctdb_mutex_fcntl_helper"
17 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
19 #######################################
21 config_from_environment ()
23 # Override from the environment. This would be easier if env was
24 # guaranteed to quote its output so it could be reused.
27 sed -e 's@=\([^"]\)@="\1@' -e 's@[^"]$@&"@' -e 's@="$@&"@'
30 # If the given IP is hosted then print 2 items: maskbits and iface
41 t=$(ip addr show to "${addr}/${bits}")
49 echo "${TEST_VAR_DIR}/node.${pnn}"
56 local node_dir=$(node_dir "$pnn")
57 echo "${node_dir}/ctdbd.conf"
64 local node_dir=$(node_dir "$pnn")
65 echo "${node_dir}/ctdbd.pid"
72 local node_dir=$(node_dir "$pnn")
73 echo "${node_dir}/ctdbd.socket"
78 local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
79 rm -f $CTDB_NODES $public_addresses_all
81 # If there are (strictly) greater than 2 nodes then we'll randomly
82 # choose a node to have no public addresses.
83 local no_public_ips=-1
84 [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
86 # When running certain tests we add and remove eventscripts, so we
87 # need to be able to modify the events.d/ directory. Therefore,
88 # we use a temporary events.d/ directory under $TEST_VAR_DIR. We
89 # copy the actual test eventscript(s) in there from the original
90 # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
91 local top=$(dirname "$TEST_SCRIPTS_DIR")
92 local events_d="${top}/events.d"
93 mkdir -p "${TEST_VAR_DIR}/events.d"
94 cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
96 local have_all_ips=true
98 for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
99 if [ -n "$CTDB_USE_IPV6" ]; then
100 local j=$(printf "%02x" $i)
101 local node_ip="fd00::5357:5f${j}"
102 if have_ip "$node_ip" ; then
103 echo "$node_ip" >>"$CTDB_NODES"
105 echo "ERROR: ${node_ip} not on an interface, please add it"
109 # 2 public addresses on most nodes, just to make things interesting.
110 if [ $(($i - 1)) -ne $no_public_ips ] ; then
111 echo "fc00:10::1:${i}/64 lo" >>"$public_addresses_all"
112 echo "fc00:10::1:$(($i + $TEST_LOCAL_DAEMONS))/64 lo" >>"$public_addresses_all"
116 echo 127.0.0.$j >>"$CTDB_NODES"
117 # 2 public addresses on most nodes, just to make things interesting.
118 if [ $(($i - 1)) -ne $no_public_ips ] ; then
119 echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
120 echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
125 if ! $have_all_ips ; then
130 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
131 local node_dir=$(node_dir "$pnn")
134 local public_addresses_mine="${node_dir}/public_addresses"
135 local public_addresses
137 if [ "$no_public_ips" = $pnn ] ; then
138 echo "Node $no_public_ips will have no public IPs."
139 public_addresses="/dev/null"
141 cp "$public_addresses_all" "$public_addresses_mine"
142 public_addresses="$public_addresses_mine"
145 local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
147 local conf=$(node_conf "$pnn")
148 local socket=$(node_socket "$pnn")
150 local db_dir="${node_dir}/db"
151 mkdir -p "${db_dir}/persistent"
154 CTDB_RECOVERY_LOCK="${TEST_VAR_DIR}/rec.lock"
155 CTDB_NODES="$CTDB_NODES"
156 CTDB_NODE_ADDRESS="${node_ip}"
157 CTDB_EVENT_SCRIPT_DIR="${TEST_VAR_DIR}/events.d"
158 CTDB_LOGGING="file:${node_dir}/log.ctdb"
160 CTDB_DBDIR="${db_dir}"
161 CTDB_DBDIR_PERSISTENT="${db_dir}/persistent"
162 CTDB_DBDIR_STATE="${db_dir}/state"
163 CTDB_PUBLIC_ADDRESSES="${public_addresses}"
164 CTDB_SOCKET="${socket}"
168 # Append any configuration variables set in environment to
169 # configuration file so they affect CTDB after each restart.
170 config_from_environment >>"$conf"
176 echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
179 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
180 local pidfile=$(node_pidfile "$pnn")
181 local conf=$(node_conf "$pnn")
183 # If there is any CTDB configuration in the environment then
184 # append it to the regular configuration in a temporary
185 # configuration file and use it just this once.
187 local env_conf=$(config_from_environment)
188 if [ -n "$env_conf" ] ; then
189 tmp_conf=$(mktemp --tmpdir="$TEST_VAR_DIR")
190 cat "$conf" >"$tmp_conf"
191 echo "$env_conf" >>"$tmp_conf"
195 CTDBD="${VALGRIND} ctdbd --sloppy-start --nopublicipcheck" \
197 ctdbd_wrapper "$pidfile" start
199 if [ -n "$tmp_conf" ] ; then
207 echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
210 for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
211 local pidfile=$(node_pidfile "$pnn")
212 local conf=$(node_conf "$pnn")
215 ctdbd_wrapper "$pidfile" stop
218 rm -rf "${TEST_VAR_DIR}/test.db"
223 if $TEST_CLEANUP ; then
236 # If this fails to find processes then the tests fails, so
237 # look at full command-line so this will work with valgrind.
238 # Note that the output could be generated with pgrep's -a
239 # option but it doesn't exist in older versions.
240 ps -p $(pgrep -f '\<ctdbd\>' | xargs | sed -e 's| |,|g') -o args ww
244 # onnode will use CTDB_NODES_SOCKETS to help the ctdb tool connection
246 export CTDB_NODES_SOCKETS=""
247 for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
248 socket=$(node_socket "$i")
249 CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${socket}"