예제 #1
0
파일: flashlight.go 프로젝트: kidaa/lantern
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()
}
예제 #2
0
func _main() {
	err := doMain()
	if err != nil {
		log.Error(err)
	}
	log.Debug("Lantern stopped")
	logging.Close()
	os.Exit(0)
}
예제 #3
0
파일: main.go 프로젝트: 2722/lantern
func _main() {
	if err := doMain(); err != nil {
		log.Error(err)
	}
	log.Debug("Lantern stopped")

	if err := logging.Close(); err != nil {
		log.Debugf("Error closing log: %v", err)
	}
	os.Exit(0)
}
예제 #4
0
파일: main.go 프로젝트: 2722/lantern
func doMain() error {
	if err := logging.EnableFileLogging(); 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
		}
	}

	// Run below in separate goroutine as config.Init() can potentially block when Lantern runs
	// for the first time. User can still quit Lantern through systray menu when it happens.
	go func() {
		if *proxyAll {
			// If proxyall flag was supplied, force proxying of all
			settings.SetProxyAll(true)
		}

		listenAddr := *addr
		if listenAddr == "" {
			listenAddr = "localhost:8787"
		}
		err := flashlight.Run(
			listenAddr,
			"localhost:8788",
			*configdir,
			*stickyConfig,
			settings.GetProxyAll,
			flagsAsMap(),
			beforeStart,
			afterStart,
			onConfigUpdate,
			exit)
		if err != nil {
			exit(err)
			return
		}
	}()

	return waitForExit()
}
예제 #5
0
파일: main.go 프로젝트: 2722/lantern
func logPanic(msg string) {
	cfg, err := config.Init(flashlight.PackageVersion, *configdir, *stickyConfig, flagsAsMap())
	if err != nil {
		panic("Error initializing config")
	}
	if err := logging.EnableFileLogging(); err != nil {
		panic("Error initializing logging")
	}

	<-logging.Configure(eventual.DefaultGetter(""), "", cfg.Client.DeviceID, flashlight.Version, flashlight.RevisionDate)

	log.Error(msg)

	logging.Flush()
	_ = logging.Close()
}
예제 #6
0
파일: flashlight.go 프로젝트: kidaa/lantern
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()
}