aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Weth <git@jonathanweth.de>2020-07-29 17:39:11 +0200
committerJonathan Weth <git@jonathanweth.de>2020-07-29 17:39:11 +0200
commite65e64391fd885b36db9231727add5c6cfd9e6e3 (patch)
tree885c437da8ae3900de1704c76fa2e52d90dcdd90
parent403c0fda0929c19c2c5fa4e0e6ec25d4af441c95 (diff)
downloadRWA.Support.SessionService-e65e64391fd885b36db9231727add5c6cfd9e6e3.tar.gz
RWA.Support.SessionService-e65e64391fd885b36db9231727add5c6cfd9e6e3.tar.bz2
RWA.Support.SessionService-e65e64391fd885b36db9231727add5c6cfd9e6e3.zip
Create lock file if service is running
-rwxr-xr-xservice.py16
1 files changed, 16 insertions, 0 deletions
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