summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/main.go b/main.go
index 405ff0a..c1e0571 100644
--- a/main.go
+++ b/main.go
@@ -3,7 +3,10 @@ package main
import (
"log"
+ "os"
+ "os/signal"
"database/sql"
+ "syscall"
)
var config RuntimeConfig
@@ -13,5 +16,18 @@ func main() {
log.Printf("Started Ceres recipe server.\n")
config = GetRuntimeConfig()
db = setupDatabase()
+ provideShutdown()
runServer()
}
+
+func provideShutdown() {
+ var listener = make(chan os.Signal)
+ signal.Notify(listener, syscall.SIGTERM)
+ signal.Notify(listener, syscall.SIGINT)
+ go func() {
+ signal := <-listener
+ log.Printf("Got signal '%+v'. Shutdown is started.\n", signal)
+ dbCleanup(db)
+ os.Exit(0)
+ }()
+}