diff --git a/CHANGES.md b/CHANGES.md index 8d87704e..f916911c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,9 @@ - fix Component.require_one raising a configuration error with strict=False - Adds command `./batou secrets decrypttostdout` to decrypt a secrets file to stdout. - Useful for integration with git diff using textconv, see documentation for installation instructions. +- The error message shown when a batou deployment fails to start due to another + deployment running at the same time, now correctly informs the user that + another deployment is running instead of showing a traceback. (#446) ## 2.5.0 (2024-09-04) diff --git a/src/batou/deploy.py b/src/batou/deploy.py index c8e62d1c..933cd85d 100644 --- a/src/batou/deploy.py +++ b/src/batou/deploy.py @@ -361,7 +361,7 @@ def main( else: ACTION = "DEPLOYMENT" SUCCESS_FORMAT = {"green": True} - with locked(".batou-lock"): + with locked(".batou-lock", exit_on_failure=True): deployment = Deployment( environment, platform, diff --git a/src/batou/utils.py b/src/batou/utils.py index 7ce3b2b5..bf1e6299 100644 --- a/src/batou/utils.py +++ b/src/batou/utils.py @@ -64,13 +64,20 @@ def flush(self): @contextlib.contextmanager -def locked(filename): +def locked(filename, exit_on_failure=False): # XXX can we make this not leave files around? with open(filename, "a+") as lockfile: try: fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: print("Could not acquire lock {}".format(filename), file=sys.stderr) + if exit_on_failure: + print( + "Another instance of batou is currently running and locked the lockfile.", + file=sys.stderr, + ) + print("Exiting.", file=sys.stderr) + sys.exit(1) raise RuntimeError( 'cannot create lock "%s": more than one instance running ' "concurrently?" % lockfile,