Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the log_path from the confguration #284

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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()}'
Expand Down