Exemplo n.º 1
0
func Run(mods ...module.Module) {
	// logger
	if conf.LogLevel != "" {
		logger, err := log.New(conf.LogLevel, conf.LogPath)
		if err != nil {
			panic(err)
		}
		log.Export(logger)
		defer logger.Close()
	}

	log.Release("Leaf starting up")

	// module
	for i := 0; i < len(mods); i++ {
		module.Register(mods[i])
	}
	module.Init()

	// cluster
	cluster.Init()

	// console
	console.Init()

	// close
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	sig := <-c
	log.Release("Leaf closing down (signal: %v)", sig)
	console.Destroy()
	cluster.Destroy()
	module.Destroy()
}
Exemplo n.º 2
0
func Run(mods ...module.Module) { //...不定参数语法,参数类型都为module.Module
	// logger
	if conf.LogLevel != "" { //日志级别不为空
		logger, err := log.New(conf.LogLevel, conf.LogPath) //创建一个logger
		if err != nil {
			panic(err)
		}
		log.Export(logger)   //替换默认的gLogger
		defer logger.Close() //Run函数返回,关闭logger
	}

	log.Release("Leaf starting up") //关键日志

	// module
	for i := 0; i < len(mods); i++ { //遍历传入的所有module
		module.Register(mods[i]) //注册module
	}
	module.Init() //初始化模块,并执行各个模块(在各个不同的goroutine里)

	// console
	console.Init() //初始化控制台

	// close
	c := make(chan os.Signal, 1)                       //新建一个管道用于接收系统Signal
	signal.Notify(c, os.Interrupt, os.Kill)            //监听SIGINT和SIGKILL信号(linux下叫这个名字)
	sig := <-c                                         //读信号,没有信号时会阻塞goroutine
	log.Release("Leaf closing down (signal: %v)", sig) //关键日志 服务器关闭
	console.Destroy()                                  //销毁控制台
	module.Destroy()                                   //销毁模块
}
Exemplo n.º 3
0
Arquivo: leaf.go Projeto: Jasonix/leaf
func Run(mods ...module.Module) {
	// logger
	if conf.LogLevel != "" {
		logger, err := log.New(conf.LogLevel, conf.LogPath)
		if err != nil {
			panic(err)
		}
		log.Export(logger)
		defer logger.Close()
	}

	log.Release("Leaf starting up")

	// profile
	if conf.EnableProfiling {
		now := time.Now()

		filename := fmt.Sprintf("%d%02d%02d_%02d_%02d_%02d.prof",
			now.Year(),
			now.Month(),
			now.Day(),
			now.Hour(),
			now.Minute(),
			now.Second())

		f, err := os.Create(path.Join(conf.ProfilePath, filename))
		if err != nil {
			log.Fatal("%v", err)
		}

		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	// module
	for i := 0; i < len(mods); i++ {
		module.Register(mods[i])
	}
	module.Init()

	// close
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	sig := <-c
	log.Release("Leaf closing down (signal: %v)", sig)
	module.Destroy()
}