wip
This commit is contained in:
@@ -25,42 +25,69 @@ 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
|
||||
# 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
|
||||
# Rename the process
|
||||
setproctitle(name)
|
||||
|
||||
# Create new context since we forked
|
||||
messaging.context = messaging.Context()
|
||||
|
||||
# add daemon name tag to logs
|
||||
# Add daemon name tag to logs
|
||||
cloudlog.bind(daemon=name)
|
||||
sentry.set_tag("daemon", name)
|
||||
|
||||
# exec the process
|
||||
mod.main()
|
||||
# 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__))
|
||||
|
||||
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")
|
||||
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)
|
||||
|
||||
def nativelauncher(pargs: list[str], cwd: str, name: str) -> None:
|
||||
os.environ['MANAGER_DAEMON'] = name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user