summaryrefslogtreecommitdiff
path: root/main.go
blob: 483633cc78772fe51669eb38d0f2ef23770a72af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main

import (
	"database/sql"
	"log"
	"os"
	"os/signal"
	"syscall"
	"text/template"
)

var config RuntimeConfig
var db *sql.DB
var templates *template.Template

func main() {
	log.Printf("Started Ceres recipe server.\n")
	config = GetRuntimeConfig()
	templates = setupTemplates()
	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)
	}()
}