MCPcopy
hub / github.com/alibaba/MongoShake / main

Function main

cmd/receiver/receiver.go:23–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21type Exit struct{ Code int }
22
23func main() {
24 var err error
25 defer handleExit()
26 defer func() {
27 if l.Logger != nil {
28 _ = l.Logger.Close()
29 }
30 }()
31
32 // argument options
33 configuration := flag.String("conf", "", "configure file absolute path")
34 verbose := flag.Int("verbose", 0, "where log goes to: 0 - file,1 - file+stdout,2 - stdout")
35 flag.Parse()
36
37 if *configuration == "" {
38 fmt.Println(utils.BRANCH)
39 panic(Exit{0})
40 }
41
42 var file *os.File
43 if file, err = os.Open(*configuration); err != nil {
44 crash(fmt.Sprintf("Configure file open failed. %v", err), -1)
45 }
46
47 configure := nimo.NewConfigLoader(file)
48 configure.SetDateFormat(utils.GolangSecurityTime)
49 if err := configure.Load(&conf.Options); err != nil {
50 crash(fmt.Sprintf("Configure file %s parse failed. %v", *configuration, err), -2)
51 }
52
53 // verify receiver options and revise
54 if err = sanitizeOptions(); err != nil {
55 crash(fmt.Sprintf("Conf.Options check failed: %s", err.Error()), -4)
56 }
57
58 if err := utils.InitialLoggerWithRotation(conf.Options.LogDirectory,
59 conf.Options.LogFileName, conf.Options.LogLevel, conf.Options.LogFlush,
60 *verbose, conf.Options.LogMaxSizeMb, conf.Options.LogMaxAge); err != nil {
61 crash(fmt.Sprintf("initial log.dir[%v] log.name[%v] failed[%v].", conf.Options.LogDirectory,
62 conf.Options.LogFileName, err), -2)
63 }
64
65 nimo.Profiling(int(conf.Options.SystemProfilePort))
66 signalProfile, _ := strconv.Atoi(utils.SIGNALPROFILE)
67 signalStack, _ := strconv.Atoi(utils.SIGNALSTACK)
68 if signalProfile > 0 {
69 nimo.RegisterSignalForProfiling(syscall.Signal(signalProfile)) // syscall.SIGUSR2
70 nimo.RegisterSignalForPrintStack(syscall.Signal(signalStack), func(bytes []byte) { // syscall.SIGUSR1
71 l.Logger.Infof("%s", string(bytes))
72 })
73 }
74
75 startup()
76
77 select {}
78}
79
80func sanitizeOptions() error {

Callers

nothing calls this directly

Calls 9

sanitizeOptionsFunction · 0.85
PrintlnMethod · 0.80
ErrorMethod · 0.80
InfofMethod · 0.80
handleExitFunction · 0.70
crashFunction · 0.70
startupFunction · 0.70
StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected