Skip to content

Commit

Permalink
Merge pull request #284 from DUNE-DAQ/plasorak/configurable-log-paths
Browse files Browse the repository at this point in the history
Use the log_path from the confguration
  • Loading branch information
PawelPlesniak authored Oct 25, 2024
2 parents ee961e3 + d6ff61d commit 2a64311
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/drunc/process_manager/oks_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)

Expand Down Expand Up @@ -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,
}
)

Expand Down Expand Up @@ -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,
}
)

Expand Down
24 changes: 21 additions & 3 deletions src/drunc/process_manager/process_manager_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,17 @@ async def _convert_oks_to_boot_request(
import os
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']
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']
Expand Down Expand Up @@ -112,10 +117,23 @@ 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 == './':
app_log_path = pwd

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: # 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: # 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)}.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(
Expand Down
12 changes: 12 additions & 0 deletions src/drunc/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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()}'
Expand Down

0 comments on commit 2a64311

Please sign in to comment.