예제 #1
0
func TestMain(m *testing.M) {
	// clean test dir
	os.RemoveAll("/tmp/cliTest")

	// manually configure
	initialize()

	// start api
	go api.StartApi()
	<-time.After(3 * time.Second)
	rtn := m.Run()

	// clean test dir
	os.RemoveAll("/tmp/cliTest")

	os.Exit(rtn)
}
예제 #2
0
파일: commands.go 프로젝트: nanopack/portal
func startPortal(ccmd *cobra.Command, args []string) error {
	if config.LogFile == "" {
		config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))
	} else {
		var err error
		config.Log, err = lumber.NewFileLogger(config.LogFile, lumber.LvlInt(config.LogLevel), lumber.ROTATE, 5000, 9, 100)
		if err != nil {
			config.Log.Fatal("File logger init failed - %v", err)
			return fmt.Errorf("")
		}
	}

	// ensure proxy ports are unique. we need to check because tls will not listen
	// until a cert is added. we want it to break sooner.
	if config.RouteHttp == config.RouteTls {
		config.Log.Fatal("Proxy addresses must be unique")
		return fmt.Errorf("")
	}
	// need ':' in case tls is double apiport (8080, 80)
	apiPort := fmt.Sprintf(":%s", config.ApiPort)
	if strings.HasSuffix(config.RouteTls, apiPort) {
		config.Log.Fatal("TLS proxy address must be unique")
		return fmt.Errorf("")
	}

	// initialize database
	err := database.Init()
	if err != nil {
		config.Log.Fatal("Database init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize balancer
	err = balance.Init()
	if err != nil {
		config.Log.Fatal("Balancer init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize proxymgr
	err = proxymgr.Init()
	if err != nil {
		config.Log.Fatal("Proxymgr init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize vipmgr
	err = vipmgr.Init()
	if err != nil {
		config.Log.Fatal("Vipmgr init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize cluster
	err = cluster.Init()
	if err != nil {
		config.Log.Fatal("Cluster init failed - %v", err)
		return fmt.Errorf("")
	}

	go sigHandle()

	// start api
	err = api.StartApi()
	if err != nil {
		config.Log.Fatal("Api start failed - %v", err)
		return fmt.Errorf("")
	}
	return nil
}