fix: use fixed path for agent healthcheck address file (#4617)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Amir Raminfar
2026-04-13 08:29:39 -07:00
committed by GitHub
parent 4616159e27
commit 3aa80b8f07
2 changed files with 11 additions and 14 deletions
+5 -8
View File
@@ -4,7 +4,6 @@ import (
"context"
"embed"
"fmt"
"io"
"net"
"os"
"os/signal"
@@ -114,12 +113,10 @@ func (a *AgentCmd) Run(args Args, embeddedCerts embed.FS) error {
if err != nil {
return fmt.Errorf("failed to listen: %w", err)
}
tempFile, err := os.CreateTemp("", "agent-*.addr")
if err != nil {
return fmt.Errorf("failed to create temp file: %w", err)
const agentAddrFile = "/tmp/dozzle-agent.addr"
if err := os.WriteFile(agentAddrFile, []byte(args.Agent.Addr), 0644); err != nil {
return fmt.Errorf("failed to write agent address file: %w", err)
}
io.WriteString(tempFile, listener.Addr().String())
log.Debug().Str("file", tempFile.Name()).Msg("Created temp file")
go StartEvent(args, "", client, "agent")
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
@@ -192,7 +189,7 @@ func (a *AgentCmd) Run(args Args, embeddedCerts embed.FS) error {
stop()
log.Info().Msg("Shutting down agent")
server.Stop()
log.Debug().Str("file", tempFile.Name()).Msg("Removing temp file")
os.Remove(tempFile.Name())
log.Debug().Str("file", agentAddrFile).Msg("Removing agent address file")
os.Remove(agentAddrFile)
return nil
}
+6 -6
View File
@@ -4,8 +4,8 @@ import (
"context"
"embed"
"fmt"
"net"
"os"
"path/filepath"
"github.com/amir20/dozzle/internal/healthcheck"
"github.com/rs/zerolog/log"
@@ -14,12 +14,12 @@ import (
type HealthcheckCmd struct{}
func (h *HealthcheckCmd) Run(args Args, embeddedCerts embed.FS) error {
if matches, err := filepath.Glob("/tmp/agent-*.addr"); err == nil && len(matches) == 1 {
data, err := os.ReadFile(matches[0])
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
const agentAddrFile = "/tmp/dozzle-agent.addr"
if data, err := os.ReadFile(agentAddrFile); err == nil {
agentAddress := string(data)
if host, port, err := net.SplitHostPort(agentAddress); err == nil && (host == "" || host == "::" || host == "0.0.0.0") {
agentAddress = "localhost:" + port
}
certs, err := ReadCertificates(embeddedCerts, args.CertPath, args.KeyPath)
if err != nil {
return fmt.Errorf("failed to read certificates: %w", err)