def _is_st2cluster_running(endpoints: list[tuple[str, str]]) -> bool:
    """Check for listening ports of st2auth, st2api, and st2stream services.

    This should not import the st2 code as it should be self-contained.
    """
    # TODO: Once each service gains a reliable health check endpoint, use that.
    # https://github.com/StackStorm/st2/issues/4020
    for host, port in endpoints:
        # based on https://stackoverflow.com/a/35370008/1134951
        with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
            # errno=0 means the connection succeeded
            if sock.connect_ex((host, int(port))) != 0:
                # failed to create a connection to the port.
                return False
    return True
Check for listening ports of st2auth, st2api, and st2stream services.

    This should not import the st2 code as it should be self-contained.
    
pants-plugins/uses_services/scripts/is_st2cluster_running.py