예제 #1
0
파일: lvs_test.go 프로젝트: nanopack/portal
func initialize() {
	ifIptables, err := exec.Command("iptables", "-S").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run iptables - %s%v\n", ifIptables, err.Error())
		skip = true
	}
	ifIpvsadm, err := exec.Command("ipvsadm", "--version").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run ipvsadm - %s%v\n", ifIpvsadm, err.Error())
		skip = true
	}

	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	if !skip {
		// todo: find more friendly way to clear crufty rules only
		err = exec.Command("iptables", "-F", "portal").Run()
		if err != nil {
			fmt.Printf("Failed to clear iptables - %v\n", err.Error())
			os.Exit(1)
		}
		err = exec.Command("ipvsadm", "-C").Run()
		if err != nil {
			fmt.Printf("Failed to clear ipvsadm - %v\n", err.Error())
			os.Exit(1)
		}

		balance.Init()
	}
}
예제 #2
0
////////////////////////////////////////////////////////////////////////////////
// PRIVS
////////////////////////////////////////////////////////////////////////////////
func nginxPrep() bool {
	nginx, err := exec.Command("which", "nginx").CombinedOutput()
	// nginx, err := exec.Command("nginx", "-v").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run nginx - %s%v\n", nginx, err.Error())
		return false
	}

	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))

	config.Balancer = "nginx"
	config.WorkDir = "/tmp/portal"

	// todo: write config file for tests to /tmp/portal/portal-nginx.conf

	err = balance.Init()
	// skip tests if failed to init
	if err != nil {
		fmt.Printf("Failed to initialize nginx - %s%v\n", nginx, err.Error())
		return false
	}
	return true
}
예제 #3
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
}