Skip to content

Commit

Permalink
add a log path from the confguration. Check it exists if the host whe…
Browse files Browse the repository at this point in the history
…re the app is meant to run is localhost
  • Loading branch information
plasorak committed Oct 23, 2024
1 parent 65e2e08 commit 46f4a8a
Show file tree
Hide file tree
Showing 3 changed files with 35 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
20 changes: 17 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,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']
Expand Down Expand Up @@ -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(
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

0 comments on commit 46f4a8a

Please sign in to comment.