diff options
author | Maxim Devaev <[email protected]> | 2022-06-19 22:30:29 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-06-19 22:30:29 +0300 |
commit | 4de5b40fb82ad5a5bb3e894e07102d85c842c229 (patch) | |
tree | fc2731557c16998ec9bc56a8eb71dc48157cea93 | |
parent | a70800323e4932d1885a210315af8c986bd2f7f9 (diff) |
better pstrun logging
-rw-r--r-- | kvmd/apps/pstrun/__init__.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/kvmd/apps/pstrun/__init__.py b/kvmd/apps/pstrun/__init__.py index c00dea4b..b5f154af 100644 --- a/kvmd/apps/pstrun/__init__.py +++ b/kvmd/apps/pstrun/__init__.py @@ -47,7 +47,7 @@ async def _run_cmd_ws(cmd: List[str], ws: aiohttp.ClientWebSocketResponse) -> in receive_task: Optional[asyncio.Task] = None proc_task: Optional[asyncio.Task] = None proc: Optional[asyncio.subprocess.Process] = None # pylint: disable=no-member - retval = 1 + try: # pylint: disable=too-many-nested-blocks while True: if receive_task is None: @@ -64,6 +64,8 @@ async def _run_cmd_ws(cmd: List[str], ws: aiohttp.ClientWebSocketResponse) -> in (event_type, event) = htserver.parse_ws_event(msg.data) if event_type == "storage_state": if event["data"]["write_allowed"] and proc is None: + logger.info("PST write is allowed: %s", event["data"]["path"]) + logger.info("Running the process ...") proc = (await asyncio.create_subprocess_exec( *cmd, preexec_fn=os.setpgrp, @@ -81,24 +83,24 @@ async def _run_cmd_ws(cmd: List[str], ws: aiohttp.ClientWebSocketResponse) -> in receive_task = None if proc_task in done: - assert proc is not None - assert proc.returncode is not None - logger.info("Process finished: returncode=%s", proc.returncode) break + except Exception: + logger.exception("Unhandled exception") - finally: - if receive_task: - receive_task.cancel() - if proc_task: - proc_task.cancel() - if proc is not None: - await aioproc.kill_process(proc, 1, logger) - assert proc.returncode is not None - retval = proc.returncode - return retval + if receive_task: + receive_task.cancel() + if proc_task: + proc_task.cancel() + if proc is not None: + await aioproc.kill_process(proc, 1, logger) + assert proc.returncode is not None + logger.info("Process finished: returncode=%d", proc.returncode) + return proc.returncode + return 1 async def _run_cmd(cmd: List[str], unix_path: str) -> None: + get_logger(0).info("Opening PST session ...") async with aiohttp.ClientSession( headers={"User-Agent": htclient.make_user_agent("KVMD-PSTRun")}, connector=aiohttp.UnixConnector(path=unix_path), |