wip
This commit is contained in:
@@ -20,6 +20,8 @@ from openpilot.common.swaglog import cloudlog
|
|||||||
WATCHDOG_FN = "/dev/shm/wd_"
|
WATCHDOG_FN = "/dev/shm/wd_"
|
||||||
ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None
|
ENABLE_WATCHDOG = os.getenv("NO_WATCHDOG") is None
|
||||||
|
|
||||||
|
_log_dir = ""
|
||||||
|
|
||||||
def nativelauncher(pargs: list[str], cwd: str, name: str, log_path: str) -> None:
|
def nativelauncher(pargs: list[str], cwd: str, name: str, log_path: str) -> None:
|
||||||
os.environ['MANAGER_DAEMON'] = name
|
os.environ['MANAGER_DAEMON'] = name
|
||||||
with open(log_path, 'a') as log_file:
|
with open(log_path, 'a') as log_file:
|
||||||
@@ -71,7 +73,6 @@ class ManagerProcess(ABC):
|
|||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def restart(self) -> None:
|
def restart(self) -> None:
|
||||||
if self.proc is not None and self.proc.exitcode is not None:
|
if self.proc is not None and self.proc.exitcode is not None:
|
||||||
self.stop(sig=signal.SIGKILL, block=False)
|
self.stop(sig=signal.SIGKILL, block=False)
|
||||||
@@ -150,7 +151,9 @@ class NativeProcess(ManagerProcess):
|
|||||||
def prepare(self) -> None:
|
def prepare(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start(self, log_path: str) -> None:
|
def start(self) -> None:
|
||||||
|
global _log_dir
|
||||||
|
log_path = _log_dir+"/"+self.name+".log"
|
||||||
if self.shutting_down or self.proc is not None:
|
if self.shutting_down or self.proc is not None:
|
||||||
return
|
return
|
||||||
self.proc = Process(target=nativelauncher, args=(self.cmdline, os.path.join(BASEDIR, self.cwd), self.name, log_path))
|
self.proc = Process(target=nativelauncher, args=(self.cmdline, os.path.join(BASEDIR, self.cwd), self.name, log_path))
|
||||||
@@ -171,7 +174,9 @@ class PythonProcess(ManagerProcess):
|
|||||||
cloudlog.info(f"preimporting {self.module}")
|
cloudlog.info(f"preimporting {self.module}")
|
||||||
importlib.import_module(self.module)
|
importlib.import_module(self.module)
|
||||||
|
|
||||||
def start(self, log_path: str) -> None:
|
def start(self) -> None:
|
||||||
|
global _log_dir
|
||||||
|
log_path = _log_dir+"/"+self.name+".log"
|
||||||
if self.shutting_down or self.proc is not None:
|
if self.shutting_down or self.proc is not None:
|
||||||
return
|
return
|
||||||
self.proc = Process(name=self.name, target=launcher, args=(self.module, self.name, log_path))
|
self.proc = Process(name=self.name, target=launcher, args=(self.module, self.name, log_path))
|
||||||
@@ -196,7 +201,9 @@ class DaemonProcess(ManagerProcess):
|
|||||||
def prepare(self) -> None:
|
def prepare(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start(self, log_path: str) -> None:
|
def start(self) -> None:
|
||||||
|
global _log_dir
|
||||||
|
log_path = _log_dir+"/"+self.name+".log"
|
||||||
if self.params is None:
|
if self.params is None:
|
||||||
self.params = Params()
|
self.params = Params()
|
||||||
|
|
||||||
@@ -222,15 +229,16 @@ class DaemonProcess(ManagerProcess):
|
|||||||
|
|
||||||
|
|
||||||
def ensure_running(procs: ValuesView[ManagerProcess], started: bool, params=None, CP: car.CarParams=None, not_run: list[str] | None=None, log_dir: str = None) -> list[ManagerProcess]:
|
def ensure_running(procs: ValuesView[ManagerProcess], started: bool, params=None, CP: car.CarParams=None, not_run: list[str] | None=None, log_dir: str = None) -> list[ManagerProcess]:
|
||||||
|
global _log_dir
|
||||||
|
_log_dir = log_dir
|
||||||
if not_run is None:
|
if not_run is None:
|
||||||
not_run = []
|
not_run = []
|
||||||
|
|
||||||
running = []
|
running = []
|
||||||
for p in procs:
|
for p in procs:
|
||||||
log_path = log_dir+"/"+p.name+".log"
|
|
||||||
if p.enabled and p.name not in not_run and p.should_run(started, params, CP):
|
if p.enabled and p.name not in not_run and p.should_run(started, params, CP):
|
||||||
if p.proc is None or p.proc.exitcode is not None:
|
if p.proc is None or p.proc.exitcode is not None:
|
||||||
p.start(log_path)
|
p.start()
|
||||||
running.append(p)
|
running.append(p)
|
||||||
else:
|
else:
|
||||||
p.stop(block=False)
|
p.stop(block=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user