2018-06-03 16:33:24 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func sigintCleanup() int {
|
2019-05-02 06:39:40 +08:00
|
|
|
if db != nil {
|
|
|
|
err := db.Close()
|
|
|
|
if err == nil {
|
|
|
|
logger.Errorf("cannot close database connection: %v", err)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 16:33:24 +08:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-07-24 14:44:25 +08:00
|
|
|
func sigintCleanupSetup() error {
|
2018-06-03 16:33:24 +08:00
|
|
|
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
|
|
|
|
}
|