popup
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user