Exemple #1
0
func doMain() error {
	if err := logging.Init(); err != nil {
		return err
	}

	// Schedule cleanup actions
	handleSignals()
	addExitFunc(func() {
		if err := logging.Close(); err != nil {
			log.Debugf("Error closing log: %v", err)
		}
	})
	addExitFunc(quitSystray)

	i18nInit()
	if showui {
		if err := configureSystemTray(); err != nil {
			return err
		}
	}
	displayVersion()

	parseFlags()

	cfg, err := config.Init(packageVersion)
	if err != nil {
		return fmt.Errorf("Unable to initialize configuration: %v", err)
	}
	go func() {
		err := config.Run(func(updated *config.Config) {
			configUpdates <- updated
		})
		if err != nil {
			exit(err)
		}
	}()
	if *help || cfg.Addr == "" || (cfg.Role != "server" && cfg.Role != "client") {
		flag.Usage()
		return fmt.Errorf("Wrong arguments")
	}

	finishProfiling := profiling.Start(cfg.CpuProfile, cfg.MemProfile)
	defer finishProfiling()

	// Configure stats initially
	if err := statreporter.Configure(cfg.Stats); err != nil {
		return err
	}

	log.Debug("Running proxy")
	if cfg.IsDownstream() {
		// This will open a proxy on the address and port given by -addr
		go runClientProxy(cfg)
	} else {
		go runServerProxy(cfg)
	}

	return waitForExit()
}
Exemple #2
0
func logPanic(msg string) {
	cfg, err := config.Init(packageVersion)
	if err != nil {
		panic("Error initializing config")
	}
	if err := logging.Init(); err != nil {
		panic("Error initializing logging")
	}

	<-logging.Configure("", "", cfg.InstanceId, version, revisionDate)

	log.Error(msg)

	logging.Flush()
	_ = logging.Close()
}