From b5e64080699536e7802e1b3dd105032386573f63 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 17 May 2017 14:44:48 +0200 Subject: bin/return-assignment: add lock file --- bin/build-packages | 24 +++++++++++++++--------- bin/return-assignment | 25 ++++++++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) (limited to 'bin') 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 -- cgit v1.2.3-54-g00ecf