diff options
author | Jonathan Weth <git@jonathanweth.de> | 2020-07-30 16:09:10 +0200 |
---|---|---|
committer | Jonathan Weth <git@jonathanweth.de> | 2020-07-30 16:09:10 +0200 |
commit | 4747c039084167143b9c567c9b4a69efef28c1f1 (patch) | |
tree | e0620daa73bed49d1bc82fbce7894f52da39ba55 /lock.py | |
parent | 367a88ffa591219f6e7028a6a544e521531dee8f (diff) | |
download | RWA.Support.SessionService-4747c039084167143b9c567c9b4a69efef28c1f1.tar.gz RWA.Support.SessionService-4747c039084167143b9c567c9b4a69efef28c1f1.tar.bz2 RWA.Support.SessionService-4747c039084167143b9c567c9b4a69efef28c1f1.zip |
Stop service if lock file was removed
Diffstat (limited to 'lock.py')
-rw-r--r-- | lock.py | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,25 @@ +import os +import tempfile + +lock_dir_path = os.path.join(tempfile.gettempdir(), "rwa-session-service") +lock_file_path = os.path.join(lock_dir_path, "rwa-session-service.lock") + + +def lock(): + """Create lock file.""" + os.makedirs(lock_dir_path, exist_ok=True) + with open(lock_file_path, "w") as f: + f.write("lock") + + +def is_locked(): + """Check if the lock file exists.""" + return os.path.exists(lock_file_path) + + +def unlock(): + """Remove the lock file.""" + try: + os.remove(lock_file_path) + except FileNotFoundError: + pass |