From 440d2d5255b46b2e5af4c6b8ae31915639d7966c Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Thu, 16 Mar 2017 15:18:42 -0700 Subject: [PATCH] Add lock file to Certbot --- certbot/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/certbot/main.py b/certbot/main.py index 1f247a7d6..b0f0d05e0 100644 --- a/certbot/main.py +++ b/certbot/main.py @@ -8,6 +8,7 @@ import sys import time import traceback +import fasteners import zope.component from acme import jose @@ -893,7 +894,15 @@ def main(cli_args=sys.argv[1:]): zope.component.provideUtility(report) atexit.register(report.atexit_print_messages) - return config.func(config, plugins) + lock = fasteners.InterProcessLock(constants.LOCK_FILE) + logger.debug("Attempting to acquire lock file %s", constants.LOCK_FILE) + if not lock.acquire(blocking=False): + raise errors.Error("Another instance of Certbot is already running.") + + try: + return config.func(config, plugins) + finally: + lock.release() if __name__ == "__main__":