Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.6 kB ยท 61 lines
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162package main
import ( "context" "fmt" "log" "net/http" "os/signal" "syscall" "time"
"github.com/openstatushq/openstatus/apps/private-location/internal/server")
func gracefulShutdown(apiServer *http.Server, cleanup func(context.Context), done chan bool) { // Create context that listens for the interrupt signal from the OS. ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop()
// Listen for the interrupt signal. <-ctx.Done()
fmt.Println("shutting down gracefully, press Ctrl+C again to force") stop() // Allow Ctrl+C to force shutdown
// The context is used to inform the server it has 5 seconds to finish // the request it is currently handling ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := apiServer.Shutdown(ctx); err != nil { log.Printf("Server forced to shutdown with error: %v", err) }
// Cleanup log provider cleanup(ctx)
log.Println("Server exiting")
// Notify the main goroutine that the shutdown is complete done <- true}
func main() {
server, cleanup := server.NewServer()
// Create a done channel to signal when the shutdown is complete done := make(chan bool, 1)
// Run graceful shutdown in a separate goroutine go gracefulShutdown(server, cleanup, done)
err := server.ListenAndServe() if err != nil && err != http.ErrServerClosed { panic(fmt.Sprintf("http server error: %s", err)) }
// Wait for the graceful shutdown to complete <-done log.Println("Graceful shutdown complete.")}