diff --git a/selfdrive/manager/process.py b/selfdrive/manager/process.py index a6612ac..a43309f 100755 --- a/selfdrive/manager/process.py +++ b/selfdrive/manager/process.py @@ -25,41 +25,68 @@ timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") _log_dir = f"/data/log2/{timestamp}" os.makedirs(_log_dir, exist_ok=True) -def launcher(proc: str, name: str, log_path: str) -> None: +# def launcher(proc: str, name: str, log_path: str) -> None: +# try: +# # import the process +# mod = importlib.import_module(proc) + +# global _log_dir +# log_path = os.path.join(_log_dir, f"{name}.log") + +# # rename the process +# setproctitle(proc) + +# # create new context since we forked +# messaging.context = messaging.Context() + +# # add daemon name tag to logs +# cloudlog.bind(daemon=name) +# sentry.set_tag("daemon", name) + +# # exec the process +# mod.main() +# except KeyboardInterrupt: +# cloudlog.warning(f"child {proc} got SIGINT") +# except Exception as e: +# # can't install the crash handler because sys.excepthook doesn't play nice +# # with threads, so catch it here. +# with open(log_path, 'a') as file: file.write(str(e)+"\n") +# sentry.capture_exception() +# raise + + +def launcher(proc: str, name: str) -> None: try: - # import the process - mod = importlib.import_module(proc) + # Import the process module + mod = importlib.import_module(proc) - # rename the process - setproctitle(proc) + # Path for logging + global _log_dir + log_path = os.path.join(_log_dir, f"{name}.log") - # create new context since we forked - messaging.context = messaging.Context() + # Rename the process + setproctitle(name) - # add daemon name tag to logs - cloudlog.bind(daemon=name) - sentry.set_tag("daemon", name) + # Create new context since we forked + messaging.context = messaging.Context() + + # Add daemon name tag to logs + cloudlog.bind(daemon=name) + sentry.set_tag("daemon", name) + + # Command construction + command = f"bash -c 'python -m {proc} 2>&1 | tee {log_path}'" + + # Execute the command + subprocess.run(command, shell=True, executable='/bin/bash', cwd=os.path.dirname(mod.__file__)) - # exec the process - mod.main() except KeyboardInterrupt: - cloudlog.warning(f"child {proc} got SIGINT") + cloudlog.warning(f"child {proc} got SIGINT") except Exception as e: - # can't install the crash handler because sys.excepthook doesn't play nice - # with threads, so catch it here. - with open(log_path, 'a') as file: file.write(str(e)+"\n") - sentry.capture_exception() - raise - -# def nativelauncher(pargs: list[str], cwd: str, name: str) -> None: -# os.environ['MANAGER_DAEMON'] = name - -# global _log_dir -# log_path = _log_dir+"/"+self.name+".log" - -# # exec the process -# os.chdir(cwd) -# os.execvp(pargs[0], pargs) + with open(log_path, 'a') as file: + file.write(str(e) + "\n") + sentry.capture_exception() + raise def nativelauncher(pargs: list[str], cwd: str, name: str) -> None: os.environ['MANAGER_DAEMON'] = name