예제 #1
0
func main() {
	var err error
	// Parse cmd-line arguments
	flag.Parse()
	log.Info("web ver: \"%s\" start", ver.Version)
	if err = InitConfig(); err != nil {
		panic(err)
	}
	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// init log
	log.LoadConfiguration(Conf.Log)
	defer log.Close()
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		if zkConn != nil {
			zkConn.Close()
		}
		panic(err)
	}
	// start pprof http
	perf.Init(Conf.PprofBind)
	// start http listen.
	StartHTTP()
	// process init
	if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
		panic(err)
	}
	// init signals, block wait signals
	signalCH := InitSignal()
	HandleSignal(signalCH)
	log.Info("web stop")
}
예제 #2
0
func main() {
	var err error
	// parse cmd-line arguments
	flag.Parse()
	signalCH := InitSignal()
	// init config
	Conf, err = InitConfig(ConfFile)
	if err != nil {
		Log.Error("NewConfig(\"%s\") error(%v)", ConfFile, err)
		return
	}
	// set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// init log
	if Log, err = log.New(Conf.LogFile, Conf.LogLevel); err != nil {
		Log.Error("log.New(\"%s\", %s) error(%v)", Conf.LogFile, Conf.LogLevel, err)
		return
	}
	// if process exit, close log
	defer Log.Close()
	Log.Info("comet start")
	// create channel
	UserChannel = NewChannelList()
	// if process exit, close channel
	defer UserChannel.Close()
	// start stats
	StartStats()
	// start pprof
	perf.Init(Conf.PprofBind)
	// init message rpc, block until message rpc init.
	InitMessageRPC()
	// start rpc
	StartRPC()
	// start comet
	StartComet()
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		Log.Error("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 {
		Log.Error("process.Init() error(%v)", err)
		return
	}
	// init signals, block wait signals
	HandleSignal(signalCH)
	// exit
	Log.Info("comet stop")
}
예제 #3
0
func main() {
	// parse cmd-line arguments
	flag.Parse()
	glog.Infof("comet ver: \"%s\" start", ver.Version)
	defer glog.Flush()
	// init config
	if err := InitConfig(); err != nil {
		glog.Errorf("InitConfig() error(%v)", err)
		return
	}
	// 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
	if err := StartRPC(); err != nil {
		glog.Errorf("StartRPC() error(%v)", err)
		return
	}
	// start comet
	if err := StartComet(); err != nil {
		glog.Errorf("StartComet() error(%v)", err)
		return
	}
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		glog.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 {
		glog.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
	glog.Info("comet stop")
}
예제 #4
0
func main() {
	// parse cmd-line arguments
	flag.Parse()
	log.Info("comet ver: \"%s\" start", ver.Version)
	// init config
	if err := InitConfig(); err != nil {
		panic(err)
	}
	// set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// init log
	log.LoadConfiguration(Conf.Log)
	defer log.Close()
	// start pprof
	perf.Init(Conf.PprofBind)
	// create channel
	// if process exit, close channel
	UserChannel = NewChannelList()
	defer UserChannel.Close()
	// start stats
	StartStats()
	// start rpc
	if err := StartRPC(); err != nil {
		panic(err)
	}
	// start comet
	if err := StartComet(); err != nil {
		panic(err)
	}
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		if zkConn != nil {
			zkConn.Close()
		}
		panic(err)
	}
	// process init
	if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
		panic(err)
	}
	// init signals, block wait signals
	signalCH := InitSignal()
	HandleSignal(signalCH)
	// exit
	log.Info("comet stop")
}
예제 #5
0
func main() {
	var err error
	// Parse cmd-line arguments
	flag.Parse()
	defer glog.Flush()
	signalCH := InitSignal()
	// Load config
	Conf, err = NewConfig(ConfFile)
	if err != nil {
		glog.Errorf("NewConfig(\"%s\") error(%v)", ConfFile, err)
		return
	}
	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// start pprof http
	perf.Init(Conf.PprofBind)
	// Initialize redis
	if err = InitStorage(); err != nil {
		glog.Errorf("InitStorage() error(%v)", err)
		return
	}
	// Start rpc
	StartRPC()
	// init zookeeper
	zk, err := InitZK()
	if err != nil {
		glog.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 {
		glog.Errorf("process.Init() error(%v)", err)
		return
	}
	glog.Infof("message(%s) start", ver.Version)
	// init signals, block wait signals
	HandleSignal(signalCH)
	// exit
	glog.Info("message stop")
}
예제 #6
0
func main() {
	flag.Parse()
	glog.Infof("message ver: \"%s\" start", ver.Version)
	defer glog.Flush()
	if err := InitConfig(); err != nil {
		glog.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 {
		glog.Errorf("InitStorage() error(%v)", err)
		return
	}
	// init rpc service
	if err := InitRPC(); err != nil {
		glog.Errorf("InitRPC() error(%v)", err)
		return
	}
	// init zookeeper
	zk, err := InitZK()
	if err != nil {
		glog.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 {
		glog.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
	glog.Info("message stop")
}
예제 #7
0
func main() {
	var err error
	// Parse cmd-line arguments
	flag.Parse()
	defer glog.Flush()
	signalCH := InitSignal()
	// Load config
	Conf, err = NewConfig(ConfFile)
	if err != nil {
		glog.Errorf("NewConfig(\"%s\") error(%v)", ConfFile, err)
		return
	}
	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// init zookeeper
	zkConn, err := InitZK()
	if err != nil {
		glog.Errorf("InitZookeeper() error(%v)", err)
		return
	}
	// if process exit, close zk
	defer zkConn.Close()
	// start pprof http
	perf.Init(Conf.PprofBind)
	// Init network router
	if Conf.Router != "" {
		if err := InitRouter(); err != nil {
			glog.Errorf("InitRouter() failed(%v)", err)
			return
		}
	}
	// start http listen.
	StartHTTP()
	// 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 {
		glog.Errorf("process.Init() error(%v)", err)
		return
	}
	// init signals, block wait signals
	glog.Infof("web(%s) start", ver.Version)
	HandleSignal(signalCH)
	glog.Info("web stop")
}
예제 #8
0
func main() {
	var err error
	// Parse cmd-line arguments
	flag.Parse()
	signalCH := InitSignal()

	// Load config
	Conf, err = NewConfig(ConfFile)
	if err != nil {
		panic(err)
	}

	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)

	// Load log
	if Log, err = log.New(Conf.LogFile, Conf.LogLevel); err != nil {
		panic(err)
	}

	// 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 {
		Log.Error("process.Init() error(%v)", err)
		os.Exit(-1)
	}

	// start pprof http
	perf.Init(Conf.PprofBind)

	// Initialize redis
	InitRedis()

	// Start rpc
	Log.Info("Message service start")
	go StartRPC()

	// init signals, block wait signals
	HandleSignal(signalCH)

	// exit
	Log.Info("Message service end")
}
예제 #9
0
func main() {
	flag.Parse()
	log.Info("message ver: \"%s\" start", ver.Version)
	if err := InitConfig(); err != nil {
		panic(err)
	}
	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// init log
	log.LoadConfiguration(Conf.Log)
	defer log.Close()
	// start pprof http
	perf.Init(Conf.PprofBind)
	// Initialize redis
	if err := InitStorage(); err != nil {
		panic(err)
	}
	// init rpc service
	if err := InitRPC(); err != nil {
		panic(err)
	}
	// init zookeeper
	zk, err := InitZK()
	if err != nil {
		if zk != nil {
			zk.Close()
		}
		panic(err)
	}
	// process init
	if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
		panic(err)
	}
	// init signals, block wait signals
	sig := InitSignal()
	HandleSignal(sig)
	// exit
	log.Info("message stop")
}
예제 #10
0
func main() {
	var err error
	// Parse cmd-line arguments
	flag.Parse()
	signalCH := InitSignal()

	// Load config
	Conf, err = NewConfig(ConfFile)
	if err != nil {
		panic(err)
	}

	// Set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)

	// Load log
	if Log, err = log.New(Conf.LogPath, Conf.LogLevel); err != nil {
		panic(err)
	}
	Log.Debug("initialize config %v", *Conf)

	// Initialize zookeeper
	if err := InitWatch(); err != nil {
		Log.Error("InitWatch() failed(%v)", err)
		os.Exit(-1)
	}

	// Begin watch nodes
	if err := BeginWatchNode(); err != nil {
		Log.Error("BeginWatchNode() failed(%v)", err)
		os.Exit(-1)
	}

	// Initialize message server client
	if err := InitMsgSvrClient(); err != nil {
		Log.Error("InitMsgSvrClient() failed(%v)", err)
		os.Exit(-1)
	}

	// start pprof http
	perf.Init(Conf.PprofBind)

	// Internal admin handle
	go func() {
		adminServeMux := http.NewServeMux()

		adminServeMux.HandleFunc("/admin/push", AdminPushPrivate)
		adminServeMux.HandleFunc("/admin/push/public", AdminPushPublic)
		adminServeMux.HandleFunc("/admin/node/add", AdminNodeAdd)
		adminServeMux.HandleFunc("/admin/node/del", AdminNodeDel)
		adminServeMux.HandleFunc("/admin/msg/clean", AdminMsgClean)

		err := http.ListenAndServe(Conf.AdminAddr, adminServeMux)
		if err != nil {
			Log.Error("http.ListenAndServe(\"%s\") failed(%v)", Conf.AdminAddr, err)
			os.Exit(-1)
		}
	}()

	// Start service
	go func() {
		// External service handle
		httpServeMux := http.NewServeMux()
		httpServeMux.HandleFunc("/server/get", ServerGet)
		httpServeMux.HandleFunc("/msg/get", MsgGet)
		httpServeMux.HandleFunc("/time/get", TimeGet)

		server := &http.Server{Handler: httpServeMux, ReadTimeout: httpReadTimeout * time.Second}
		l, err := net.Listen("tcp", Conf.Addr)
		if err != nil {
			Log.Error("net.Listen(\"tcp\", \"%s\") error(%v)", Conf.Addr, err)
			os.Exit(-1)
		}
		if err := server.Serve(l); err != nil {
			Log.Error("server.Serve(\"%s\") error(%v)", Conf.Addr, err)
			os.Exit(-1)
		}
	}()

	// 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 {
		Log.Error("process.Init() error(%v)", err)
		os.Exit(-1)
	}

	// init signals, block wait signals
	Log.Info("Web service start")
	HandleSignal(signalCH)

	// Clost message service client
	MsgSvrClose()
	// Stop watch
	WatchStop()
	Log.Warn("Web service end")
}
예제 #11
0
파일: main.go 프로젝트: humortian/im
func main() {
	// parse cmd-line arguments
	flag.Parse()
	log.Info("comet ver: \"%s\" start", ver.Version)
	// init config
	if err := InitConfig(); err != nil {
		panic(err)
	}
	// set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)
	// init log
	log.Info("comet log configuration")
	log.LoadConfiguration(Conf.Log)
	defer log.Close()
	// start pprof
	log.Info("comet init perf")
	perf.Init(Conf.PprofBind)
	// create channel
	// if process exit, close channel
	UserChannel = NewChannelList()
	defer UserChannel.Close()
	// start stats
	log.Info("comet start stats")

	StartStats()
	// start rpc,应该不需要了吧?
	log.Info("comet start rpc")

	if err := InitControllerRpcClient(); err != nil {
		panic(err)
	}
	defer thriftPool.Release()

	// start comet
	log.Info("comet start ")
	if err := StartComet(); err != nil {
		panic(err)
	}

	// configuration the kafka topic and kafka consumer to consum the notify messages.
	log.Info("queue start")
	if err := StartQueue(); err != nil {
		panic(err)
	}

	// init zookeeper,用来监控instance的启动和服务down。同步instance的ip,queue,信息到配置中心。配置中心监控监控变动,同步信息到调度中心。
	zkConn, err := InitZK()
	if err != nil {
		if zkConn != nil {
			zkConn.Close()
		}
		panic(err)
	}
	// process init
	//	if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil {
	//		panic(err)
	//	}
	// init signals, block wait signals
	signalCH := InitSignal()
	HandleSignal(signalCH)
	// exit
	log.Info("comet stop")
}