-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
67 lines (57 loc) · 1.73 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import "github.com/astaxie/beego"
import "github.com/astaxie/beego/plugins/cors"
import "github.com/humpback/common/models"
import "github.com/humpback/humpback-agent/config"
import "github.com/humpback/humpback-agent/controllers"
import "github.com/humpback/humpback-agent/routers"
import "github.com/humpback/humpback-center/cluster/types"
import (
"os"
"os/signal"
"syscall"
)
func main() {
config.Init()
config.SetVersion("1.3.7")
controllers.Init()
var conf = config.GetConfig()
beego.BConfig.MaxMemory = conf.DockerComposePackageMaxSize
composeStorage, err := models.NewComposeStorage(conf.DockerComposePath)
if err != nil {
beego.Error("compose storage error, " + err.Error())
return
}
routers.Init(composeStorage)
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization"},
AllowCredentials: true,
}))
beego.SetLogFuncCall(true)
beego.SetLevel(conf.LogLevel)
ipAddr, bindPort, err := config.GetNodeHTTPAddrIPPort()
if err != nil {
beego.Error("agent httpaddr error:" + err.Error())
}
beego.BConfig.Listen.HTTPPort = bindPort
if conf.DockerClusterEnabled {
clusterOptions := types.NewNodeRegisterOptions(ipAddr, bindPort, &conf)
if err := types.NodeRegister(clusterOptions); err != nil {
beego.Error("cluster node register error:" + err.Error())
return
}
}
go signalListen()
beego.Run()
}
func signalListen() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
for {
<-c
types.NodeClose()
os.Exit(0)
}
}