api: handle SIGINT gracefully
This commit is contained in:
parent
a44e389b10
commit
72ab137f06
@ -8,6 +8,7 @@ func main() {
|
|||||||
exitIfError(smtpConfigure())
|
exitIfError(smtpConfigure())
|
||||||
exitIfError(oauthConfigure())
|
exitIfError(oauthConfigure())
|
||||||
exitIfError(createMarkdownRenderer())
|
exitIfError(createMarkdownRenderer())
|
||||||
|
exitIfError(setupSigintCleanup())
|
||||||
|
|
||||||
exitIfError(serveRoutes())
|
exitIfError(serveRoutes())
|
||||||
}
|
}
|
||||||
|
25
api/sigint.go
Normal file
25
api/sigint.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user