ssh into hosts ol-web1 and ol-web2 and if filename is found in the docker_container openlibrary_web_1 then return its contents.
(
filename: str,
hosts=("ol-web1.us.archive.org", "ol-web2.us.archive.org"),
docker_container: str = "openlibrary_web_1",
)
| 23 | |
| 24 | |
| 25 | def get_web_error( |
| 26 | filename: str, |
| 27 | hosts=("ol-web1.us.archive.org", "ol-web2.us.archive.org"), |
| 28 | docker_container: str = "openlibrary_web_1", |
| 29 | ) -> str: |
| 30 | """ |
| 31 | ssh into hosts ol-web1 and ol-web2 and if filename is found in the |
| 32 | docker_container openlibrary_web_1 then return its contents. |
| 33 | """ |
| 34 | file_path = f"/var/log/openlibrary/ol-errors/{filename}" |
| 35 | for host in hosts: |
| 36 | cmd = f"ssh -A -t {host} 'docker exec -i {docker_container} cat {file_path}'" |
| 37 | try: |
| 38 | if output := subprocess.check_output(cmd, shell=True, text=True): |
| 39 | return output |
| 40 | except subprocess.CalledProcessError as e: |
| 41 | print(f"Error: {e!r}") |
| 42 | raise (e) |
| 43 | return f"Error: {file_path} was not found on {' or '.join(hosts)}." |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |