use central deploy lock in git plugin

This commit is contained in:
Michael Hobbs
2016-06-17 16:10:51 -07:00
parent 4f8c1b64c9
commit fcefd4a29b
4 changed files with 30 additions and 43 deletions

View File

@@ -824,19 +824,25 @@ merge_dedupe_list() {
acquire_app_deploy_lock() {
declare desc="acquire advisory lock for use in git/tar deploys"
local APP="$1"; verify_app_name "$APP"
local LOCK_TYPE="${2:-waiting}"
local APP_DEPLOY_LOCK_FD="200"
local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
local APP_DEPLOY_LOCK_MSG="$APP is currently being deployed. Waiting..."
local LOCK_WAITING_MSG="$APP is currently being deployed. Waiting..."
local LOCK_FAILED_MSG="$APP is currently being deployed. Exiting..."
local SHOW_MSG=true
eval "exec $APP_DEPLOY_LOCK_FD>$APP_DEPLOY_LOCK_FILE"
while [[ $(flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null ; echo $?) -ne 0 ]]; do
if [[ "$SHOW_MSG" == "true" ]]; then
echo "$APP_DEPLOY_LOCK_MSG"
SHOW_MSG=false
fi
sleep 1
done
if [[ "$LOCK_TYPE" == "waiting" ]]; then
while [[ $(flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null ; echo $?) -ne 0 ]]; do
if [[ "$SHOW_MSG" == "true" ]]; then
echo "$LOCK_WAITING_MSG"
SHOW_MSG=false
fi
sleep 1
done
else
flock -n "$APP_DEPLOY_LOCK_FD" &>/dev/null || dokku_log_fail "$LOCK_FAILED_MSG"
fi
}
release_app_deploy_lock() {