-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.go
82 lines (64 loc) · 1.56 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"github.com/webitel/storage/apis"
"github.com/webitel/storage/app"
"github.com/webitel/storage/grpc_api"
_ "github.com/webitel/storage/stt"
_ "github.com/webitel/storage/synchronizer"
_ "github.com/webitel/storage/uploader"
"github.com/webitel/wlog"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"github.com/webitel/storage/apis/private"
)
func main() {
interruptChan := make(chan os.Signal, 1)
a, err := app.New()
if err != nil {
panic(err.Error())
}
wlog.Info(fmt.Sprintf("server version: %s", a.Version()))
serverErr := a.StartServer()
if serverErr != nil {
wlog.Critical(serverErr.Error())
return
}
apis.Init(a, a.Srv.Router)
serverErr = a.StartInternalServer()
if serverErr != nil {
wlog.Critical(serverErr.Error())
return
}
private.Init(a, a.InternalSrv.Router)
a.Uploader.Start()
a.Synchronizer.Start()
grpc_api.Init(a, a.GrpcServer.Server())
if err = a.StartGrpcServer(); err != nil {
panic(err.Error())
}
setDebug()
// wait for kill signal before attempting to gracefully shutdown
// the running service
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interruptChan
a.Shutdown()
//a.Broker.Close()
wlog.Info("Stopping synchronizer server")
a.Synchronizer.Stop()
wlog.Info("Stopping uploader server")
a.Uploader.Stop()
}
func setDebug() {
//debug.SetGCPercent(-1)
go func() {
wlog.Info("Start debug server on http://localhost:8090/debug/pprof/")
err := http.ListenAndServe(":8090", nil)
if err != nil {
wlog.Critical(err.Error())
}
}()
}