# .agent/tools/port_checker.py import sys import socket import urllib.request import time def check_service(url_or_port, retries=5): """Verifica se um serviço local está respondendo.""" target = url_or_port if target.isdigit(): target = f"http://localhost:{target}" print(f"🩺 Checando saúde de: {target}...") for i in range(retries): try: code = urllib.request.urlopen(target, timeout=2).getcode() if code == 200: return f"✅ Serviço UP! Status: {code}" except Exception as e: print(f" Tentativa {i+1}/{retries}: Aguardando serviço... ({e})") time.sleep(2) return f"❌ Serviço indisponível após {retries} tentativas." if __name__ == "__main__": if len(sys.argv) < 2: print("Uso: python port_checker.py 3000") else: print(check_service(sys.argv[1]))