summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--database.go13
-rw-r--r--main.go16
2 files changed, 16 insertions, 13 deletions
diff --git a/database.go b/database.go
index ea11cfa..5d9181c 100644
--- a/database.go
+++ b/database.go
@@ -7,11 +7,9 @@ import (
"path/filepath"
"io"
"os"
- "os/signal"
"os/user"
"os/exec"
"strconv"
- "syscall"
"database/sql"
_ "github.com/go-sql-driver/mysql"
@@ -41,17 +39,6 @@ func setupDatabase() *sql.DB {
migrate(db)
- // allow graceful shutdown
- var listener = make(chan os.Signal)
- signal.Notify(listener, syscall.SIGTERM)
- signal.Notify(listener, syscall.SIGINT)
- go func() {
- signal := <-listener
- log.Printf("\nGot signal '%+v'. Shutting down ...\n", signal)
- dbCleanup(db)
- os.Exit(0) // TODO this does not belong to a database - write utils file 'shutdown.go'
- }()
-
log.Printf("Connected to database: %s\n", target)
return db
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)
+ }()
+}