summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordd <dd@wx.tnyzeq.icu>2024-07-01 10:51:20 +0200
committerdd <dd@wx.tnyzeq.icu>2024-07-01 12:57:10 +0200
commitf4d4bdb3256707707a17d92de86c52a8c97bda98 (patch)
treeff7abe77d488ba0e72de5a4656d5df60eab71be6
parentf3a27f88d8ae1ef0fef70b9fb920797919afae4b (diff)
downloadvyos-jenkins-f4d4bdb3256707707a17d92de86c52a8c97bda98.tar.gz
vyos-jenkins-f4d4bdb3256707707a17d92de86c52a8c97bda98.zip
added reprepro-mirror lock
-rwxr-xr-xextras/mirror/reprepro-mirror.sh17
1 files changed, 16 insertions, 1 deletions
diff --git a/extras/mirror/reprepro-mirror.sh b/extras/mirror/reprepro-mirror.sh
index 41bc8a0..04b68ac 100755
--- a/extras/mirror/reprepro-mirror.sh
+++ b/extras/mirror/reprepro-mirror.sh
@@ -15,7 +15,7 @@ set -e
# that doesn't need to be as efficient as rsync is since it will run only when necessary.
#
# Extra dependencies:
-# apt install curl jq rsync
+# apt install --no-install-recommends -y curl jq rsync procmail
#
# Configuration:
# export TARGET_PATH=mirror@10.0.0.127:/var/www/...
@@ -43,10 +43,15 @@ markerFiles=(
# Metadata.
workDir="/tmp/reprepro-mirror"
lastSyncPath="$workDir/lastSync"
+lockPath="$workDir/lock"
# Should be synchronization postponed? Return 1 if yes otherwise 0.
function isSynchronizationPostponed {
jenkinsIdle=$(curl -Ss -g --fail-with-body "$jenkinsUrl/computer/api/json" | jq .computer[0].idle)
+ exitCode=$?
+ if [ "$exitCode" -ne 0 ]; then
+ exit $exitCode
+ fi
if [ "$jenkinsIdle" == "true" ]; then
return 0
fi
@@ -54,6 +59,16 @@ function isSynchronizationPostponed {
}
# The logic.
+if lockfile -0 -r 0 -! "$lockPath" > /dev/null 2>&1; then
+ echo "Other synchronization is already in progress."
+ exit 0
+fi
+
+function cleanup {
+ rm -f "$lockPath"
+}
+trap '(exit 130)' INT; trap '(exit 143)' TERM; trap cleanup EXIT
+
function formatDate {
echo $(date -d "@$1" "+%Y-%m-%d %H:%M:%S")
}