aboutsummaryrefslogtreecommitdiff
path: root/service.py
diff options
context:
space:
mode:
Diffstat (limited to 'service.py')
-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