Skip to content

Commit a70aece

Browse files
author
Matthias
committed
fix(deploy): default service bind to 0.0.0.0 and reconcile env overrides
Behind a containerized reverse proxy (nginx-in-Docker via host.docker.internal), a 127.0.0.1 bind is unreachable and 502s. Default ONTOLOVIZ_HOST to 0.0.0.0; set 127.0.0.1 explicitly for host-local-only deploys. - install-service.sh: reconcile explicitly-passed HOST/PORT/PROXY_HEADERS into an existing /etc/ontoloviz.env. The file was write-once, so re-run overrides were silently ignored — the trap that stranded the service on 127.0.0.1:8000. Operator customizations and defaults-only re-runs are left untouched. - update-service.sh: warn when bound to 127.0.0.1, since the host-local healthcheck passes even when the proxy cannot reach the service.
1 parent 8e0bf37 commit a70aece

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

install-service.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -euo pipefail
1515
# With no argument, the newest dist/*.whl in this repo is used.
1616
#
1717
# Deployment config is injected via env (conventional defaults otherwise):
18-
# ONTOLOVIZ_HOST bind address (default 127.0.0.1; use 0.0.0.0 behind a proxy)
18+
# ONTOLOVIZ_HOST bind address (default 0.0.0.0 for proxied deploys; set 127.0.0.1 for host-local only)
1919
# ONTOLOVIZ_PORT listen port (default 8000)
2020
# ONTOLOVIZ_PROXY_HEADERS trust X-Forwarded-* (default 0; set 1 behind TLS proxy)
2121
# e.g. reverse-proxied deployment on a custom port:
@@ -43,7 +43,17 @@ fi
4343
SERVICE_GROUP="$(id -gn "$SERVICE_USER")"
4444

4545
# Deployment config — conventional defaults; override via env at install time.
46-
BIND="${ONTOLOVIZ_HOST:-127.0.0.1}"
46+
# Default bind is 0.0.0.0 so a containerized/external reverse proxy can reach the
47+
# service (e.g. nginx-in-Docker via host.docker.internal); exposure is then gated
48+
# upstream by the firewall/VPN, not by this address. Set ONTOLOVIZ_HOST=127.0.0.1
49+
# explicitly for a host-local-only deployment.
50+
# Track whether each value was passed explicitly: an existing env file is
51+
# write-once, so without this a re-run override (e.g. ONTOLOVIZ_PORT=49317) is
52+
# silently ignored — the trap that strands the service on the wrong port/bind.
53+
HOST_EXPLICIT="${ONTOLOVIZ_HOST+set}"
54+
PORT_EXPLICIT="${ONTOLOVIZ_PORT+set}"
55+
PROXY_EXPLICIT="${ONTOLOVIZ_PROXY_HEADERS+set}"
56+
BIND="${ONTOLOVIZ_HOST:-0.0.0.0}"
4757
PORT="${ONTOLOVIZ_PORT:-8000}"
4858
PROXY_HEADERS="${ONTOLOVIZ_PROXY_HEADERS:-0}"
4959

@@ -109,7 +119,23 @@ fi
109119

110120
chown -R "$SERVICE_USER":"$SERVICE_GROUP" "$APP_HOME"
111121

112-
# --- env file (optional, created once) -------------------------------------
122+
# --- env file --------------------------------------------------------------
123+
# Created once with the resolved values. On re-run we never clobber an
124+
# operator-customized file; we only reconcile keys passed explicitly THIS run,
125+
# so `sudo ONTOLOVIZ_HOST=0.0.0.0 ONTOLOVIZ_PORT=49317 ./install-service.sh`
126+
# actually applies even though the file already exists.
127+
reconcile_env_kv() {
128+
local key="$1" val="$2" explicit="$3"
129+
[ -n "$explicit" ] || return 0
130+
if grep -qE "^${key}=" "$ENV_FILE"; then
131+
grep -qxF "${key}=${val}" "$ENV_FILE" && return 0
132+
sed -i "s|^${key}=.*|${key}=${val}|" "$ENV_FILE"
133+
else
134+
printf '%s=%s\n' "$key" "$val" >> "$ENV_FILE"
135+
fi
136+
echo " set ${key}=${val}"
137+
}
138+
113139
if [ ! -f "$ENV_FILE" ]; then
114140
cat > "$ENV_FILE" <<EOF
115141
# OntoloViz server environment (written by install-service.sh).
@@ -135,6 +161,11 @@ ONTOLOVIZ_WORKERS=1
135161
EOF
136162
chown "$SERVICE_USER":"$SERVICE_GROUP" "$ENV_FILE"
137163
chmod 640 "$ENV_FILE"
164+
elif [ -n "$HOST_EXPLICIT$PORT_EXPLICIT$PROXY_EXPLICIT" ]; then
165+
echo "[..] reconciling explicit overrides into existing ${ENV_FILE}:"
166+
reconcile_env_kv ONTOLOVIZ_HOST "$BIND" "$HOST_EXPLICIT"
167+
reconcile_env_kv ONTOLOVIZ_PORT "$PORT" "$PORT_EXPLICIT"
168+
reconcile_env_kv ONTOLOVIZ_PROXY_HEADERS "$PROXY_HEADERS" "$PROXY_EXPLICIT"
138169
fi
139170

140171
# --- compose the unit ------------------------------------------------------

update-service.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ if [ -n "${ONTOLOVIZ_HOST:-}" ] && [ "${ONTOLOVIZ_HOST}" != "0.0.0.0" ]; then H=
8484
if [ -n "${ONTOLOVIZ_PORT:-}" ]; then P="$ONTOLOVIZ_PORT"; fi
8585
BASE="http://${H}:${P}"
8686

87+
# The host-local healthcheck below passes even when a containerized/external
88+
# reverse proxy can't reach the service. A 127.0.0.1 bind is unreachable via
89+
# host.docker.internal and 502s at the proxy — warn loudly so it isn't missed.
90+
if [ "${ONTOLOVIZ_HOST:-127.0.0.1}" = "127.0.0.1" ]; then
91+
echo "WARNING: ONTOLOVIZ_HOST=127.0.0.1 — a containerized/external reverse proxy"
92+
echo " (e.g. nginx via host.docker.internal) cannot reach this and will 502."
93+
echo " For a proxied deploy set ONTOLOVIZ_HOST=0.0.0.0 in ${ENV_FILE},"
94+
echo " then: sudo systemctl restart ${SERVICE_NAME}"
95+
fi
96+
8797
ok=0
8898
for _ in $(seq 1 15); do
8999
if curl -fsS "${BASE}/api/health" >/dev/null 2>&1; then ok=1; break; fi

0 commit comments

Comments
 (0)