Skip to content

Commit 6f741c6

Browse files
committed
Loop around rsync when it is broken
1 parent 403f677 commit 6f741c6

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

rspamd_build.sh

+34-9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,30 @@ if [ $FETCH_STAGE -eq 1 ] ; then
144144
fi
145145
gh_hash=`$SSH_CMD $SSH_HOST_X86 "cd rspamd ; git rev-parse --short HEAD"`
146146

147+
retry_rsync() {
148+
local RETRY_INTERVAL=5
149+
local MAX_ATTEMPTS=100
150+
local attempt=0
151+
152+
while true; do
153+
rsync "$@"
154+
155+
local RSYNC_EXIT_CODE=$?
156+
157+
if [ $RSYNC_EXIT_CODE -eq 0 ]; then
158+
return 0
159+
fi
160+
161+
if [ "$attempt" -ge "$MAX_ATTEMPTS" ]; then
162+
exit 1
163+
fi
164+
165+
attempt=$((attempt + 1))
166+
sleep $RETRY_INTERVAL
167+
done
168+
}
169+
170+
147171
build_rspamd_deb() {
148172
HOST=$1
149173
DISTNAME=$2
@@ -204,6 +228,7 @@ if [ ${DIST} -ne 0 ] ; then
204228
fi
205229

206230
if [ $BUILD_STAGE -eq 1 ] ; then
231+
rm -fr ${TARGET_DIR}
207232
mkdir -p ${TARGET_DIR}
208233
if [ -n "${STABLE}" ] ; then
209234
_version="${STABLE_VER}"
@@ -305,10 +330,10 @@ EOD
305330
# Copy old packages remaining to include them into the repo
306331
if [ ${NO_DELETE} -eq 0 ] ; then
307332
if [ -n "${STABLE}" ] ; then
308-
rsync -e "ssh -i ${SSH_KEY_DEB_STABLE}" --ignore-existing ${RSYNC_ARGS} \
333+
retry_rsync -e "ssh -i ${SSH_KEY_DEB_STABLE}" --ignore-existing ${RSYNC_ARGS} \
309334
${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_DEB_STABLE}/* ${TARGET_DIR}/repos/
310335
else
311-
rsync -e "ssh -i ${SSH_KEY_DEB_UNSTABLE}" --ignore-existing ${RSYNC_ARGS} \
336+
retry_rsync -e "ssh -i ${SSH_KEY_DEB_UNSTABLE}" --ignore-existing ${RSYNC_ARGS} \
312337
${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_DEB_UNSTABLE}/* ${TARGET_DIR}/repos/
313338
fi
314339
fi
@@ -330,7 +355,7 @@ EOD
330355
reprepro -P extra -S debug -b $_repodir -v --keepunreferencedfiles includedeb $_distname $deb_pkg
331356
done
332357
for deb_dsc in ${TARGET_DIR}/$d/rspamd_*.dsc ; do
333-
reprepro -P extra -S mail -b $_repodir -v --keepunreferencedfiles includedsc $_distname
358+
reprepro -P extra -S mail -b $_repodir -v --keepunreferencedfiles includedsc $_distname $deb_dsc
334359
done
335360

336361
debsign --re-sign -k $KEY ${TARGET_DIR}/$d/rspamd_*.changes
@@ -354,10 +379,10 @@ EOD
354379
# Copy old stuff
355380
if [ ${NO_DELETE} -eq 0 ] ; then
356381
if [ -n "${STABLE}" ] ; then
357-
rsync -e "ssh -i ${SSH_KEY_RPM_STABLE}" ${RSYNC_ARGS} --ignore-existing \
382+
retry_rsync -e "ssh -i ${SSH_KEY_RPM_STABLE}" ${RSYNC_ARGS} --ignore-existing \
358383
${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_RPM_STABLE}/$d/* ${TARGET_DIR}/rpm/$d/
359384
else
360-
rsync -e "ssh -i ${SSH_KEY_RPM_UNSTABLE}" ${RSYNC_ARGS} --ignore-existing \
385+
retry_rsync -e "ssh -i ${SSH_KEY_RPM_UNSTABLE}" ${RSYNC_ARGS} --ignore-existing \
361386
${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_RPM_UNSTABLE}/$d/* ${TARGET_DIR}/rpm/$d/
362387
fi
363388
fi
@@ -421,21 +446,21 @@ if [ ${UPLOAD_STAGE} -eq 1 ] ; then
421446

422447
if [ $DEBIAN -ne 0 ] ; then
423448
if [ -n "${STABLE}" ] ; then
424-
rsync -e "ssh -i ${SSH_KEY_DEB_STABLE}" ${RSYNC_ARGS} \
449+
retry_rsync -e "ssh -i ${SSH_KEY_DEB_STABLE}" ${RSYNC_ARGS} \
425450
${TARGET_DIR}/repos/* ${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_DEB_STABLE}
426451
else
427-
rsync -e "ssh -i ${SSH_KEY_DEB_UNSTABLE}" ${RSYNC_ARGS} \
452+
retry_rsync -e "ssh -i ${SSH_KEY_DEB_UNSTABLE}" ${RSYNC_ARGS} \
428453
${TARGET_DIR}/repos/* ${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_DEB_UNSTABLE}
429454
fi
430455
fi
431456

432457
if [ $RPM -ne 0 ] ; then
433458
for d in $DISTRIBS_RPM ; do
434459
if [ -n "${STABLE}" ] ; then
435-
rsync -e "ssh -i ${SSH_KEY_RPM_STABLE}" ${RSYNC_ARGS} \
460+
retry_rsync -e "ssh -i ${SSH_KEY_RPM_STABLE}" ${RSYNC_ARGS} \
436461
${TARGET_DIR}/rpm/$d/* ${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_RPM_STABLE}/$d/
437462
else
438-
rsync -e "ssh -i ${SSH_KEY_RPM_UNSTABLE}" ${RSYNC_ARGS} \
463+
retry_rsync -e "ssh -i ${SSH_KEY_RPM_UNSTABLE}" ${RSYNC_ARGS} \
439464
${TARGET_DIR}/rpm/$d/* ${UPLOAD_HOST}:${UPLOAD_SUFFIX}${TARGET_RPM_UNSTABLE}/$d/
440465
fi
441466
done

0 commit comments

Comments
 (0)