mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-27 02:27:45 +00:00
bfe0d4c9b0
Adds a Docker healthcheck and the small HTTP/CLI plumbing it needs. - Expose `GET /healthz` on the HTTP-mode server. - Add `-healthcheck` to dial `http://127.0.0.1:<port>/healthz` and exit with status. - Add a Dockerfile `HEALTHCHECK` instruction using `-healthcheck`. - Document HTTP-mode usage and stdio override guidance. Closes https://gitea.com/gitea/gitea-mcp/issues/146 Assisted by Codet. Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/254 Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
30 lines
735 B
Go
30 lines
735 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// runHealthcheck dials the /healthz endpoint on 127.0.0.1:port and reports
|
|
// success or failure. It returns true when the server responds with a 2xx
|
|
// status.
|
|
func runHealthcheck(client *http.Client, port int, stdout, stderr io.Writer) bool {
|
|
url := fmt.Sprintf("http://127.0.0.1:%d/healthz", port)
|
|
|
|
resp, err := client.Get(url)
|
|
if err != nil {
|
|
fmt.Fprintf(stderr, "healthcheck failed: %v\n", err)
|
|
return false
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
|
fmt.Fprintf(stderr, "healthcheck failed: unexpected status %s\n", resp.Status)
|
|
return false
|
|
}
|
|
|
|
fmt.Fprintln(stdout, "healthy")
|
|
return true
|
|
}
|