Example #1
0
func main() {

	logLevel := flag.String("log_level", "info", "logger level")
	// parse cmd-line arguments
	flag.Parse()
	log.SetLevel(*logLevel)
	logger.Infof("comet ver: \"%s\" start", ver.Version)

	// init config
	if err := InitConfig(); err != nil {
		logger.Errorf("InitConfig() error(%v)", err)
		return
	}
	//init db config
	if err := db.InitConfig(); err != nil {
		logger.Error("db-InitConfig() wrror(%v)", err)
		return
	}

	db.InitDB()
	defer db.CloseDB()

	// set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// start pprof
	perf.Init(Conf.PprofBind)
	// create channel
	// if process exit, close channel
	UserChannel = NewChannelList()
	defer UserChannel.Close()
	// start stats
	StartStats()
	// start rpc
	StartRPC()
	// start comet
	StartComet()
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		logger.Errorf("InitZookeeper() error(%v)", err)
		return
	}
	// if process exit, close zk
	defer zkConn.Close()
	// init process
	// sleep one second, let the listen start
	time.Sleep(time.Second)
	if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
		logger.Errorf("process.Init(\"%s\", \"%s\", \"%s\") error(%v)", Conf.User, Conf.Dir, Conf.PidFile, err)
		return
	}
	// init signals, block wait signals
	signalCH := InitSignal()
	HandleSignal(signalCH)
	// exit
	logger.Info("comet stop")
}
Example #2
0
func main() {
	logLevel := flag.String("log_level", "info", "logger level")
	flag.Parse()
	log.SetLevel(*logLevel)
	logger.Infof("message ver: \"%s\" start", ver.Version)

	if err := InitConfig(); err != nil {
		logger.Errorf("InitConfig() error(%v)", err)
		return
	}
	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// start pprof http
	perf.Init(Conf.PprofBind)
	// Initialize redis
	if err := InitStorage(); err != nil {
		logger.Errorf("InitStorage() error(%v)", err)
		return
	}
	// init rpc service
	InitRPC()
	// init zookeeper
	zk, err := InitZK()
	if err != nil {
		logger.Errorf("InitZK() error(%v)", err)
		if zk != nil {
			zk.Close()
		}
		return
	}
	// if process exit, close zk
	defer zk.Close()
	// init process
	// sleep one second, let the listen start
	time.Sleep(time.Second)
	if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
		logger.Errorf("process.Init(\"%s\", \"%s\", \"%s\") error(%v)", Conf.User, Conf.Dir, Conf.PidFile, err)
		return
	}
	// init signals, block wait signals
	sig := InitSignal()
	HandleSignal(sig)
	// exit
	logger.Info("message stop")
}
Example #3
0
func main() {
	var err error
	// Parse cmd-line arguments
	logLevel := flag.String("log_level", "info", "logger level")
	flag.Parse()
	log.SetLevel(*logLevel)

	logger.Infof("web ver: \"%s\" start", ver.Version)

	if err = app.InitConfig(); err != nil {
		logger.Errorf("InitConfig() error(%v)", err)
		return
	}
	//init db config
	if err = db.InitConfig(); err != nil {
		logger.Error("db-InitConfig() error(%v)", err)
		return
	}
	// Set max routine
	runtime.GOMAXPROCS(app.Conf.MaxProc)
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		logger.Errorf("InitZookeeper() error(%v)", err)
		return
	}
	// if process exit, close zk
	defer zkConn.Close()
	// start pprof http
	perf.Init(app.Conf.PprofBind)
	// Init network router
	if app.Conf.Router != "" {
		if err := InitRouter(); err != nil {
			logger.Errorf("InitRouter() failed(%v)", err)
			return
		}
	}

	db.InitDB()
	defer db.CloseDB()

	app.InitRedisStorage()

	// start http listen.
	StartHTTP()
	// init process
	// sleep one second, let the listen start
	time.Sleep(time.Second)
	if err = process.Init(app.Conf.User, app.Conf.Dir, app.Conf.PidFile); err != nil {
		logger.Errorf("process.Init() error(%v)", err)
		return
	}

	defer db.MySQL.Close()

	//初始化配额配置
	app.InitQuotaAll()
	go app.LoadQuotaAll()

	//启动扫描过期文件
	go app.ScanExpireFileLink()

	// init signals, block wait signals
	signalCH := InitSignal()
	HandleSignal(signalCH)

	logger.Info("web stop")
}