summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-05-17 14:44:48 +0200
committerErich Eckner <git@eckner.net>2017-05-17 14:45:15 +0200
commitb5e64080699536e7802e1b3dd105032386573f63 (patch)
treee46848bcc5fac023c0a0f02809038900d6a121e7
parenta689951e9d6ace2e1d617cdd8ab337a60fe56c74 (diff)
downloadbuilder-b5e64080699536e7802e1b3dd105032386573f63.tar.xz
bin/return-assignment: add lock file
-rwxr-xr-xbin/build-packages24
-rwxr-xr-xbin/return-assignment25
2 files changed, 35 insertions, 14 deletions
diff --git a/bin/build-packages b/bin/build-packages
index 70676d5..c3be5ff 100755
--- a/bin/build-packages
+++ b/bin/build-packages
@@ -110,17 +110,23 @@ while [ ${count} -ne 0 ]; do
# build successful
ls -1 *.pkg.tar.xz | \
xargs -rn1 gpg --detach-sign
- if ! tar -c *.pkg.tar.xz{,.sig} | \
- ssh \
- -i "${master_build_server_identity}" \
- -p "${master_build_server_port}" \
- "${master_build_server_user}@${master_build_server}" \
- 'return-assignment' "${package}" "${git_revision}" "${mod_git_revision}" "${repository}"; then
+ tar -c 'package.tar' *.pkg.tar.xz{,.sig}
+ while ! ssh \
+ -i "${master_build_server_identity}" \
+ -p "${master_build_server_port}" \
+ "${master_build_server_user}@${master_build_server}" \
+ 'return-assignment' "${package}" "${git_revision}" "${mod_git_revision}" "${repository}" \
+ < 'package.tar'; do
case $? in
1)
- >&2 echo 'I was too slow, the package is outdated. I will continue ...'
+ # 'return-assignment' was running already
+ sleep $[15+$RANDOM%30]
;;
2)
+ >&2 echo 'I was too slow, the package is outdated. I will continue ...'
+ break
+ ;;
+ 3)
>& echo "'return-assignment' reports a signature error."
exit 1
;;
@@ -128,7 +134,7 @@ while [ ${count} -ne 0 ]; do
>&2 echo "unknown return code $? from 'return-assignment'"
exit 1
esac
- fi
+ done
success=true
break
fi
@@ -179,7 +185,7 @@ while [ ${count} -ne 0 ]; do
*)
- >&2 echo "ERROR: Unknown exit code $?."
+ >&2 echo "ERROR: Unknown exit code $? from 'get-assignment'."
exit 1
;;
diff --git a/bin/return-assignment b/bin/return-assignment
index 3468f49..b8d1bb4 100755
--- a/bin/return-assignment
+++ b/bin/return-assignment
@@ -9,16 +9,31 @@
# exit codes:
# 0: ok
-# 1: outdated package
-# 2: signature error
+# 1: another instance was already running
+# 2: outdated package
+# 3: signature error
# TODO:
-# use lock file(s)
+# use lock file for build list
# remove old version(s) of newly compiled packages
# check that received archive contains the expected packages
. "${0%/*}/../conf/default.conf"
+# Create a lock file and a trap.
+
+exec 9> "${lock_file}"
+if ! flock -n 9; then
+ >&2 echo 'come back (shortly) later - I was running already'
+ exit 1
+fi
+
+function clean_up {
+ rm -f "${lock_file}"
+}
+
+trap clean_up EXIT
+
if [ "$5" == 'ERROR' ]; then
# the build failed on the build slave
@@ -51,7 +66,7 @@ fi
if ! grep -q "^${1//./\\.} $2 $3 $4\$" "${work_dir}/build-list"; then
>&2 echo 'Sorry, the sent package is outdated.'
- exit 1
+ exit 2
fi
function clean_up {
@@ -78,7 +93,7 @@ signature_errors="$(
if [ -n "${signature_errors}" ]; then
>&2 echo 'The following packages lack a signature or vice versa:'
>&2 echo "${signature_errors}"
- exit 2
+ exit 3
fi
# move packages