From 40b8bf25a15d3e5ca3982f9503c15f890dca9424 Mon Sep 17 00:00:00 2001 From: Aaron Meihm Date: Mon, 11 Sep 2017 15:02:42 -0500 Subject: [PATCH] loader: load configuration from external configuration file --- conf/mig-loader.cfg.inc | 39 +++++++++++++++++++++++++++++++++++++++ mig-loader/loader.go | 21 ++++++++++++--------- 2 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 conf/mig-loader.cfg.inc diff --git a/conf/mig-loader.cfg.inc b/conf/mig-loader.cfg.inc new file mode 100644 index 00000000..fa830afa --- /dev/null +++ b/conf/mig-loader.cfg.inc @@ -0,0 +1,39 @@ +; Sample MIG Loader configuration file + +[loader] + ; location of the mig api + api = "http://localhost:1664/api/v1/" + + ; comma delimited list of host:port proxies to use, if desired + ; the loader will attempt to try to proxies for manifest retrieval + ; proxies = "proxy1:8888,proxy2:8888" + + ; attempt to retrieve the public IP behind which the loader is running + discoverpublicip = off + + ; attempt to retrieve AWS metadata from the metadata service to include in the environment + ; sent to the API + discoverawsmeta = off + + ; the number of signatures required in a manifest for the manifest to be considered + ; valid + requiredsignatures = 1 + + ; Tags can be specified for a given loader at compile-time using the loader built-in + ; configuration TAGS value. Additional tags can be included in the configuration file + ; here if desired to override or extend the tags the loader has already been compiled + ; with. + ; tags = "tagname:tagvalue" + +[logging] + mode = "stdout" ; stdout | file | syslog + level = "debug" + +; for file logging +; file = "mig_scheduler.log" +; maxfilesize = 0 ; if > 0, log file will be rotated once it reaches size + +; for syslog, logs go into local3 +; host = "localhost" +; port = 514 +; protocol = "udp" diff --git a/mig-loader/loader.go b/mig-loader/loader.go index 9934b87d..75a599e6 100644 --- a/mig-loader/loader.go +++ b/mig-loader/loader.go @@ -391,13 +391,7 @@ func initContext() (err error) { } }() - ctx.Channels.Log = make(chan mig.Log, 37) - ctx.Logging, err = getLoggingConf() - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n", err) - os.Exit(1) - } - ctx.Logging, err = mig.InitLogger(ctx.Logging, "mig-loader") + ctx.Logging, err = mig.InitLogger(LOGGINGCONF, "mig-loader") if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) @@ -406,8 +400,6 @@ func initContext() (err error) { go func() { var stop bool for event := range ctx.Channels.Log { - // Also write the message to stderr to ease debugging - fmt.Fprintf(os.Stderr, "%v\n", event.Desc) stop, err = mig.ProcessLog(ctx.Logging, event) if err != nil { panic("unable to process log") @@ -538,16 +530,27 @@ func main() { var ( initialMode bool runService bool + confPath string checkOnly bool err error ) runtime.GOMAXPROCS(1) flag.BoolVar(&checkOnly, "c", false, "only check if agent is running") + flag.StringVar(&confPath, "f", configDefault(), "Load configuration from file") flag.BoolVar(&initialMode, "i", false, "initialization mode") flag.BoolVar(&runService, "s", false, "persistent service mode") flag.Parse() + ctx.Channels.Log = make(chan mig.Log, 37) + + err = configLoad(confPath) + if err != nil { + logInfo("warning: unable to load configuration from %v, using built-in configuration", confPath) + } else { + logInfo("using external configuration from %v", confPath) + } + if runService { err = serviceMode() if err != nil {