#!/usr/bin/env python3 import subprocess import os import sys PRO_PATH = "/platform/LAS/" LOGFILE = PRO_PATH + "LAS.log" PIDFILE = PRO_PATH + "LAS.pid" def is_running(pid): try: os.kill(pid, 0) return True except OSError: return False def start(): if os.path.exists(PIDFILE): with open(PIDFILE, "r") as f: pid = int(f.read()) if is_running(pid): print(f"LAS is already running with PID {pid}") return else: print("Found stale PID file. Cleaning up.") os.remove(PIDFILE) with open(LOGFILE, "a") as log: process = subprocess.Popen( [sys.executable, "LAS.py"], stdout=log, stderr=log, stdin=subprocess.DEVNULL, close_fds=True, ) with open(PIDFILE, "w") as f: f.write(str(process.pid)) print(f"LAS started with PID {process.pid}") if __name__ == "__main__": start()