Skip to content

Commit 8b949d9

Browse files
committed
MDEV-15511 Use stunnel during rsync SST if available
Merge the 10.2 version, which was created by Vasil Dimov.
2 parents 1b4c5b7 + 4c652fc commit 8b949d9

File tree

1 file changed

+64
-10
lines changed

1 file changed

+64
-10
lines changed

scripts/wsrep_sst_rsync.sh

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ cleanup_joiner()
4141
kill -9 $RSYNC_REAL_PID >/dev/null 2>&1 || \
4242
:
4343
rm -rf "$RSYNC_CONF"
44+
rm -f "$STUNNEL_CONF"
45+
rm -f "$STUNNEL_PID"
4446
rm -rf "$MAGIC_FILE"
4547
rm -rf "$RSYNC_PID"
4648
wsrep_log_info "Joiner cleanup done."
@@ -68,7 +70,7 @@ check_pid_and_port()
6870
local port_info="$(sockstat -46lp ${rsync_port} 2>/dev/null | \
6971
grep ":${rsync_port}")"
7072
local is_rsync="$(echo $port_info | \
71-
grep '[[:space:]]\+rsync[[:space:]]\+'"$rsync_pid" 2>/dev/null)"
73+
grep -E '[[:space:]]+(rsync|stunnel)[[:space:]]+'"$rsync_pid" 2>/dev/null)"
7274
;;
7375
*)
7476
if ! which lsof > /dev/null; then
@@ -79,7 +81,7 @@ check_pid_and_port()
7981
local port_info="$(lsof -i :$rsync_port -Pn 2>/dev/null | \
8082
grep "(LISTEN)")"
8183
local is_rsync="$(echo $port_info | \
82-
grep -w '^rsync[[:space:]]\+'"$rsync_pid" 2>/dev/null)"
84+
grep -E '^(rsync|stunnel)[[:space:]]+'"$rsync_pid" 2>/dev/null)"
8385
;;
8486
esac
8587

@@ -119,6 +121,12 @@ is_local_ip()
119121
$get_addr_bin | grep "$address" > /dev/null
120122
}
121123

124+
STUNNEL_CONF="$WSREP_SST_OPT_DATA/stunnel.conf"
125+
rm -f "$STUNNEL_CONF"
126+
127+
STUNNEL_PID="$WSREP_SST_OPT_DATA/stunnel.pid"
128+
rm -f "$STUNNEL_PID"
129+
122130
MAGIC_FILE="$WSREP_SST_OPT_DATA/rsync_sst_complete"
123131
rm -rf "$MAGIC_FILE"
124132

@@ -156,9 +164,28 @@ fi
156164
FILTER="-f '- /lost+found' -f '- /.fseventsd' -f '- /.Trashes'
157165
-f '+ /wsrep_sst_binlog.tar' -f '+ /ib_lru_dump' -f '+ /ibdata*' -f '+ /*/' -f '- /*'"
158166

167+
SSTKEY=$(parse_cnf sst tkey "")
168+
SSTCERT=$(parse_cnf sst tcert "")
169+
STUNNEL=""
170+
if [ -f "$SSTKEY" ] && [ -f "$SSTCERT" ] && wsrep_check_programs stunnel
171+
then
172+
STUNNEL="stunnel ${STUNNEL_CONF}"
173+
fi
174+
159175
if [ "$WSREP_SST_OPT_ROLE" = "donor" ]
160176
then
161177

