Skip to content

Instantly share code, notes, and snippets.

@nad2000
Created April 16, 2025 23:22
Show Gist options
  • Save nad2000/447b29474263adcdd76b4986c562fc8d to your computer and use it in GitHub Desktop.
Save nad2000/447b29474263adcdd76b4986c562fc8d to your computer and use it in GitHub Desktop.
Using SIGINT to gracefully shut down a service
package main
import (
"fmt"
"os"
"os/signal"
"time"
)
func main() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
sig := <-ch
fmt.Println("Recieved signal:", sig)
fmt.Println("Shutting down...")
time.Sleep(3 * time.Second)
fmt.Println("Shutdown complete")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment