func main() { defer func() { cleanup() if err := recover(); err != nil { fmt.Println(err) debug.PrintStack() } }() setupLogging(options.logLevel, options.logFile) setupProfiler() ticker := time.NewTicker(time.Second * time.Duration(options.tick)) go runWatchdog(ticker) defer ticker.Stop() e := engine.NewEngine(options.configFile).LoadConfigFile() e.RegisterHttpApi("/ver", func(w http.ResponseWriter, req *http.Request, params map[string]interface{}) (interface{}, error) { output := make(map[string]interface{}) output["ver"] = BuildID return output, nil }) e.ServeForever() shutdown() }
func init() { parseFlags() if options.showVersion { server.ShowVersionAndExit() } server.SetupLogging(options.logFile, options.logLevel, options.crashLogFile, options.alarmLogSock, options.alarmTag) // thrift lib use "log", so we also need to customize its behavior _log.SetFlags(_log.Ldate | _log.Ltime | _log.Lshortfile) if options.kill { s := server.NewServer("fae") s.LoadConfig(options.configFile) s.Launch() // stop new requests engine.NewEngine(). LoadConfig(s.Conf). UnregisterEtcd() // finish all outstanding RPC sessions if err := signal.SignalProcessByPidFile(options.lockFile, syscall.SIGUSR1); err != nil { fmt.Fprintf(os.Stderr, "stop failed: %s\n", err) os.Exit(1) } cleanup() // TODO wait till that faed process terminates, who will do the cleanup fmt.Println("faed killed") os.Exit(0) } if options.lockFile != "" { if locking.InstanceLocked(options.lockFile) { fmt.Fprintf(os.Stderr, "Another instance is running, exit...\n") os.Exit(1) } locking.LockInstance(options.lockFile) } }
func main() { defer func() { cleanup() if err := recover(); err != nil { fmt.Println(err) debug.PrintStack() } }() if options.cpuprof || options.memprof { cf := &profiler.Config{ Quiet: true, ProfilePath: "prof", CPUProfile: options.cpuprof, MemProfile: options.memprof, BlockProfile: options.blockprof, } defer profiler.Start(cf).Stop() } log.Info("%s", ` ____ __ ____ ( ___) /__\ ( ___) )__) /(__)\ )__) (__) (__)(__) (____)`) s := server.NewServer("fae") s.LoadConfig(options.configFile) s.Launch() go server.RunSysStats(time.Now(), options.tick) engineRunner = engine.NewEngine() signal.RegisterSignalHandler(syscall.SIGINT, func(sig os.Signal) { shutdown() engineRunner.StopRpcServe() }) engineRunner.LoadConfig(s.Conf). ServeForever() }
func main() { defer func() { cleanup() if err := recover(); err != nil { fmt.Println(err) debug.PrintStack() } }() setupLogging(options.logLevel, options.logFile) setupProfiler() ticker := time.NewTicker(time.Second * time.Duration(options.tick)) go runWatchdog(ticker) defer ticker.Stop() engine.NewEngine(options.configFile). LoadConfigFile(). ServeForever() shutdown() }