2022-05-08 20:49:53 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-06-01 00:15:21 +02:00
|
|
|
"flag"
|
2025-03-24 05:16:34 +11:00
|
|
|
"runtime/debug"
|
|
|
|
|
2023-10-08 17:45:31 +02:00
|
|
|
"github.com/mariocandela/beelzebub/v3/builder"
|
|
|
|
"github.com/mariocandela/beelzebub/v3/parser"
|
2023-06-01 00:15:21 +02:00
|
|
|
|
2022-05-08 20:49:53 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-06-26 11:55:49 -05:00
|
|
|
var (
|
2023-10-05 21:40:34 +02:00
|
|
|
quit = make(chan struct{})
|
|
|
|
configurationsCorePath string
|
2023-06-26 11:55:49 -05:00
|
|
|
configurationsServicesDirectory string
|
2025-03-24 05:16:34 +11:00
|
|
|
memLimitMiB int
|
2023-10-05 21:40:34 +02:00
|
|
|
)
|
2023-06-01 00:15:21 +02:00
|
|
|
|
|
|
|
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
|
|
|
|
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
|
2025-03-24 05:16:34 +11:00
|
|
|
flag.IntVar(&memLimitMiB, "memLimitMiB", 100, "Process Memory in MiB (default 100, set to -1 to use system default)")
|
2023-06-01 00:15:21 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
2025-03-24 05:16:34 +11:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2023-06-01 00:15:21 +02:00
|
|
|
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
|
2022-05-08 20:49:53 +02:00
|
|
|
|
2022-05-12 22:46:15 +02:00
|
|
|
coreConfigurations, err := parser.ReadConfigurationsCore()
|
2023-06-26 11:55:49 -05:00
|
|
|
failOnError(err, "Error during ReadConfigurationsCore: ")
|
2022-05-08 20:49:53 +02:00
|
|
|
|
2022-05-12 22:46:15 +02:00
|
|
|
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
2023-06-26 11:55:49 -05:00
|
|
|
failOnError(err, "Error during ReadConfigurationsServices: ")
|
2022-05-21 11:43:10 +02:00
|
|
|
|
2022-11-04 20:06:50 +01:00
|
|
|
beelzebubBuilder := builder.NewBuilder()
|
2022-05-08 20:49:53 +02:00
|
|
|
|
2022-11-04 20:06:50 +01:00
|
|
|
director := builder.NewDirector(beelzebubBuilder)
|
2022-05-08 20:49:53 +02:00
|
|
|
|
2022-11-04 20:06:50 +01:00
|
|
|
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
2023-06-26 11:55:49 -05:00
|
|
|
failOnError(err, "Error during BuildBeelzebub: ")
|
2023-06-01 00:15:21 +02:00
|
|
|
|
|
|
|
err = beelzebubBuilder.Run()
|
2023-06-26 11:55:49 -05:00
|
|
|
failOnError(err, "Error during run beelzebub core: ")
|
2022-05-08 20:49:53 +02:00
|
|
|
|
2022-11-04 20:06:50 +01:00
|
|
|
defer beelzebubBuilder.Close()
|
|
|
|
|
2022-05-08 20:49:53 +02:00
|
|
|
<-quit
|
|
|
|
}
|
2022-05-21 11:43:10 +02:00
|
|
|
|
|
|
|
func failOnError(err error, msg string) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("%s: %s", msg, err)
|
|
|
|
}
|
|
|
|
}
|