#!/usr/bin/env bash # Quayel agent bootstrap — install Docker, nixpacks, dirs, then compose up the edge proxy # + qagent (public image: quayel/agent-agent-api). Edge proxy (GATEWAY_ENGINE): # quayel Quayel Gateway (quayel/quayel-gateway): the agent writes /etc/quayel/gateway/config.json # apisix etcd + APISIX (admin API) # Engine: GATEWAY_ENGINE env > gateway_engine in the agent config (when set) > quayel. # Every install and update lands on quayel, including servers now on APISIX; set # gateway_engine to "apisix" in the agent config to keep or move every server back. # # Usage: # sudo SERVER_TOKEN=... ./install.sh # curl -fsSL | sudo bash -s -- # # Image and download locations come from the global agent config # (GET $QUAYEL_METRICS_HOST/api/v1/agent/config), so moving them needs no script edit. # Env vars (GATEWAY_ENGINE, QAGENT_IMAGE, QUAYEL_GATEWAY_IMAGE, ETCD_IMAGE, APISIX_IMAGE, # NIXPACKS_INSTALL_URL) still win. The agent image is the exception: it is always # quayel/agent-agent-api:latest unless QAGENT_IMAGE is set. # # Bump VERSION whenever this script's behavior/config changes (written to /etc/quayel/install_version). VERSION=1.3.4 set -euo pipefail # The dashboard update runs this under systemd-run, which sets no HOME and a bare PATH. export HOME="${HOME:-/root}" export PATH="${PATH:-/usr/bin:/bin}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:${HOME}/.local/bin:${HOME}/.nix-profile/bin" INSTALL_DIR="${QUAYEL_INSTALL_DIR:-/opt/quayel}" NETWORK_NAME="${QUAYEL_NETWORK:-quayel-main-network}" COMPOSE_PROJECT="${COMPOSE_PROJECT_NAME:-quayel}" QUAYEL_METRICS_HOST="${QUAYEL_METRICS_HOST:-}" QAGENT_IMAGE_OVERRIDE="${QAGENT_IMAGE:-}" ETCD_IMAGE_OVERRIDE="${ETCD_IMAGE:-}" APISIX_IMAGE_OVERRIDE="${APISIX_IMAGE:-}" GATEWAY_IMAGE_OVERRIDE="${QUAYEL_GATEWAY_IMAGE:-}" GATEWAY_ENGINE_OVERRIDE="${GATEWAY_ENGINE:-}" NIXPACKS_INSTALL_URL_OVERRIDE="${NIXPACKS_INSTALL_URL:-}" log() { printf '\n==> %s\n' "$*"; } ok() { printf ' OK %s\n' "$*"; } warn() { printf ' WARN %s\n' "$*" >&2; } die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } need_root() { if [[ "$(id -u)" -ne 0 ]]; then die "run as root (sudo ./install.sh)" fi } detect_os() { if [[ -f /etc/os-release ]]; then # Subshell: os-release defines VERSION, which would overwrite this script's VERSION. OS_ID="$(. /etc/os-release && printf '%s' "${ID:-}")" OS_VER="$(. /etc/os-release && printf '%s' "${VERSION_CODENAME:-}")" else die "unsupported OS (need /etc/os-release)" fi case "$OS_ID" in ubuntu|debian) ;; *) warn "untested OS '$OS_ID' — continuing with Debian-style packages" ;; esac } install_host_packages() { log "Installing host packages" export DEBIAN_FRONTEND=noninteractive apt-get update -qq apt-get install -y -qq \ ca-certificates curl gnupg lsb-release \ openssl jq util-linux \ >/dev/null ok "base packages" } load_remote_config() { log "Loading Quayel agent config" if [[ -z "$QUAYEL_METRICS_HOST" && -f "${INSTALL_DIR}/.env" ]]; then QUAYEL_METRICS_HOST="$(sed -n 's/^QUAYEL_METRICS_HOST=//p' "${INSTALL_DIR}/.env" | tail -1)" fi QUAYEL_METRICS_HOST="${QUAYEL_METRICS_HOST:-https://agent-api.quayel.com}" local url="${QUAYEL_METRICS_HOST%/}/api/v1/agent/config" body="" local remote_etcd="" remote_apisix="" remote_nixpacks="" remote_gateway="" remote_engine="" body="$(curl -fsSL --max-time 15 "$url" 2>/dev/null || true)" if [[ -n "$body" ]] && jq -e '.config | type == "object"' >/dev/null 2>&1 <<<"$body"; then remote_etcd="$(jq -r '.config.etcd_image // empty' <<<"$body")" remote_apisix="$(jq -r '.config.apisix_image // empty' <<<"$body")" remote_nixpacks="$(jq -r '.config.nixpacks_install_url // empty' <<<"$body")" remote_gateway="$(jq -r '.config.gateway_image // empty' <<<"$body")" remote_engine="$(jq -r '.config.gateway_engine // empty' <<<"$body")" ok "config from ${url}" else warn "could not load ${url} — using built-in defaults" fi # The agent always tracks :latest; only an explicit QAGENT_IMAGE pins another tag. # agent_image from the agent config is ignored, so a stale pin there cannot hold servers back. QAGENT_IMAGE="${QAGENT_IMAGE_OVERRIDE:-quayel/agent-agent-api:latest}" ETCD_IMAGE="${ETCD_IMAGE_OVERRIDE:-${remote_etcd:-quay.io/coreos/etcd:v3.5.16}}" APISIX_IMAGE="${APISIX_IMAGE_OVERRIDE:-${remote_apisix:-apache/apisix:3.11.0-debian}}" QUAYEL_GATEWAY_IMAGE="${GATEWAY_IMAGE_OVERRIDE:-${remote_gateway:-quayel/quayel-gateway:latest}}" NIXPACKS_INSTALL_URL="${NIXPACKS_INSTALL_URL_OVERRIDE:-${remote_nixpacks:-https://nixpacks.com/install.sh}}" GATEWAY_ENGINE="${GATEWAY_ENGINE_OVERRIDE:-${remote_engine:-quayel}}" case "$GATEWAY_ENGINE" in quayel|apisix) ;; *) warn "unknown gateway engine '${GATEWAY_ENGINE}' — using quayel"; GATEWAY_ENGINE=quayel ;; esac export QUAYEL_METRICS_HOST QAGENT_IMAGE ETCD_IMAGE APISIX_IMAGE QUAYEL_GATEWAY_IMAGE GATEWAY_ENGINE NIXPACKS_INSTALL_URL if [[ "$GATEWAY_ENGINE" == quayel ]]; then ok "engine=quayel qagent=${QAGENT_IMAGE} gateway=${QUAYEL_GATEWAY_IMAGE}" else ok "engine=apisix qagent=${QAGENT_IMAGE} etcd=${ETCD_IMAGE} apisix=${APISIX_IMAGE}" fi } # Kernel settings for the gateway (many connections) and for database templates: # Elasticsearch/OpenSearch refuse to start below vm.max_map_count 262144. tune_host() { log "Host tuning (/etc/sysctl.d/99-quayel.conf)" local map_count map_count="$(sysctl -n vm.max_map_count 2>/dev/null || echo 0)" (( map_count < 262144 )) && map_count=262144 cat > /etc/sysctl.d/99-quayel.conf </dev/null 2>&1; then ok "vm.max_map_count=${map_count}, network backlog raised" else warn "some sysctl settings were not applied (container/VPS kernel?) — continuing" fi } install_docker() { if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then ok "Docker already installed ($(docker --version))" return fi log "Installing Docker Engine + Compose plugin" install -m 0755 -d /etc/apt/keyrings if [[ ! -f /etc/apt/keyrings/docker.asc ]]; then curl -fsSL "https://download.docker.com/linux/${OS_ID}/gpg" -o /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.asc fi arch="$(dpkg --print-architecture)" echo "deb [arch=${arch} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/${OS_ID} ${OS_VER} stable" \ > /etc/apt/sources.list.d/docker.list apt-get update -qq apt-get install -y -qq \ docker-ce docker-ce-cli containerd.io \ docker-buildx-plugin docker-compose-plugin \ >/dev/null systemctl enable --now docker ok "Docker $(docker --version)" } install_nixpacks() { if command -v nixpacks >/dev/null 2>&1; then ok "nixpacks already installed ($(nixpacks --version 2>/dev/null | head -1))" return fi log "Installing nixpacks" curl -fsSL "$NIXPACKS_INSTALL_URL" | bash -s -- -y if [[ ! -x /usr/local/bin/nixpacks && -x "$HOME/.local/bin/nixpacks" ]]; then ln -sf "$HOME/.local/bin/nixpacks" /usr/local/bin/nixpacks fi command -v nixpacks >/dev/null 2>&1 || die "nixpacks install failed" ok "nixpacks $(nixpacks --version 2>/dev/null | head -1)" } ensure_swarm_and_network() { log "Docker Swarm + network ${NETWORK_NAME}" if ! docker info 2>/dev/null | grep -q 'Swarm: active'; then ADV="$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="src"){print $(i+1); exit}}' || true)" if [[ -n "${ADV}" ]]; then docker swarm init --advertise-addr "$ADV" >/dev/null || true else docker swarm init >/dev/null || true fi fi if docker info 2>/dev/null | grep -q 'Swarm: active'; then ok "swarm active" else warn "swarm not active — overlay network may fail; trying anyway" fi if docker network inspect "$NETWORK_NAME" >/dev/null 2>&1; then ok "network ${NETWORK_NAME} exists" else docker network create --driver overlay --attachable "$NETWORK_NAME" >/dev/null ok "created overlay network ${NETWORK_NAME}" fi } write_apisix_config() { cat > /etc/quayel/apisix/config.yaml <<'YAML' apisix: node_listen: - 9080 enable_admin: true enable_control: true # Never reveal gateway internals to clients (no upstream status, no APISIX version). show_upstream_status_in_response_header: false enable_server_tokens: false enable_http2: true dns_resolver: - "127.0.0.11" dns_resolver_valid: 5 resolver_timeout: 3 ssl: enable: true listen: - port: 9443 fallback_sni: "quayel-default" # Cache zones live under apisix.proxy_cache; plugin_attr.proxy-cache is ignored. proxy_cache: cache_ttl: 10s zones: - name: disk_cache_one memory_size: 50m disk_size: 1G disk_path: /var/lib/apisix/cache cache_levels: "1:2" - name: memory_cache memory_size: 256m discovery: dns: servers: - "127.0.0.11:53" plugin_attr: prometheus: export_uri: /apisix/prometheus/metrics metric_prefix: apisix_ enable_export_server: true export_addr: ip: 0.0.0.0 port: 9091 metrics: http_status: extra_labels: - cache_status: $sent_http_quayel_cache_status - upstream_cache: $upstream_cache_status deployment: admin: # Admin is never published on the host; only the Docker network may reach it. # install.sh narrows the private ranges to the quayel-main-network subnet. allow_admin: - 127.0.0.0/8 - 10.0.0.0/8 - 172.16.0.0/12 - 192.168.0.0/16 admin_key: - name: admin # Replaced per server by install.sh (/etc/quayel/apisix_admin_key). key: quayel-apisix-admin-key role: admin etcd: host: - "http://etcd:2379" prefix: "/apisix" timeout: 30 nginx_config: enable_cpu_affinity: true worker_rlimit_nofile: 65535 event: worker_connections: 32768 http: enable_access_log: false upstream: keepalive: 500 keepalive_requests: 100000 keepalive_timeout: 60s http_configuration_snippet: | lua_shared_dict quayel_analytics 64m; keepalive_requests 100000; client_header_buffer_size 4k; large_client_header_buffers 4 8k; tcp_nodelay on; tcp_nopush on; YAML } write_compose_file() { if [[ "$GATEWAY_ENGINE" == quayel ]]; then write_gateway_compose_file else write_apisix_compose_file fi } # Quayel Gateway: the agent writes /etc/quayel/gateway/config.json, the gateway hot-reloads it. # The directory is mounted (not the file) so the agent's atomic renames are seen. write_gateway_compose_file() { cat > "${INSTALL_DIR}/docker-compose.yml" <<'YAML' services: quayel-gateway: image: ${QUAYEL_GATEWAY_IMAGE:-quayel/quayel-gateway:latest} container_name: quayel-gateway restart: unless-stopped ulimits: nofile: soft: 65535 hard: 65535 ports: - "80:80" - "443:443" environment: RUST_LOG: ${RUST_LOG:-info} QG_CLICKHOUSE_PASSWORD: ${QUAYEL_GATEWAY_CLICKHOUSE_PASSWORD:-} volumes: - /etc/quayel/gateway:/etc/quayel-gateway:ro - /var/lib/quayel/certs:/var/lib/quayel/certs - /var/log/quayel/gateway:/var/log/quayel/gateway stop_grace_period: 15s networks: - quayel-main-network quayel-agent-api: image: ${QAGENT_IMAGE:-quayel/agent-agent-api:latest} container_name: quayel-agent-api restart: unless-stopped privileged: true pid: host environment: NODE_ENV: production SERVER_TOKEN: ${SERVER_TOKEN:-} GATEWAY_ENGINE: quayel QUAYEL_GATEWAY_CLICKHOUSE_URL: ${QUAYEL_GATEWAY_CLICKHOUSE_URL:-} QUAYEL_GATEWAY_CLICKHOUSE_DATABASE: ${QUAYEL_GATEWAY_CLICKHOUSE_DATABASE:-quayel_analytics} QUAYEL_GATEWAY_CLICKHOUSE_USER: ${QUAYEL_GATEWAY_CLICKHOUSE_USER:-} QUAYEL_METRICS_HOST: ${QUAYEL_METRICS_HOST:-https://agent-api.quayel.com} QAGENT_IMAGE: ${QAGENT_IMAGE:-quayel/agent-agent-api:latest} # Empty = use install_script_url from the global agent config. INSTALL_SCRIPT_URL: ${INSTALL_SCRIPT_URL:-} UPDATE_CHECK_INTERVAL_MS: ${UPDATE_CHECK_INTERVAL_MS:-} UPDATE_CHECK_DISABLED: ${UPDATE_CHECK_DISABLED:-} ANALYTICS_CLICKHOUSE_URL: ${ANALYTICS_CLICKHOUSE_URL:-} ANALYTICS_CLICKHOUSE_DATABASE: ${ANALYTICS_CLICKHOUSE_DATABASE:-quayel_analytics} ANALYTICS_CLICKHOUSE_ENABLED: ${ANALYTICS_CLICKHOUSE_ENABLED:-1} volumes: - /etc/quayel:/etc/quayel - /var/log/quayel:/var/log/quayel - /var/lib/quayel:/var/lib/quayel - /var/run/docker.sock:/var/run/docker.sock networks: - quayel-main-network networks: quayel-main-network: external: true YAML } # Until the agent writes the real config. listen + metrics are only read when the gateway # starts, so the seed already has them; routes arrive by hot reload. seed_gateway_config() { local cfg=/etc/quayel/gateway/config.json [[ -s "$cfg" ]] && return 0 cat > "$cfg" <<'JSON' { "gateway_id": "quayel", "gateway_name": "quayel", "server_name": "quayel", "config_version": "seed", "listen": { "http": "0.0.0.0:80", "https": "0.0.0.0:443" }, "metrics": { "listen": "0.0.0.0:9464", "path": "/metrics", "max_hosts": 1000 }, "plugins": { "load_balancer": { "enabled": true, "load_balancers": [] } } } JSON ok "seeded ${cfg}" } write_apisix_compose_file() { # Embedded compose — always written so a pasted install.sh is self-contained. # Never set ETCD_DATA_DIR / ALLOW_NONE_AUTHENTICATION — conflicts with --data-dir (etcd fatal). cat > "${INSTALL_DIR}/docker-compose.yml" <<'YAML' services: etcd: image: ${ETCD_IMAGE:-quay.io/coreos/etcd:v3.5.16} container_name: etcd restart: unless-stopped command: - /usr/local/bin/etcd - --data-dir=/etcd-data - --name=etcd0 - --listen-client-urls=http://0.0.0.0:2379 - --advertise-client-urls=http://etcd:2379 - --listen-peer-urls=http://0.0.0.0:2380 - --initial-advertise-peer-urls=http://etcd:2380 - --initial-cluster=etcd0=http://etcd:2380 - --initial-cluster-token=quayel-etcd - --initial-cluster-state=new volumes: - etcd-data:/etcd-data networks: - quayel-main-network healthcheck: test: ["CMD", "etcdctl", "endpoint", "health"] interval: 5s timeout: 5s retries: 12 start_period: 10s apisix: image: ${APISIX_IMAGE:-apache/apisix:3.11.0-debian} container_name: apisix restart: unless-stopped ulimits: nofile: soft: 65535 hard: 65535 depends_on: etcd: condition: service_healthy ports: - "80:9080" - "443:9443" volumes: - /etc/quayel/apisix/config.yaml:/usr/local/apisix/conf/config.yaml:ro - /var/lib/quayel/apisix-cache:/var/lib/apisix/cache networks: - quayel-main-network quayel-agent-api: image: ${QAGENT_IMAGE:-quayel/agent-agent-api:latest} container_name: quayel-agent-api restart: unless-stopped privileged: true pid: host depends_on: - apisix environment: NODE_ENV: production SERVER_TOKEN: ${SERVER_TOKEN:-} APISIX_ADMIN_URL: http://apisix:9180 APISIX_ADMIN_KEY: ${APISIX_ADMIN_KEY:-quayel-apisix-admin-key} QUAYEL_METRICS_HOST: ${QUAYEL_METRICS_HOST:-https://agent-api.quayel.com} QAGENT_IMAGE: ${QAGENT_IMAGE:-quayel/agent-agent-api:latest} # Empty = use install_script_url from the global agent config. INSTALL_SCRIPT_URL: ${INSTALL_SCRIPT_URL:-} UPDATE_CHECK_INTERVAL_MS: ${UPDATE_CHECK_INTERVAL_MS:-} UPDATE_CHECK_DISABLED: ${UPDATE_CHECK_DISABLED:-} # vip (default): Swarm virtual IP. tasks: APISIX balances and health-checks each replica. QUAYEL_UPSTREAM_MODE: ${QUAYEL_UPSTREAM_MODE:-vip} volumes: - /etc/quayel:/etc/quayel - /var/log/quayel:/var/log/quayel - /var/lib/quayel:/var/lib/quayel - /var/run/docker.sock:/var/run/docker.sock networks: - quayel-main-network volumes: etcd-data: networks: quayel-main-network: external: true YAML } # Per-server admin key + admin access limited to the Docker network (never published on the host). secure_apisix_admin() { local cfg=/etc/quayel/apisix/config.yaml key_file=/etc/quayel/apisix_admin_key subnets s if [[ -s "$key_file" ]]; then APISIX_ADMIN_KEY="$(tr -d '[:space:]' < "$key_file")" else APISIX_ADMIN_KEY="$(openssl rand -hex 24 2>/dev/null || head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n')" (umask 077 && printf '%s\n' "$APISIX_ADMIN_KEY" > "$key_file") ok "generated APISIX admin key (${key_file})" fi export APISIX_ADMIN_KEY sed -i "s/^\( key: \).*$/\1${APISIX_ADMIN_KEY}/" "$cfg" subnets="$(docker network inspect "$NETWORK_NAME" --format '{{range .IPAM.Config}}{{.Subnet}} {{end}}' 2>/dev/null || true)" if [[ -n "${subnets// }" ]]; then sed -i -e '/^ - 10\.0\.0\.0\/8$/d' -e '/^ - 172\.16\.0\.0\/12$/d' -e '/^ - 192\.168\.0\.0\/16$/d' "$cfg" for s in $subnets; do sed -i "s#^ - 127\.0\.0\.0/8\$#&\n - ${s}#" "$cfg" done ok "APISIX admin limited to 127.0.0.0/8 ${subnets}" fi } ensure_dirs_and_files() { log "Quayel directories + config (no git clone — qagent from Docker Hub)" mkdir -p \ "$INSTALL_DIR" \ /var/lib/quayel/{logs,source,compose,ssl,backups} \ /var/log/quayel SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [[ "$GATEWAY_ENGINE" == quayel ]]; then mkdir -p /etc/quayel/gateway /var/lib/quayel/certs /var/log/quayel/gateway seed_gateway_config else mkdir -p /etc/quayel/apisix /var/lib/quayel/apisix-cache # Bad prior mounts sometimes created config.yaml as a directory. if [[ -d /etc/quayel/apisix/config.yaml ]]; then warn "/etc/quayel/apisix/config.yaml is a directory — removing" rm -rf /etc/quayel/apisix/config.yaml fi if [[ -f "${SCRIPT_DIR}/deploy/apisix/config.yaml" ]]; then cp -f "${SCRIPT_DIR}/deploy/apisix/config.yaml" /etc/quayel/apisix/config.yaml else write_apisix_config fi secure_apisix_admin ok "/etc/quayel/apisix/config.yaml" fi # Always rewrite compose from this script (fixes old ETCD_DATA_DIR installs). write_compose_file ok "${INSTALL_DIR}/docker-compose.yml" # Agent JWT RS256 public key only (private key never installed). mkdir -p /etc/quayel/keys if [[ -f "${SCRIPT_DIR}/keys/agent-jwt-public.pem" ]]; then cp -f "${SCRIPT_DIR}/keys/agent-jwt-public.pem" /etc/quayel/keys/agent-jwt-public.pem else cat > /etc/quayel/keys/agent-jwt-public.pem <<'PEM' -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8jbhyWrMedlR2r1HyziM 2k/mYp0osFmp1pR7vnIMEoKqR70Yof5VKxHQwyS3cPxWiEHTd3fSf+ljPxawxwib EjJY0G7sUttqhjYkaHy+OksT/pu+w63zJ9yqF0SiAi5SvhmWg3JmWafwkqfVGsGS TJU/DEKDTgU5V6fU3csonDfmuWfYeTDSXxibBvJmdUCME8CoREjeb723/drmlm6w XjQLsQqkqgP3srm652zAJhpa+FV1CKPukYUsynhS7r5FRM2I4saiJN/1nryXNzUu LJJih8vcveAwwBQ+AwkcavL0zK8Fr5PgmBa26xIbxjIixmbKxbIfbzbXT/cjICN0 WQIDAQAB -----END PUBLIC KEY----- PEM fi chmod 644 /etc/quayel/keys/agent-jwt-public.pem ok "agent JWT public key (RS256 / kid agent-v1)" if [[ -n "${SERVER_TOKEN:-}" ]]; then printf '%s\n' "$SERVER_TOKEN" > /etc/quayel/server_token chmod 600 /etc/quayel/server_token ok "SERVER_TOKEN saved" elif [[ -f /etc/quayel/server_token ]]; then SERVER_TOKEN="$(tr -d '[:space:]' < /etc/quayel/server_token)" export SERVER_TOKEN ok "loaded SERVER_TOKEN from /etc/quayel/server_token" else warn "SERVER_TOKEN not set — agent cloud sync will fail until you set it" fi umask 077 cat > "${INSTALL_DIR}/.env" </dev/null 2>&1 || true done docker compose "${compose_files[@]}" up -d --force-recreate --remove-orphans ok "compose up (engine=${GATEWAY_ENGINE})" if [[ "$GATEWAY_ENGINE" == quayel ]]; then wait_agent_health sleep 2 docker exec quayel-agent-api curl -sf -X POST http://127.0.0.1:4000/api/v1/gateway/reload >/dev/null 2>&1 \ && ok "gateway config written" \ || warn "gateway config write skipped (retries on agent boot)" return 0 fi log "Waiting for etcd healthy" local i=0 until docker exec etcd etcdctl endpoint health >/dev/null 2>&1; do i=$((i + 1)) if [[ "$i" -gt 30 ]]; then warn "etcd timed out — check: docker logs etcd" warn "if volume is corrupt: docker compose -f ${INSTALL_DIR}/docker-compose.yml down && docker volume rm ${COMPOSE_PROJECT}_etcd-data" break fi sleep 2 done if docker exec etcd etcdctl endpoint health >/dev/null 2>&1; then ok "etcd healthy" fi wait_agent_health # APISIX admin is only on the Docker network: check it through the agent container. log "Waiting for APISIX admin (via agent)" i=0 until docker exec quayel-agent-api curl -sf http://apisix:9180/apisix/admin/routes \ -H "X-API-KEY: ${APISIX_ADMIN_KEY:-quayel-apisix-admin-key}" >/dev/null 2>&1; do i=$((i + 1)) if [[ "$i" -gt 60 ]]; then break fi sleep 2 done if docker exec quayel-agent-api curl -sf http://apisix:9180/apisix/admin/routes \ -H "X-API-KEY: ${APISIX_ADMIN_KEY:-quayel-apisix-admin-key}" >/dev/null 2>&1; then ok "agent → apisix:9180 reachable" else warn "agent cannot reach http://apisix:9180 — check docker network" docker network inspect "$NETWORK_NAME" --format '{{range .Containers}}{{.Name}} {{end}}' || true fi sleep 2 docker exec quayel-agent-api curl -sf -X POST http://127.0.0.1:4000/api/v1/gateway/reload >/dev/null 2>&1 \ && ok "gateway reloaded" \ || warn "gateway reload skipped (retries on agent restart)" } wait_agent_health() { log "Waiting for agent health" local i=0 until docker exec quayel-agent-api curl -sf http://127.0.0.1:4000/health >/dev/null 2>&1; do i=$((i + 1)) if [[ "$i" -gt 60 ]]; then warn "agent health timed out — check: docker logs quayel-agent-api" return 0 fi sleep 2 done ok "agent healthy on :4000" } print_summary() { local edge="APISIX: http://127.0.0.1/ (admin only on the Docker network)" if [[ "$GATEWAY_ENGINE" == quayel ]]; then edge="Gateway: Quayel Gateway on :80/:443 (config /etc/quayel/gateway/config.json)" fi cat < /etc/quayel/install_version ok "install version ${VERSION} → /etc/quayel/install_version" print_summary } main "$@"