From cd8f14bc0cd7f1ee28e12c241526b2e7f97148ae Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 16 Sep 2020 23:40:39 -0700 Subject: [PATCH] update.sh: use "update.pid" lock against simultaneous updates Use the "update.pid" lock file similarly to the way the "gc.pid" file is used to lock out simultaneous updates of the same project. The `update.sh` script does not handle having multiple copies run simultaneously for the same project. With this change it, all copies but the first will error out. This, however, does not yet mean that `update.sh` can run simultaneously on the same project as `gc.sh`. While theoretically such is possible (since remote pushes into the repository are always allowed while `gc.sh` is running on the repository), the `update.sh` script will need a full audit before allowing such a thing. Signed-off-by: Kyle J. McKay --- jobd/update.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jobd/update.sh b/jobd/update.sh index ea21e07..80e5edc 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -1,6 +1,7 @@ #!/bin/sh . @basedir@/shlib.sh +. @basedir@/jobd/updategc-util-functions.sh set -e @@ -103,6 +104,15 @@ git_bzr_fetch() ( return $? ) +# On return a "$lockf" will have been created that must be removed when gc is done +lock_update() { + v_lock_file _lockresult "update.pid" || { + echo >&2 "[$proj] $_lockresult" + exit 1 + } + lockf="$_lockresult" +} + [ -n "$cfg_mirror" ] || { echo "Mirroring is disabled" >&2; exit 0; } umask 002 @@ -124,6 +134,7 @@ check_and_set_needsgc bang_log= incoming_fetch= incoming_objs= +lockf= cleanup_exit() { ec=$? if [ $ec != 0 ]; then @@ -132,6 +143,7 @@ cleanup_exit() { [ -z "$incoming_fetch" ] || rm -rf "$incoming_fetch" [ -z "$incoming_objs" ] || rm -rf "$incoming_objs" [ -z "$bang_log" ] || rm -f "$bang_log" + [ -z "$lockf" ] || rm -f "$lockf" } trap 'cleanup_exit' EXIT trap 'exit 129' HUP @@ -150,6 +162,7 @@ if [ -e .nofetch ]; then progress "x [$proj] update disabled (.nofetch exists)" exit 0 fi +lock_update progress "+ [$proj] update ($(date))" # Any pre-existing FETCH_HEAD from a previous fetch, failed or not, is garbage -- 2.11.4.GIT