func init() { pflag.DurationVar(&config.TickerTime, "ticker-time", 60*time.Second, "Ticker time.") pflag.DurationVar(&config.DeleteTime, "delete-time", 60*time.Minute, "Time before deleting undesired units.") pflag.DurationVar(&config.UpdateCooldownTime, "update-cooldown-time", 15*time.Minute, "Time between updates of changed units.") pflag.StringVar(&config.MachineTag, "machine-tag", "", "The machine-tag to filter for.") pflag.StringVar(&config.UnitTemplate, "unit-template", "", "The template to render for new units. Prefix with @ to load from a file.") pflag.StringVar(&config.UnitPrefix, "unit-prefix", "", "The prefix for the units to identify.") pflag.StringVar(&glogFlags.logToStderr, "logtostderr", "true", "log to standard error instead of files") pflag.StringVar(&glogFlags.alsoLogToStderr, "alsologtostderr", "false", "log to standard error as well as files") pflag.StringVarP(&glogFlags.verbosity, "verbose", "v", "1", "log level for V logs") pflag.StringVar(&glogFlags.vmodule, "vmodule", "", "comma-separated list of pattern=N settings for file-filtered logging") pflag.StringVar(&glogFlags.logBacktraceAt, "log_backtrace_at", "", "when logging hits line file:N, emit a stack trace") }
func (mmsd *mmsdService) Run() { flag.BoolVarP(&mmsd.Verbose, "verbose", "v", mmsd.Verbose, "Set verbosity level") flag.IPVar(&mmsd.MarathonIP, "marathon-ip", mmsd.MarathonIP, "Marathon endpoint TCP IP address") flag.UintVar(&mmsd.MarathonPort, "marathon-port", mmsd.MarathonPort, "Marathon endpoint TCP port number") flag.DurationVar(&mmsd.ReconnectDelay, "reconnect-delay", mmsd.ReconnectDelay, "Marathon reconnect delay") flag.StringVar(&mmsd.RunStateDir, "run-state-dir", mmsd.RunStateDir, "Path to directory to keep run-state") flag.StringVar(&mmsd.FilterGroups, "filter-groups", mmsd.FilterGroups, "Application group filter") flag.IPVar(&mmsd.ManagedIP, "managed-ip", mmsd.ManagedIP, "IP-address to manage for mmsd") flag.BoolVar(&mmsd.GatewayEnabled, "enable-gateway", mmsd.GatewayEnabled, "Enables gateway support") flag.IPVar(&mmsd.GatewayAddr, "gateway-bind", mmsd.GatewayAddr, "gateway bind address") flag.UintVar(&mmsd.GatewayPortHTTP, "gateway-port-http", mmsd.GatewayPortHTTP, "gateway port for HTTP") flag.UintVar(&mmsd.GatewayPortHTTPS, "gateway-port-https", mmsd.GatewayPortHTTPS, "gateway port for HTTPS") flag.BoolVar(&mmsd.FilesEnabled, "enable-files", mmsd.FilesEnabled, "enables file based service discovery") flag.BoolVar(&mmsd.UDPEnabled, "enable-udp", mmsd.UDPEnabled, "enables UDP load balancing") flag.BoolVar(&mmsd.TCPEnabled, "enable-tcp", mmsd.TCPEnabled, "enables haproxy TCP load balancing") flag.BoolVar(&mmsd.LocalHealthChecks, "enable-health-checks", mmsd.LocalHealthChecks, "Enable local health checks (if available) instead of relying on Marathon health checks alone.") flag.StringVar(&mmsd.HaproxyBin, "haproxy-bin", mmsd.HaproxyBin, "path to haproxy binary") flag.StringVar(&mmsd.HaproxyTailCfg, "haproxy-cfgtail", mmsd.HaproxyTailCfg, "path to haproxy tail config file") flag.IPVar(&mmsd.ServiceAddr, "haproxy-bind", mmsd.ServiceAddr, "haproxy management port") flag.UintVar(&mmsd.HaproxyPort, "haproxy-port", mmsd.HaproxyPort, "haproxy management port") flag.BoolVar(&mmsd.DnsEnabled, "enable-dns", mmsd.DnsEnabled, "Enables DNS-based service discovery") flag.UintVar(&mmsd.DnsPort, "dns-port", mmsd.DnsPort, "DNS service discovery port") flag.BoolVar(&mmsd.DnsPushSRV, "dns-push-srv", mmsd.DnsPushSRV, "DNS service discovery to also push SRV on A") flag.StringVar(&mmsd.DnsBaseName, "dns-basename", mmsd.DnsBaseName, "DNS service discovery's base name") flag.DurationVar(&mmsd.DnsTTL, "dns-ttl", mmsd.DnsTTL, "DNS service discovery's reply message TTL") showVersionAndExit := flag.BoolP("version", "V", false, "Shows version and exits") flag.Usage = func() { showVersion() fmt.Fprintf(os.Stderr, "\nUsage: mmsd [flags ...]\n\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\n") } flag.Parse() if *showVersionAndExit { showVersion() os.Exit(0) } mmsd.setupHandlers() mmsd.setupEventBusListener() mmsd.setupHttpService() <-mmsd.quitChannel }
// NewServer creates a new http.Server instance based off the BaseConfiguration. // NewServer also handles reading the TOML configuration file and // providing/reading the command line flags. Because of this // NewServer should always be called after all flags have been defined. func NewServer(conf *BaseConfiguration) http.Server { // TOML configuration file can overwrite defaults tomlData, err := ioutil.ReadFile(os.Args[len(os.Args)-1]) if err != nil { defer Logger.Info("No conf. Skipping.") } else { if _, err := toml.Decode(string(tomlData), &conf); err != nil { defer Logger.Errorf("Configuration file could not be decoded. %s. Exiting...", err) } } // Flags can override config items // Server flags flag.StringVar(&conf.BindAddress, "BindAddress", conf.BindAddress, "Bind address.") flag.IntVar(&conf.BindPort, "BindPort", conf.BindPort, "HTTP bind port.") flag.DurationVar(&conf.ReadTimeout, "ReadTimeout", conf.ReadTimeout, "Read timeout.") flag.DurationVar(&conf.WriteTimeout, "WriteTimeout", conf.WriteTimeout, "Write timeout.") flag.IntVar(&conf.MaxHeaderBytes, "MaxHeaderBytes", conf.MaxHeaderBytes, "Max header bytes.") // Server Logger flags flag.StringVar(&conf.LogLevel, "LogLevel", conf.LogLevel, "Log level.") flag.StringVar(&conf.LogFile, "LogFile", conf.LogFile, "Log file.") // TLS related flags flag.IntVar(&conf.BindHttpsPort, "BindHttpsPort", conf.BindHttpsPort, "HTTPS bind port.") flag.StringVar(&conf.CertFile, "CertFile", conf.CertFile, "Cert file.") flag.StringVar(&conf.KeyFile, "KeyFile", conf.KeyFile, "Key file.") flag.Parse() // Logging specific work also injecting the logrus log into the Servers errorlog // BUG(ashcrow): This needs work!!! makeLogger(conf) Logger.Debugf("Final configuration: %+v", conf) w := Logger.Writer() defer w.Close() ServerErrorLogger = *log.New(w, "ServerErrorLogger", log.Lshortfile) // ------------- // Return the configured http.Server return http.Server{ Addr: fmt.Sprintf("%s:%d", conf.BindAddress, conf.BindPort), ReadTimeout: conf.ReadTimeout, WriteTimeout: conf.WriteTimeout, MaxHeaderBytes: conf.MaxHeaderBytes, ErrorLog: &ServerErrorLogger, } }
func init() { pflag.DurationVar(&config.TickerTime, "ticker-time", 15*time.Minute, "Ticker time.") pflag.BoolVar(&config.DryRun, "dry-run", true, "Write to STDOUT instead of InfluxDB") pflag.IntVar(&config.OWMcityID, "owm-city-id", 0, "Open Weather Map city ID") pflag.IntVar(&config.InfluxPort, "influx-port", 8086, "InfluxDB Port") pflag.StringVar(&config.InfluxHost, "influx-host", "localhost", "InfluxDB Port") pflag.StringVar(&config.InfluxUser, "influx-user", "", "InfluxDB User") pflag.StringVar(&config.InfluxDB, "influx-db", "", "InfluxDB Database") pflag.StringVar(&config.InfluxPassword, "influx-password", "", "InfluxDB Password") pflag.StringVar(&config.InfluxRetention, "influx-retention", "default", "InfluxDB Retention") pflag.StringVar(&config.DhtType, "dht-type", "DHT22", "DHT Type (DHT11, DHT22)") pflag.IntVar(&config.DhtPin, "dht-pin", 4, "Pin Number DHT Data is connected to") pflag.BoolVar(&config.DHTPerf, "dht-perf", false, "Run DHT read in Boost Performance Mode - true will result in needing sudo") pflag.IntVar(&config.DhtRetries, "dht-retries", 15, "Number of reading data retries") }