From 2a0b71dafaa337caa9ada40a8d95e28a21f81ed0 Mon Sep 17 00:00:00 2001 From: southerntofu Date: Wed, 29 Apr 2020 23:41:20 +0200 Subject: [PATCH] Better lockfile (don't complain when running multiple git-build) --- git-build.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/git-build.sh b/git-build.sh index 7473a65..071500b 100755 --- a/git-build.sh +++ b/git-build.sh @@ -8,6 +8,10 @@ BASEDIR="$HOME/.git-build" +# So scripts can know we're still running (for autoupdater) +echo "$BASHPID" > $BASEDIR/.LOCK + + # Default logging levels (error is always enabled) INFO=1 DEBUG=0 @@ -72,10 +76,6 @@ run() { (GITBUILDCONF="$CONFDIR" GITBUILDDIR="$BASEDIR" nohup $BASEDIR/$p_name $p_name > $BASEDIR/$p_name.log 2>&1) & } -# So scripts can know we're still running (for autoupdater) -# TODO needs to be reworked so multiple instances can run at the same time https://tildegit.org/southerntofu/git-build.sh/issues/13 -touch $BASEDIR/.LOCK - # Overriden by -f/--force to force rebuild when no update is available FORCE=0 @@ -214,5 +214,8 @@ for p_name in ${PROJECTS[*]}; do fi done -# TODO: better locking mechanism -rm $BASEDIR/.LOCK +# Check the PID in lockfile is still ours, we don't want +# to remove the lockfile if another git-build "owns" it +if [[ "$(cat $BASEDIR/.LOCK)" = "$BASHPID" ]]; then + rm $BASEDIR/.LOCK +fi