forked from bfenetworks/bfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bfe.go
116 lines (99 loc) · 2.99 KB
/
bfe.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2019 The BFE Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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 (
"flag"
"fmt"
"path"
"runtime"
"time"
)
import (
"github.com/baidu/go-lib/log"
"github.com/baidu/go-lib/log/log4go"
)
import (
"github.com/bfenetworks/bfe/bfe_config/bfe_conf"
"github.com/bfenetworks/bfe/bfe_debug"
"github.com/bfenetworks/bfe/bfe_server"
"github.com/bfenetworks/bfe/bfe_util"
)
var (
help *bool = flag.Bool("h", false, "to show help")
confRoot *string = flag.String("c", "./conf", "root path of configuration")
logPath *string = flag.String("l", "./log", "dir path of log")
stdOut *bool = flag.Bool("s", false, "to show log in stdout")
showVersion *bool = flag.Bool("v", false, "to show version of bfe")
showVerbose *bool = flag.Bool("V", false, "to show verbose information about bfe")
debugLog *bool = flag.Bool("d", false, "to show debug log (otherwise >= info)")
)
var version string
var commit string
func main() {
var err error
var config bfe_conf.BfeConfig
var logSwitch string
flag.Parse()
if *help {
flag.PrintDefaults()
return
}
if *showVersion {
fmt.Printf("bfe version: %s\n", version)
return
}
if *showVerbose {
fmt.Printf("bfe version: %s\n", version)
fmt.Printf("go version: %s\n", runtime.Version())
fmt.Printf("git commit: %s\n", commit)
return
}
// debug switch
if *debugLog {
logSwitch = "DEBUG"
bfe_debug.DebugIsOpen = true
} else {
logSwitch = "INFO"
bfe_debug.DebugIsOpen = false
}
// initialize log
log4go.SetLogBufferLength(10000)
log4go.SetLogWithBlocking(false)
log4go.SetLogFormat(log4go.FORMAT_DEFAULT_WITH_PID)
log4go.SetSrcLineForBinLog(false)
err = log.Init("bfe", logSwitch, *logPath, *stdOut, "midnight", 7)
if err != nil {
fmt.Printf("bfe: err in log.Init():%s\n", err.Error())
bfe_util.AbnormalExit()
}
log.Logger.Info("bfe[version:%s] start", version)
// load server config
confPath := path.Join(*confRoot, "bfe.conf")
config, err = bfe_conf.BfeConfigLoad(confPath, *confRoot)
if err != nil {
log.Logger.Error("main(): in BfeConfigLoad():%s", err.Error())
bfe_util.AbnormalExit()
}
// set maximum number of cpus
runtime.GOMAXPROCS(config.Server.MaxCpus)
// set log level
bfe_debug.SetDebugFlag(config.Server)
// start and serve
if err = bfe_server.StartUp(config, version, *confRoot); err != nil {
log.Logger.Error("main(): bfe_server.StartUp(): %s", err.Error())
}
// waiting for logger finish jobs
time.Sleep(1 * time.Second)
log.Logger.Close()
}