Merge fix/launcher-detect-external-gateway: detect external gateway
Brings in launcher external gateway detection fix (PR #1811 against sipeed/picoclaw). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
86e68a255d
1 changed files with 36 additions and 1 deletions
|
|
@ -72,6 +72,13 @@ func (h *Handler) TryAutoStartGateway() {
|
||||||
gateway.cmd = nil
|
gateway.cmd = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether a gateway is already running externally (e.g. via systemd).
|
||||||
|
// If the health endpoint responds we skip auto-start to avoid a duplicate.
|
||||||
|
if h.isGatewayHealthy() {
|
||||||
|
log.Printf("Skip auto-starting gateway: already running externally")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ready, reason, err := h.gatewayStartReady()
|
ready, reason, err := h.gatewayStartReady()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Skip auto-starting gateway: %v", err)
|
log.Printf("Skip auto-starting gateway: %v", err)
|
||||||
|
|
@ -117,6 +124,27 @@ func (h *Handler) gatewayStartReady() (bool, string, error) {
|
||||||
return true, "", nil
|
return true, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isGatewayHealthy probes the gateway health endpoint and returns true if it
|
||||||
|
// responds with HTTP 200. Used to detect an externally-managed gateway process.
|
||||||
|
func (h *Handler) isGatewayHealthy() bool {
|
||||||
|
cfg, err := config.LoadConfig(h.configPath)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
host := gatewayProbeHost(h.effectiveGatewayBindHost(cfg))
|
||||||
|
port := cfg.Gateway.Port
|
||||||
|
if port == 0 {
|
||||||
|
port = 18790
|
||||||
|
}
|
||||||
|
url := fmt.Sprintf("http://%s/health", net.JoinHostPort(host, strconv.Itoa(port)))
|
||||||
|
resp, err := gatewayHealthGet(url, 1*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
|
return resp.StatusCode == http.StatusOK
|
||||||
|
}
|
||||||
|
|
||||||
func lookupModelConfig(cfg *config.Config, modelName string) *config.ModelConfig {
|
func lookupModelConfig(cfg *config.Config, modelName string) *config.ModelConfig {
|
||||||
modelCfg, err := cfg.GetModelConfig(modelName)
|
modelCfg, err := cfg.GetModelConfig(modelName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -596,8 +624,15 @@ func (h *Handler) gatewayStatusData() map[string]any {
|
||||||
|
|
||||||
if !processAlive {
|
if !processAlive {
|
||||||
gateway.mu.Lock()
|
gateway.mu.Lock()
|
||||||
data["gateway_status"] = currentGatewayStatusLocked(false)
|
launcherStatus := currentGatewayStatusLocked(false)
|
||||||
gateway.mu.Unlock()
|
gateway.mu.Unlock()
|
||||||
|
// Only probe for an external gateway when the launcher has no in-progress
|
||||||
|
// state (restarting/error). Those states take precedence.
|
||||||
|
if launcherStatus == "stopped" && h.isGatewayHealthy() {
|
||||||
|
data["gateway_status"] = "running"
|
||||||
|
} else {
|
||||||
|
data["gateway_status"] = launcherStatus
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Process is alive — probe its health endpoint
|
// Process is alive — probe its health endpoint
|
||||||
host := "127.0.0.1"
|
host := "127.0.0.1"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue