-
-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (47 loc) · 2.03 KB
/
main.go
File metadata and controls
64 lines (47 loc) · 2.03 KB
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
package main
import (
"errors"
"flag"
"runtime/debug"
"github.com/mariocandela/beelzebub/v3/builder"
"github.com/mariocandela/beelzebub/v3/parser"
log "github.com/sirupsen/logrus"
)
func main() {
var (
quit = make(chan struct{})
configurationsCorePath string
configurationsServicesDirectory string
memLimitMiB int
)
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
flag.IntVar(&memLimitMiB, "memLimitMiB", 100, "Process Memory in MiB (default 100, set to -1 to use system default)")
flag.Parse()
if memLimitMiB > 0 {
// SetMemoryLimit takes an int64 value for the number of bytes.
// bytes value = MiB value * 1024 * 1024
debug.SetMemoryLimit(int64(memLimitMiB * 1024 * 1024))
}
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
coreConfigurations, err := parser.ReadConfigurationsCore()
failOnError(err, "Error during ReadConfigurationsCore: ")
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
failOnError(err, "Error during ReadConfigurationsServices: ")
if len(beelzebubServicesConfiguration) == 0 && !coreConfigurations.Core.BeelzebubCloud.Enabled {
failOnError(errors.New("no services configured: provide a services directory, set BEELZEBUB_SERVICES_CONFIG, or enable beelzebub-cloud"), "Error during ReadConfigurationsServices: ")
}
beelzebubBuilder := builder.NewBuilder()
director := builder.NewDirector(beelzebubBuilder)
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
failOnError(err, "Error during BuildBeelzebub: ")
err = beelzebubBuilder.Run()
failOnError(err, "Error during run beelzebub core: ")
defer beelzebubBuilder.Close()
<-quit
}
func failOnError(err error, msg string) {
if err != nil {
log.Fatalf("%s: %s", msg, err)
}
}