From 46f4a8acb6e86eca38cec85f990410d1e34709c3 Mon Sep 17 00:00:00 2001 From: Pierre Lasorak Date: Wed, 23 Oct 2024 06:44:05 -0500 Subject: [PATCH 1/3] add a log path from the confguration. Check it exists if the host where the app is meant to run is localhost --- src/drunc/process_manager/oks_parser.py | 9 ++++++--- .../process_manager/process_manager_driver.py | 20 ++++++++++++++++--- src/drunc/utils/utils.py | 12 +++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/drunc/process_manager/oks_parser.py b/src/drunc/process_manager/oks_parser.py index 167d943e..85917ed6 100644 --- a/src/drunc/process_manager/oks_parser.py +++ b/src/drunc/process_manager/oks_parser.py @@ -75,7 +75,8 @@ def collect_apps(db, session, segment, env:Dict[str,str]) -> List[Dict]: "restriction": host, "host": host, "env": rc_env, - "tree_id": pmch.create_id(controller, segment) + "tree_id": pmch.create_id(controller, segment), + "log_path": controller.log_path, } ) @@ -116,7 +117,8 @@ def collect_apps(db, session, segment, env:Dict[str,str]) -> List[Dict]: "restriction": host, "host": host, "env": app_env, - "tree_id": pmch.create_id(app) + "tree_id": pmch.create_id(app), + "log_path": app.log_path, } ) @@ -168,7 +170,8 @@ def collect_infra_apps(session, env:Dict[str, str]) -> List[Dict]: "restriction": host, "host": host, "env": app_env, - "tree_id": pmch.create_id(app) + "tree_id": pmch.create_id(app), + "log_path": app.log_path, } ) diff --git a/src/drunc/process_manager/process_manager_driver.py b/src/drunc/process_manager/process_manager_driver.py index 442bae96..062beb13 100644 --- a/src/drunc/process_manager/process_manager_driver.py +++ b/src/drunc/process_manager/process_manager_driver.py @@ -79,12 +79,15 @@ async def _convert_oks_to_boot_request( import os pwd = os.getcwd() + session_log_path = session_dal.log_path + for app in apps: host = app['restriction'] name = app['name'] exe = app['type'] args = app['args'] env = app['env'] + app_log_path = app['log_path'] env['DUNE_DAQ_BASE_RELEASE'] = os.getenv("DUNE_DAQ_BASE_RELEASE") env['SPACK_RELEASES_DIR'] = os.getenv("SPACK_RELEASES_DIR") tree_id = app['tree_id'] @@ -112,10 +115,21 @@ async def _convert_oks_to_boot_request( args=args)) from drunc.utils.utils import now_str - if override_logs: - log_path = f'{pwd}/log_{user}_{session}_{name}.log' + + if app_log_path: + log_path = f'{app_log_path}/log_{user}_{session}_{name}_{now_str(True)}.txt' + elif session_log_path: + log_path = f'{session_log_path}/log_{user}_{session}_{name}_{now_str(True)}.txt' + elif override_logs: + log_path = f'{pwd}/log_{user}_{session}_{name}.txt' else: - log_path = f'{pwd}/log_{user}_{session}_{name}_{now_str(True)}.log' + log_path = f'{pwd}/log_{user}_{session}_{name}_{now_str(True)}.txt' + + import os, socket + from drunc.utils.utils import host_is_local + if host_is_local(host) and not os.path.exists(os.path.dirname(log_path)): + raise DruncShellException(f"Log path {log_path} does not exist.") + self._log.debug(f'{name}\'s env:\n{env}') breq = BootRequest( process_description = ProcessDescription( diff --git a/src/drunc/utils/utils.py b/src/drunc/utils/utils.py index 64bf1253..650fbb80 100644 --- a/src/drunc/utils/utils.py +++ b/src/drunc/utils/utils.py @@ -183,6 +183,18 @@ def resolve_localhost_and_127_ip_to_network_ip(address): return address +def host_is_local(host): + from socket import gethostname, gethostbyname + + if host in ['localhost', '0.0.0.0', gethostname(), gethostbyname(gethostname())]: + return True + + if host.startswith('127.'): + return True + + return False + + def pid_info_str(): import os return f'Parent\'s PID: {os.getppid()} | This PID: {os.getpid()}' From 62fe7503aef95c4a7de0a0292ccd4b4dad2335d8 Mon Sep 17 00:00:00 2001 From: Pierre Lasorak Date: Fri, 25 Oct 2024 13:06:05 +0200 Subject: [PATCH 2/3] parse ./ --- src/drunc/process_manager/process_manager_driver.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/drunc/process_manager/process_manager_driver.py b/src/drunc/process_manager/process_manager_driver.py index 062beb13..ffb0099d 100644 --- a/src/drunc/process_manager/process_manager_driver.py +++ b/src/drunc/process_manager/process_manager_driver.py @@ -115,12 +115,14 @@ async def _convert_oks_to_boot_request( args=args)) from drunc.utils.utils import now_str + if app_log_path == './': + app_log_path = pwd - if app_log_path: + if app_log_path: # if the user wants to write to a specific path, we never override log_path = f'{app_log_path}/log_{user}_{session}_{name}_{now_str(True)}.txt' - elif session_log_path: + elif session_log_path: # if the user wants the session to write to a specific path, we never override log_path = f'{session_log_path}/log_{user}_{session}_{name}_{now_str(True)}.txt' - elif override_logs: + elif override_logs: # else we check for the override flag log_path = f'{pwd}/log_{user}_{session}_{name}.txt' else: log_path = f'{pwd}/log_{user}_{session}_{name}_{now_str(True)}.txt' From d6ff61d00b2843b35909e8722161e9d2adb7d550 Mon Sep 17 00:00:00 2001 From: Pierre Lasorak Date: Fri, 25 Oct 2024 14:16:38 +0200 Subject: [PATCH 3/3] parse sessionlog path too --- src/drunc/process_manager/process_manager_driver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/drunc/process_manager/process_manager_driver.py b/src/drunc/process_manager/process_manager_driver.py index ffb0099d..d68dba32 100644 --- a/src/drunc/process_manager/process_manager_driver.py +++ b/src/drunc/process_manager/process_manager_driver.py @@ -80,6 +80,8 @@ async def _convert_oks_to_boot_request( pwd = os.getcwd() session_log_path = session_dal.log_path + if session_log_path == './': + session_log_path = pwd for app in apps: host = app['restriction']