This commit is contained in:
2026-04-04 12:52:08 +02:00
parent 02fec72c43
commit 1e5423c4db
17 changed files with 618 additions and 21 deletions

View File

@@ -44,8 +44,11 @@ func main() {
log.Fatalf("Failed to start device manager: %v", err)
}
// Channel de shutdown partagé entre main et le handler API
shutdownChan := make(chan struct{})
// Create HTTP server with embedded files
server := api.NewServer(deviceManager, hub, cfg)
server := api.NewServer(deviceManager, hub, cfg, shutdownChan)
mux := server.SetupRoutes()
// Serve embedded static files
@@ -76,12 +79,17 @@ func main() {
}
}()
// Wait for interrupt signal
// Wait for interrupt signal or API shutdown request
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutting down server...")
select {
case <-quit:
log.Println("Signal received, shutting down...")
case <-shutdownChan:
log.Println("API shutdown requested, shutting down...")
}
deviceManager.Stop()
log.Println("Server stopped")
}