#!/usr/bin/env bash # Boots are racy for the gateway containers (both root-caused 2026-08-31): # - prod binds :4000/:9090 to the tailscale IP; if dockerd wins the race over # tailscaled, the bind fails and docker NEVER retries failed starts; # - live-restore can drop a container's network endpoint across a boot, # leaving it started with the host resolver (gateway-db unresolvable, # crash loop). A plain `docker start` does NOT reattach the endpoint. # Waits for the tailscale IP, then recreates any lane not actually serving. # Idempotent; recreating is safe at boot time (nothing in flight). set -u GW_DIR=/home/reachableceo/projects/ukrrs/gateway TS_IP=100.101.187.119 for _ in $(seq 1 60); do /usr/sbin/ip -o addr | grep -q "$TS_IP/" && break sleep 2 done ensure_lane() { # name host:port project compose_file local name=$1 hostport=$2 project=$3 file=$4 if timeout 5 bash -c "/dev/null; then echo "$name: serving on $hostport" return 0 fi echo "$name: NOT serving on $hostport; recreating" docker compose -p "$project" -f "$GW_DIR/$file" up -d --no-deps --force-recreate gateway } ensure_lane prod "$TS_IP:4000" mopac-gateway docker-compose.yml ensure_lane beta "127.0.0.1:4002" mopac-gateway-beta compose.beta.yaml exit 0