From e65e64391fd885b36db9231727add5c6cfd9e6e3 Mon Sep 17 00:00:00 2001 From: Jonathan Weth Date: Wed, 29 Jul 2020 17:39:11 +0200 Subject: Create lock file if service is running --- service.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/service.py b/service.py index 5e32f65..090cf6b 100755 --- a/service.py +++ b/service.py @@ -2,7 +2,9 @@ import argparse import json import logging +import os import signal +import tempfile import time from threading import Thread from typing import Union @@ -231,6 +233,17 @@ def str2bool(v: Union[str, bool, int]) -> bool: if __name__ == "__main__": + lock_file_path = os.path.join(tempfile.gettempdir(), "rwa-session-service.lock") + + # Check for lock file + if os.path.exists(lock_file_path): + logging.error("The service is already running.") + exit(1) + + # Create lock file + with open(lock_file_path, "w") as f: + f.write("lock") + parser = argparse.ArgumentParser(description="D-Bus Session Service for RWA") parser.add_argument( "-m", @@ -272,3 +285,6 @@ if __name__ == "__main__": signal.signal(signal.SIGINT, signal_handler) loop.run() + + logging.info("Remove lock file ...") + os.remove(lock_file_path) \ No newline at end of file -- cgit v1.2.3