Skip to content

Commit

Permalink
Resolved bfenetworks#800 support test configuration
Browse files Browse the repository at this point in the history
Signed-off-by: kwanhur <[email protected]>
  • Loading branch information
kwanhur committed Sep 25, 2021
1 parent e06b45c commit c7bb9c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 14 additions & 3 deletions bfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
showVersion = flag.Bool("v", false, "to show version of bfe")
showVerbose = flag.Bool("V", false, "to show verbose information about bfe")
debugLog = flag.Bool("d", false, "to show debug log (otherwise >= info)")
testConf = flag.Bool("t", false, "test configuration and exit")
)

var version string
Expand Down Expand Up @@ -84,23 +85,33 @@ func main() {
log4go.SetLogFormat(log4go.FORMAT_DEFAULT_WITH_PID)
log4go.SetSrcLineForBinLog(false)

err = log.Init("bfe", logSwitch, *logPath, *stdOut, "midnight", 7)
err = log.Init("bfe", logSwitch, *logPath, *stdOut || *testConf, "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)
if !*testConf {
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())
if *testConf {
fmt.Printf("bfe: configuration file %s test failed\n", confPath)
}
bfe_util.AbnormalExit()
}

// maximum number of CPUs (GOMAXPROCS) defaults to runtime.CPUNUM
if *testConf {
fmt.Printf("bfe: configuration file %s test is successful\n", confPath)
bfe_util.NormalExit()
}

// maximum number of CPUs (GOMAXPROCS) defaults to runtime.CPUNUM
// if running on machine, or CPU quota if running on container
// (with the help of "go.uber.org/automaxprocs").
// here, we change maximum number of cpus if the MaxCpus is positive.
Expand Down
12 changes: 10 additions & 2 deletions bfe_util/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ import (
"github.com/baidu/go-lib/log"
)

func AbnormalExit() {
func exit(code int) {
// waiting for logger finish jobs
log.Logger.Close()
// exit
os.Exit(1)
os.Exit(code)
}

func AbnormalExit() {
exit(1)
}

func NormalExit() {
exit(0)
}

0 comments on commit c7bb9c6

Please sign in to comment.