-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (39 loc) · 943 Bytes
/
main.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"net/http"
"os"
"os/signal"
"time"
"github.com/hashicorp/go-hclog"
"github.com/resinstack/dtn/pkg/nomad"
"github.com/resinstack/dtn/pkg/web"
)
func main() {
appLogger := hclog.New(&hclog.LoggerOptions{
Name: "dtn",
Level: hclog.LevelFromString("DEBUG"),
})
appLogger.Info("Starting Up")
n := nomad.New()
n.SetParentLogger(appLogger)
n.Connect()
ws := web.New()
ws.SetParentLogger(appLogger)
ws.SetNomadProvider(n)
go func() {
if err := ws.Start(":1323"); err != nil && err != http.ErrServerClosed {
appLogger.Error("Error starting server", "error", err)
return
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
appLogger.Info("Shutting down")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := ws.Shutdown(ctx); err != nil {
appLogger.Error("Error shutting down", "error", err)
}
}