diff --git a/api/main.go b/api/main.go index a395a2c..43f8b60 100644 --- a/api/main.go +++ b/api/main.go @@ -8,6 +8,7 @@ func main() { exitIfError(smtpConfigure()) exitIfError(oauthConfigure()) exitIfError(createMarkdownRenderer()) + exitIfError(setupSigintCleanup()) exitIfError(serveRoutes()) } diff --git a/api/sigint.go b/api/sigint.go new file mode 100644 index 0000000..5b91edf --- /dev/null +++ b/api/sigint.go @@ -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 +}