1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api: handle SIGINT gracefully

This commit is contained in:
Adhityaa
2018-06-03 14:03:24 +05:30
parent a44e389b10
commit 72ab137f06
2 changed files with 26 additions and 0 deletions

25
api/sigint.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"os"
"os/signal"
"syscall"
)
func sigintCleanup() int {
// TODO: close the database connection and do other cleanup jobs
return 0
}
func setupSigintCleanup() error {
logger.Infof("setting up SIGINT cleanup")
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGINT)
go func() {
<-c
os.Exit(sigintCleanup())
}()
return nil
}