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) }
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() }
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)) } }