I would recommend using run-one command - much simpler than dealing with the locks. From the docs:
run-one is a wrapper script that runs no more than one unique instance of some command with a unique set of arguments. This is often useful with cronjobs, when you want no more than one copy running at a time.
run-this-one is exactly like run-one, except that it will use pgrep and kill to find and kill any running processes owned by the user
and matching the target commands and arguments. Note that run-this-one will block while trying to kill matching processes, until all matching
processes are dead.
run-one-constantly operates exactly like run-one except that it
respawns "COMMAND [ARGS]" any time COMMAND exits (zero or non-zero).
keep-one-running is an alias for run-one-constantly.
run-one-until-success operates exactly like run-one-constantly except
that it respawns "COMMAND [ARGS]" until COMMAND exits successfully (ie,
exits zero).
run-one-until-failure operates exactly like run-one-constantly except
that it respawns "COMMAND [ARGS]" until COMMAND exits with failure (ie,
exits non-zero).