package main import ( "database/sql" "log" "os" "os/signal" "syscall" ) var config RuntimeConfig var db *sql.DB 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) }() }