Ejemplo n.º 1
0
func (s *testAgentSuite) SetUpSuite(c *C) {
	// initial whole test environment
	configFile = "config.ini"
	resetAbsPath(&configFile)
	cfg, err := utils.InitConfigFromFile(configFile)
	c.Assert(err, IsNil)

	globalEnv = env.LoadRebornEnv(cfg)
	globalConn, err = globalEnv.NewCoordConn()
	c.Assert(err, IsNil)

	s.testSetExecPath(c)

	// remove all infos in coordinator first
	err = zkhelper.DeleteRecursive(globalConn, fmt.Sprintf("/zk/reborn/db_%s", globalEnv.ProductName()), -1)
	if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
		c.Assert(err, IsNil)
	}

	s.agentDashboard = s.testStartAgent(c, "127.0.0.1:39001", false)
	s.agentProxy = s.testStartAgent(c, "127.0.0.1:39002", false)
	s.agentStoreMaster = s.testStartAgent(c, "127.0.0.1:39003", false)
	s.agentStoreSlave = s.testStartAgent(c, "127.0.0.1:39004", false)

	s.testDashboard(c)

	s.testInitGroup(c)
	s.testInitSlots(c)
	s.testStoreAddServer(c)
}
Ejemplo n.º 2
0
func LoadConf(configFile string) (*Conf, error) {
	srvConf := &Conf{}
	conf, err := utils.InitConfigFromFile(configFile)
	if err != nil {
		log.Fatal(err)
	}

	srvConf.ProductName, _ = conf.ReadString("product", "test")
	if len(srvConf.ProductName) == 0 {
		log.Fatalf("invalid config: product entry is missing in %s", configFile)
	}
	srvConf.CoordinatorAddr, _ = conf.ReadString("coordinator_addr", "")
	if len(srvConf.CoordinatorAddr) == 0 {
		log.Fatalf("invalid config: need coordinator addr entry is missing in %s", configFile)
	}
	srvConf.CoordinatorAddr = strings.TrimSpace(srvConf.CoordinatorAddr)
	srvConf.Coordinator, _ = conf.ReadString("coordinator", "zookeeper")
	srvConf.StoreAuth, _ = conf.ReadString("store_auth", "")

	// below configs should be set from command flag. We will remove below code later.
	srvConf.NetTimeout, _ = conf.ReadInt("net_timeout", 5)
	srvConf.Proto, _ = conf.ReadString("proto", "tcp")

	srvConf.Addr, _ = conf.ReadString("addr", "")
	srvConf.HTTPAddr, _ = conf.ReadString("http_addr", "")
	srvConf.ProxyID, _ = conf.ReadString("proxy_id", "")
	srvConf.PidFile, _ = conf.ReadString("pidfile", "")

	srvConf.ProxyAuth, _ = conf.ReadString("proxy_auth", "")

	return srvConf, nil
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: vebin/reborn
func main() {
	log.SetLevelByString("info")

	args, err := docopt.Parse(usage, nil, true, "reborn agent v0.1", true)
	if err != nil {
		log.Fatal(err)
	}

	setStringFromOpt(&configFile, args, "-c")
	resetAbsPath(&configFile)

	cfg, err := utils.InitConfigFromFile(configFile)
	if err != nil {
		fatal(err)
	}

	globalEnv = env.LoadRebornEnv(cfg)
	globalConn, err = globalEnv.NewCoordConn()
	if err != nil {
		fatal(err)
	}

	setStringFromOpt(&addr, args, "--http-addr")

	agentID = genProcID()

	if err := addAgent(&agentInfo{
		ID:   agentID,
		Addr: addr,
		PID:  os.Getpid(),
	}); err != nil {
		fatal(err)
	}

	setStringFromOpt(&qdbConfigFile, args, "--qdb-config")
	resetAbsPath(&qdbConfigFile)

	setStringFromOpt(&redisConfigFile, args, "--redis-config")
	resetAbsPath(&redisConfigFile)

	if v := getStringArg(args, "--exec-path"); len(v) > 0 {
		path := os.ExpandEnv(fmt.Sprintf("${PATH}:%s", v))
		os.Setenv("PATH", path)
	}

	// set data dir
	setStringFromOpt(&dataDir, args, "--data-dir")
	resetAbsPath(&dataDir)

	os.MkdirAll(baseProcDataDir(), 0755)

	// set app log dir
	setStringFromOpt(&logDir, args, "--log-dir")
	resetAbsPath(&logDir)

	os.MkdirAll(baseProcLogDir(), 0755)

	// set app trash log dir
	os.MkdirAll(baseTrashLogDir(), 0755)

	// set output log file
	if v := getStringArg(args, "-L"); len(v) > 0 {
		log.SetHighlighting(false)
		log.SetOutputByName(v)
	}

	// set log level
	if v := getStringArg(args, "--log-level"); len(v) > 0 {
		log.SetLevelByString(v)
	}

	// set cpu
	if v := getStringArg(args, "--cpu"); len(v) > 0 {
		cpus, err = strconv.Atoi(v)
		if err != nil {
			fatal(err)
		}
	}

	runtime.GOMAXPROCS(cpus)

	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGTERM, os.Interrupt, os.Kill)
	go func() {
		<-c

		fatal("ctrl-c or SIGTERM found, exit")
	}()

	if args["--ha"].(bool) {
		setIntArgFromOpt(&haMaxRetryNum, args, "--ha-max-retry-num")
		setIntArgFromOpt(&haRetryDelay, args, "--ha-retry-delay")

		go startHA()
	}

	err = loadSavedProcs()
	if err != nil {
		log.Fatalf("restart agent using last saved processes err: %v", err)
	}

	clearProcFiles()

	go runCheckProcs()

	log.Infof("listening %s", addr)
	runHTTPServer()
}
Ejemplo n.º 4
0
func main() {
	log.SetLevelByString("info")

	args, err := docopt.Parse(usage, nil, true, "reborn config v0.1", true)
	if err != nil {
		log.Error(err)
	}

	if v := args["--pidfile"]; v != nil {
		pidFile = v.(string)
	}

	// set config file
	var configFile string
	var config *cfg.Cfg
	if args["-c"] != nil {
		configFile = args["-c"].(string)
		config, err = utils.InitConfigFromFile(configFile)
		if err != nil {
			Fatal(err)
		}
	} else {
		config, err = utils.InitConfig()
		if err != nil {
			Fatal(err)
		}
	}

	// load global vars
	globalEnv = env.LoadRebornEnv(config)
	globalConn = CreateCoordConn()

	// set output log file
	if args["-L"] != nil {
		log.SetHighlighting(false)
		log.SetOutputByName(args["-L"].(string))
	}

	// set log level
	if args["--log-level"] != nil {
		log.SetLevelByString(args["--log-level"].(string))
	}

	cmd := args["<command>"].(string)
	cmdArgs := args["<args>"].([]string)

	httpAddr := ":10086"
	if v := args["--http-addr"]; v != nil {
		httpAddr = v.(string)
	}

	go http.ListenAndServe(httpAddr, nil)

	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGTERM, os.Interrupt, os.Kill)
	go func() {
		<-c

		Fatal("ctrl-c or SIGTERM found, exit")
	}()

	utils.CreatePidFile(pidFile)

	err = runCommand(cmd, cmdArgs)
	if err != nil {
		log.Fatal(errors.ErrorStack(err))
	}
}