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,41 +201,44 @@ class DaemonProcess(ManagerProcess):
|
|||||||
def prepare(self) -> None:
|
def prepare(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start(self, log_path: str) -> None:
|
def start(self) -> None:
|
||||||
if self.params is None:
|
global _log_dir
|
||||||
self.params = Params()
|
log_path = _log_dir+"/"+self.name+".log"
|
||||||
|
if self.params is None:
|
||||||
|
self.params = Params()
|
||||||
|
|
||||||
pid = self.params.get(self.param_name, encoding='utf-8')
|
pid = self.params.get(self.param_name, encoding='utf-8')
|
||||||
if pid is not None:
|
if pid is not None:
|
||||||
try:
|
try:
|
||||||
os.kill(int(pid), 0)
|
os.kill(int(pid), 0)
|
||||||
return # Process is already running
|
return # Process is already running
|
||||||
except OSError:
|
except OSError:
|
||||||
pass # Process not running, continue to start it
|
pass # Process not running, continue to start it
|
||||||
|
|
||||||
log_file_path = os.path.join(log_path, f"{self.name}.log")
|
log_file_path = os.path.join(log_path, f"{self.name}.log")
|
||||||
self.params.put(self.param_name, str(self.proc.pid))
|
self.params.put(self.param_name, str(self.proc.pid))
|
||||||
cloudlog.info(f"starting daemon {self.name}")
|
cloudlog.info(f"starting daemon {self.name}")
|
||||||
self.proc = subprocess.Popen(['python', '-m', self.module],
|
self.proc = subprocess.Popen(['python', '-m', self.module],
|
||||||
stdin=open('/dev/null'),
|
stdin=open('/dev/null'),
|
||||||
stdout=open(log_file_path, 'a'),
|
stdout=open(log_file_path, 'a'),
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
preexec_fn=os.setpgrp)
|
preexec_fn=os.setpgrp)
|
||||||
|
|
||||||
def stop(self, retry=True, block=True, sig=None) -> None:
|
def stop(self, retry=True, block=True, sig=None) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
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