Skip to content

Commit

Permalink
Merge pull request #1282 from OCR-D/mets-server-rm-socket
Browse files Browse the repository at this point in the history
deployer: Remove any pre-existing socket file before starting the server (again)
  • Loading branch information
kba authored Oct 2, 2024
2 parents 7a3be1e + 9a71d04 commit 8b6a49c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ocrd/mets_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def kill_process(mets_server_pid: int):
def shutdown(self):
if self.is_uds:
if Path(self.url).exists():
self.log.debug(f'UDS socket {self.url} still exists, removing it')
self.log.warning(f"Due to a server shutdown, removing the existing UDS socket file: {self.url}")
Path(self.url).unlink()
# os._exit because uvicorn catches SystemExit raised by sys.exit
_exit(0)
Expand Down
8 changes: 8 additions & 0 deletions src/ocrd_network/runtime_data/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def start_uds_mets_server(self, ws_dir_path: str) -> Path:
if is_mets_server_running(mets_server_url=str(mets_server_url)):
self.log.debug(f"The UDS mets server for {ws_dir_path} is already started: {mets_server_url}")
return mets_server_url
elif Path(mets_server_url).is_socket():
self.log.warning(
f"The UDS mets server for {ws_dir_path} is not running but the socket file exists: {mets_server_url}."
"Removing to avoid any weird behavior before starting the server.")
Path(mets_server_url).unlink()
self.log.info(f"Starting UDS mets server: {mets_server_url}")
pid = OcrdMetsServer.create_process(mets_server_url=mets_server_url, ws_dir_path=ws_dir_path, log_file=log_file)
self.mets_servers[mets_server_url] = pid
Expand All @@ -160,6 +165,9 @@ def stop_uds_mets_server(self, mets_server_url: str, stop_with_pid: bool = False
raise Exception(message)
mets_server_pid = self.mets_servers[Path(mets_server_url)]
OcrdMetsServer.kill_process(mets_server_pid=mets_server_pid)
if Path(mets_server_url).exists():
self.log.warning(f"Deployer is removing the existing UDS socket file: {mets_server_url}")
Path(mets_server_url).unlink()
return
# TODO: Reconsider this again
# Not having this sleep here causes connection errors
Expand Down

0 comments on commit 8b6a49c

Please sign in to comment.