-
Notifications
You must be signed in to change notification settings - Fork 249
/
main.go
96 lines (81 loc) · 2.76 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package main
import (
"net"
"os"
"github.com/Tencent/bk-bcs/bcs-common/common/blog"
"github.com/Tencent/bk-bcs/bcs-common/common/conf"
"github.com/Tencent/bk-bcs/bcs-common/common/http/httpserver"
"github.com/Tencent/bk-bcs/bcs-runtime/bcs-mesos/bcs-process-daemon/process-daemon/api"
"github.com/Tencent/bk-bcs/bcs-runtime/bcs-mesos/bcs-process-daemon/process-daemon/config"
"github.com/Tencent/bk-bcs/bcs-runtime/bcs-mesos/bcs-process-daemon/process-daemon/manager"
)
// Option daemon process Option
type Option struct {
conf.FileConfig
conf.ServiceConfig
conf.MetricConfig
conf.CertConfig
conf.LicenseServerConfig
conf.LogConfig
conf.ProcessConfig
DataDir string `json:"data_dir" value:"" usage:"the process daemon data dir"`
UnixSocket string `json:"unix_socket" value:"" usage:"the unix socket path"`
WorkspaceDir string `json:"workspace_dir" value:"" usage:"the process packages dir"`
}
// Init process init
func Init() {
op := &Option{}
conf.Parse(op)
op.LogConfig.ToStdErr = true
// op.DataDir = "./data"
// op.UnixSocket = "/var/run/process.sock"
// op.WorkspaceDir = "/data/bcs/workspace"
blog.InitLogs(op.LogConfig)
defer blog.CloseLogs()
_, err := os.Stat(op.DataDir)
if err != nil {
blog.Errorf("datadir %s don't exist", err.Error())
return
}
config := &config.Config{
DataDir: op.DataDir,
WorkspaceDir: op.WorkspaceDir,
}
manager := manager.NewManager(config)
err = manager.Init()
if err != nil {
blog.Errorf("manager init error %s", err.Error())
return
}
manager.Start()
route := api.NewRouter(manager)
os.Remove(op.UnixSocket)
unixaddr, err := net.ResolveUnixAddr("unix", op.UnixSocket)
if err != nil {
blog.Errorf("resolve unixaddr %s error %s", op.UnixSocket, err.Error())
return
}
l, err := net.ListenUnix("unix", unixaddr)
if err != nil {
blog.Errorf("listen unix addr %s error %s", op.UnixSocket, err.Error())
return
}
httpServ := httpserver.NewHttpServer(uint(0), "", "")
httpServ.RegisterWebServer("/bcsapi/v1/processdaemon", nil, route.GetActions())
httpServ.Serve(l)
}
func main() {
Init()
}