Refuse invalid settings at start, health check follows PORT (closes #31)
check / check (push) Successful in 2m49s

PORT (1 to 65535) and XDG_DATA_HOME (an absolute path) are now checked in
the config package, which is built before the database opens, so a bad
value stops the start with an error and a non-zero exit instead of leaving
the daemon running without HTTP or putting the database somewhere else.
entrypoint.sh refuses a MALLOC_ARENA_MAX that is not a positive whole
number, since glibc ignores a bad one silently. The HEALTHCHECK probes the
port PORT names. The README corrects the Linux state directory, lists
XDG_DATA_HOME, and adds a "Running under upaas" section.

Model: opus-5-5
This commit is contained in:
2026-09-28 17:05:36 +00:00
parent df9e23d503
commit b305942e5e
9 changed files with 151 additions and 17 deletions
+7 -9
View File
@@ -4,9 +4,10 @@ package server
import (
"context"
"net/http"
"os"
"strconv"
"time"
"git.eeqj.de/sneak/routewatch/internal/config"
"git.eeqj.de/sneak/routewatch/internal/database"
"git.eeqj.de/sneak/routewatch/internal/logger"
"git.eeqj.de/sneak/routewatch/internal/streamer"
@@ -33,16 +34,18 @@ type Server struct {
db database.Store
streamer *streamer.Streamer
logger *logger.Logger
port int
srv *http.Server
asnFetcher ASNFetcher
}
// New creates a new HTTP server
func New(db database.Store, streamer *streamer.Streamer, logger *logger.Logger) *Server {
func New(db database.Store, streamer *streamer.Streamer, logger *logger.Logger, cfg *config.Config) *Server {
s := &Server{
db: db,
streamer: streamer,
logger: logger,
port: cfg.Port,
}
s.setupRoutes()
@@ -52,11 +55,6 @@ func New(db database.Store, streamer *streamer.Streamer, logger *logger.Logger)
// Start starts the HTTP server
func (s *Server) Start() error {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
const (
readHeaderTimeout = 40 * time.Second
readTimeout = 60 * time.Second
@@ -65,7 +63,7 @@ func (s *Server) Start() error {
)
s.srv = &http.Server{
Addr: ":" + port,
Addr: ":" + strconv.Itoa(s.port),
Handler: s.router,
ReadHeaderTimeout: readHeaderTimeout,
ReadTimeout: readTimeout,
@@ -73,7 +71,7 @@ func (s *Server) Start() error {
IdleTimeout: idleTimeout,
}
s.logger.Info("Starting HTTP server", "port", port, "addr", s.srv.Addr)
s.logger.Info("Starting HTTP server", "port", s.port, "addr", s.srv.Addr)
// Start in goroutine but log when actually listening
go func() {