mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-14 03:01:48 +00:00
Exit gracefully (run deferred statements in main()) on SIGINT.
This commit is contained in:
@@ -384,6 +384,11 @@ func Main() {
|
||||
} else {
|
||||
log.Println("serve: ready")
|
||||
}
|
||||
select {}
|
||||
|
||||
interrupt := make(chan struct{})
|
||||
OnInterrupt(func() { interrupt <- struct{}{} })
|
||||
<-interrupt
|
||||
|
||||
log.Println("exiting gracefully")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,3 +5,7 @@ package git_pages
|
||||
func OnReload(handler func()) {
|
||||
// not implemented
|
||||
}
|
||||
|
||||
func OnInterrupt(handler func()) {
|
||||
// not implemented
|
||||
}
|
||||
|
||||
@@ -18,3 +18,13 @@ func OnReload(handler func()) {
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func OnInterrupt(handler func()) {
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, syscall.SIGINT)
|
||||
go func() {
|
||||
<-sigint
|
||||
signal.Stop(sigint)
|
||||
handler()
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user