diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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) + }() +} |