blob: ea4272db2e665d774b658c56f11affa6abb5ca9f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# If we're not running on a real cluster then we need a local copy of
# ctdb (and other stuff) in $PATH and we will use local daemons.
export CTDB_NODES_SOCKETS=""
for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${TEST_VAR_DIR}/sock.${i}"
done
# Use in-tree binaries if running against local daemons.
# Otherwise CTDB need to be installed on all nodes.
if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
# ctdbd_wrapper is in config/ directory
PATH="${ctdb_dir}/bin:${ctdb_dir}/config:${PATH}"
export CTDB_LOCK_HELPER="${ctdb_dir}/bin/ctdb_lock_helper"
export CTDB_EVENT_HELPER="${ctdb_dir}/bin/ctdb_event_helper"
export CTDB_RECOVERY_HELPER="${ctdb_dir}/bin/ctdb_recovery_helper"
fi
export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
#######################################
daemons_stop ()
{
echo "Attempting to politely shutdown daemons..."
onnode -q all $CTDB shutdown || true
echo "Sleeping for a while..."
sleep_for 1
local pat="ctdbd --sloppy-start --nopublicipcheck --nosetsched"
if pgrep -f "$pat" >/dev/null ; then
echo "Killing remaining daemons..."
pkill -f "$pat"
if pgrep -f "$pat" >/dev/null ; then
echo "Once more with feeling.."
pkill -9 -f "$pat"
fi
fi
rm -rf "${TEST_VAR_DIR}/test.db"
}
setup_ctdb ()
{
mkdir -p "${TEST_VAR_DIR}/test.db/persistent"
local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
rm -f $CTDB_NODES $public_addresses_all $no_public_addresses
# If there are (strictly) greater than 2 nodes then we'll randomly
# choose a node to have no public addresses.
local no_public_ips=-1
[ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
echo "$no_public_ips" >$no_public_addresses
# When running certain tests we add and remove eventscripts, so we
# need to be able to modify the events.d/ directory. Therefore,
# we use a temporary events.d/ directory under $TEST_VAR_DIR. We
# copy the actual test eventscript(s) in there from the original
# events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
local top=$(dirname "$TEST_SCRIPTS_DIR")
local events_d="${top}/events.d"
mkdir -p "${TEST_VAR_DIR}/events.d"
cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
local i
for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
if [ "${CTDB_USE_IPV6}x" != "x" ]; then
j=$((printf "%02x" $i))
echo "fd00::5357:5f${j}" >>"$CTDB_NODES"
# FIXME: need to add addresses to lo as root before running :-(
# ip addr add "fc00:10::${i}/64" dev lo
# 2 public addresses on most nodes, just to make things interesting.
if [ $(($i - 1)) -ne $no_public_ips ] ; then
echo "fc00:10::1:${i}/64 lo" >>"$public_addresses_all"
echo "fc00:10::1:$(($i + $TEST_LOCAL_DAEMONS))/64 lo" >>"$public_addresses_all"
fi
else
j=$(( $i + 10))
echo 127.0.0.$j >>"$CTDB_NODES"
# 2 public addresses on most nodes, just to make things interesting.
if [ $(($i - 1)) -ne $no_public_ips ] ; then
echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
fi
fi
done
}
daemons_start_1 ()
{
local pnn="$1"
shift # "$@" gets passed to ctdbd
local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"
local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
local public_addresses
local no_public_ips=-1
[ -r $no_public_addresses ] && read no_public_ips <$no_public_addresses
if [ "$no_public_ips" = $pnn ] ; then
echo "Node $no_public_ips will have no public IPs."
public_addresses="/dev/null"
else
cp "$public_addresses_all" "$public_addresses_mine"
public_addresses="$public_addresses_mine"
fi
local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
local pidfile="${TEST_VAR_DIR}/ctdbd.${pnn}.pid"
local conf="${TEST_VAR_DIR}/ctdbd.${pnn}.conf"
cat >"$conf" <<EOF
CTDB_RECOVERY_LOCK="${TEST_VAR_DIR}/rec.lock"
CTDB_NODES="$CTDB_NODES"
CTDB_NODE_ADDRESS="${node_ip}"
CTDB_EVENT_SCRIPT_DIR="${TEST_VAR_DIR}/events.d"
CTDB_LOGGING="file:${TEST_VAR_DIR}/daemon.${pnn}.log"
CTDB_DEBUGLEVEL=3
CTDB_DBDIR="${TEST_VAR_DIR}/test.db"
CTDB_DBDIR_PERSISTENT="${TEST_VAR_DIR}/test.db/persistent"
CTDB_DBDIR_STATE="${TEST_VAR_DIR}/test.db/state"
CTDB_PUBLIC_ADDRESSES="${public_addresses}"
CTDB_SOCKET="${TEST_VAR_DIR}/sock.$pnn"
EOF
# We'll use "pkill -f" to kill the daemons with
# "ctdbd --sloppy-start --nopublicipcheck --nosetsched" as context.
CTDBD="ctdbd --sloppy-start --nopublicipcheck --nosetsched" \
CTDBD_CONF="$conf" \
ctdbd_wrapper "$pidfile" start
}
daemons_start ()
{
# "$@" gets passed to ctdbd
echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
daemons_start_1 $i "$@"
done
}
maybe_stop_ctdb ()
{
if $TEST_CLEANUP ; then
daemons_stop
fi
}
_restart_ctdb_all ()
{
daemons_stop
daemons_start "$@"
}
|