178+
cat << EOF > "$STUNNEL_CONF"
179+
CApath = ${SSTCERT%/*}
180+
foreground = yes
181+
pid = $STUNNEL_PID
182+
debug = warning
183+
client = yes
184+
connect = ${WSREP_SST_OPT_ADDR%/*}
185+
TIMEOUTclose = 0
186+
verifyPeer = yes
187+
EOF
188+
162189
if [ $WSREP_SST_OPT_BYPASS -eq 0 ]
163190
then
164191

@@ -220,7 +247,8 @@ then
220247

221248
# first, the normal directories, so that we can detect incompatible protocol
222249
RC=0
223-
eval rsync --owner --group --perms --links --specials \
250+
eval rsync ${STUNNEL:+--rsh="$STUNNEL"} \
251+
--owner --group --perms --links --specials \
224252
--ignore-times --inplace --dirs --delete --quiet \
225253
$WHOLE_FILE_OPT ${FILTER} "$WSREP_SST_OPT_DATA/" \
226254
rsync://$WSREP_SST_OPT_ADDR >&2 || RC=$?
@@ -243,7 +271,8 @@ then
243271
fi
244272

245273
# second, we transfer InnoDB log files
246-
rsync --owner --group --perms --links --specials \
274+
rsync ${STUNNEL:+--rsh="$STUNNEL"} \
275+
--owner --group --perms --links --specials \
247276
--ignore-times --inplace --dirs --delete --quiet \
248277
$WHOLE_FILE_OPT -f '+ /ib_logfile[0-9]*' -f '- **' "$WSREP_LOG_DIR/" \
249278
rsync://$WSREP_SST_OPT_ADDR-log_dir >&2 || RC=$?
@@ -263,7 +292,8 @@ then
263292

264293
find . -maxdepth 1 -mindepth 1 -type d -not -name "lost+found" \
265294
-print0 | xargs -I{} -0 -P $count \
266-
rsync --owner --group --perms --links --specials \
295+
rsync ${STUNNEL:+--rsh="$STUNNEL"} \
296+
--owner --group --perms --links --specials \
267297
--ignore-times --inplace --recursive --delete --quiet \
268298
$WHOLE_FILE_OPT --exclude '*/ib_logfile*' "$WSREP_SST_OPT_DATA"/{}/ \
269299
rsync://$WSREP_SST_OPT_ADDR/{} >&2 || RC=$?
@@ -286,7 +316,8 @@ then
286316
echo "continue" # now server can resume updating data
287317

288318
echo "$STATE" > "$MAGIC_FILE"
289-
rsync --archive --quiet --checksum "$MAGIC_FILE" rsync://$WSREP_SST_OPT_ADDR
319+
rsync ${STUNNEL:+--rsh="$STUNNEL"} \
320+
--archive --quiet --checksum "$MAGIC_FILE" rsync://$WSREP_SST_OPT_ADDR
290321

291322
echo "done $STATE"
292323

@@ -347,14 +378,37 @@ EOF
347378
# If the IP is local listen only in it
348379
if is_local_ip "$RSYNC_ADDR"
349380
then
350-
rsync --daemon --no-detach --address "$RSYNC_ADDR" --port "$RSYNC_PORT" --config "$RSYNC_CONF" &
381+
RSYNC_EXTRA_ARGS="--address $RSYNC_ADDR"
382+
STUNNEL_ACCEPT="$RSYNC_ADDR:$RSYNC_PORT"
351383
else
352-
# Not local, possibly a NAT, listen in all interface
353-
rsync --daemon --no-detach --port "$RSYNC_PORT" --config "$RSYNC_CONF" &
384+
# Not local, possibly a NAT, listen on all interfaces
385+
RSYNC_EXTRA_ARGS=""
386+
STUNNEL_ACCEPT="$RSYNC_PORT"
354387
# Overwrite address with all
355388
RSYNC_ADDR="*"
356389
fi
357-
RSYNC_REAL_PID=$!
390+
391+
if [ -z "$STUNNEL" ]
392+
then
393+
rsync --daemon --no-detach --port "$RSYNC_PORT" --config "$RSYNC_CONF" ${RSYNC_EXTRA_ARGS} &
394+
RSYNC_REAL_PID=$!
395+
else
396+
cat << EOF > "$STUNNEL_CONF"
397+
key = $SSTKEY
398+
cert = $SSTCERT
399+
foreground = yes
400+
pid = $STUNNEL_PID
401+
debug = warning
402+
client = no
403+
[rsync]
404+
accept = $STUNNEL_ACCEPT
405+
exec = $(which rsync)
406+
execargs = rsync --server --daemon --config=$RSYNC_CONF .
407+
EOF
408+
stunnel "$STUNNEL_CONF" &
409+
RSYNC_REAL_PID=$!
410+
RSYNC_PID=$STUNNEL_PID
411+
fi
358412

359413
until check_pid_and_port "$RSYNC_PID" "$RSYNC_REAL_PID" "$RSYNC_ADDR" "$RSYNC_PORT"
360414
do

0 commit comments

Comments
 (0)