Skip to content

Commit 3810fe1

Browse files
committed
fix(distributed): worker container healthcheck always unhealthy
The Dockerfile's HEALTHCHECK probes http://localhost:8080/readyz, which is the OpenAI API server port. When the same image runs as a worker, it listens on the gRPC base port (50051) and an HTTP file transfer server on port-1 (50050) — nothing on 8080 — so docker always reports the container as unhealthy. Add unauthenticated /readyz and /healthz endpoints to the worker's HTTP file transfer server, and override HEALTHCHECK_ENDPOINT for worker-1 in the distributed compose file. Disable the healthcheck for agent-worker since it is NATS-only and exposes no HTTP server. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: claude-code:claude-opus-4-7 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent bdfa5e9 commit 3810fe1

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

core/services/nodes/file_transfer_server.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ func StartFileTransferServerWithListener(lis net.Listener, stagingDir, modelsDir
109109
registerBackendLogHandlers(mux, token, ls)
110110
}
111111

112+
// Liveness/readiness probes — unauthenticated so container orchestrators
113+
// (Docker HEALTHCHECK, k8s probes) can hit them without the bearer token.
114+
// Reaching this point means the listener is bound and the mux is serving.
115+
healthHandler := func(w http.ResponseWriter, r *http.Request) {
116+
if r.Method != http.MethodGet && r.Method != http.MethodHead {
117+
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
118+
return
119+
}
120+
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
121+
w.WriteHeader(http.StatusOK)
122+
_, _ = w.Write([]byte("ok"))
123+
}
124+
mux.HandleFunc("/readyz", healthHandler)
125+
mux.HandleFunc("/healthz", healthHandler)
126+
112127
addr := lis.Addr().String()
113128
server := &http.Server{
114129
Handler: mux,

docker-compose.distributed.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ services:
9696
- BASE_IMAGE=ubuntu:24.04
9797
command:
9898
- worker
99+
# The image's default HEALTHCHECK targets the server's /readyz on 8080.
100+
# Workers don't run the OpenAI API server — their HTTP file transfer
101+
# server runs on the gRPC base port - 1 (50050 here) and exposes /readyz.
102+
# Override the env var so the inherited HEALTHCHECK probes the right port.
99103
environment:
104+
HEALTHCHECK_ENDPOINT: "http://localhost:50050/readyz"
100105
LOCALAI_SERVE_ADDR: "0.0.0.0:50051"
101106
LOCALAI_ADVERTISE_ADDR: "worker-1:50051"
102107
LOCALAI_ADVERTISE_HTTP_ADDR: "worker-1:50050"
@@ -187,6 +192,10 @@ services:
187192
- |
188193
apt-get update -qq && apt-get install -y -qq docker.io >/dev/null 2>&1
189194
exec /entrypoint.sh agent-worker
195+
# The agent worker is NATS-only — no HTTP server to probe. Disable the
196+
# image's inherited HEALTHCHECK so the container doesn't show unhealthy.
197+
healthcheck:
198+
disable: true
190199
environment:
191200
LOCALAI_NATS_URL: "nats://nats:4222"
192201
LOCALAI_REGISTER_TO: "http://localai:8080"

0 commit comments

Comments
 (0)