Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/sidecar/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package main

import (
"os"
"os/signal"
"syscall"

"github.com/FastLane-Labs/fastlane-sidecar/internal/orchestrator"
"github.com/FastLane-Labs/fastlane-sidecar/pkg/config"
"github.com/FastLane-Labs/fastlane-sidecar/pkg/log"
Expand All @@ -23,6 +27,14 @@ func main() {
panic(err)
}

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
go func() {
sig := <-sigCh
log.Info("shutdown signal received", "signal", sig.String())
sidecar.Stop()
}()

log.Info("Sidecar started ...")
<-shutdownChan
log.Info("Shutting down ...")
Expand Down
9 changes: 8 additions & 1 deletion internal/health/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package health

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -69,7 +70,13 @@ func (s *Server) Start() error {
// Stop gracefully stops the HTTP server
func (s *Server) Stop() error {
log.Info("Stopping monitoring server")
return s.httpServer.Close()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := s.httpServer.Shutdown(ctx); err != nil {
log.Error("monitoring server shutdown error", "error", err)
return s.httpServer.Close()
}
return nil
}

// handleHealth handles GET /health requests
Expand Down