2024-05-22 11:54:29 -05:00
|
|
|
import os
|
|
|
|
|
import sys
|
2025-10-06 17:09:40 +01:00
|
|
|
from ipaddress import ip_address
|
2024-05-22 11:54:29 -05:00
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
port = os.getenv("IMMICH_PORT", 3003)
|
2025-07-15 00:08:29 +02:00
|
|
|
host = os.getenv("IMMICH_HOST", "0.0.0.0")
|
|
|
|
|
|
2025-10-07 12:24:23 -04:00
|
|
|
|
|
|
|
|
def is_ipv6(host: str) -> bool:
|
|
|
|
|
try:
|
|
|
|
|
return ip_address(host).version == 6
|
|
|
|
|
except ValueError:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
2025-07-15 00:08:29 +02:00
|
|
|
host = "localhost" if host == "0.0.0.0" else host
|
2025-10-07 12:24:23 -04:00
|
|
|
host = f"[{host}]" if is_ipv6(host) else host
|
2024-05-22 11:54:29 -05:00
|
|
|
|
|
|
|
|
try:
|
2025-07-15 00:08:29 +02:00
|
|
|
response = requests.get(f"http://{host}:{port}/ping", timeout=2)
|
2024-05-22 11:54:29 -05:00
|
|
|
if response.status_code == 200:
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
except requests.RequestException:
|
|
|
|
|
sys.exit(1)
|