73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
_ "net/http/pprof"
|
|
"os"
|
|
"rocommon"
|
|
"rocommon/service"
|
|
_ "rocommon/socket"
|
|
_ "rocommon/socket/tcp"
|
|
"roserver/baseserver"
|
|
"roserver/baseserver/model"
|
|
self "roserver/battleboss/model"
|
|
_ "roserver/battleboss/msg"
|
|
"runtime"
|
|
"strconv"
|
|
"syscall"
|
|
)
|
|
|
|
//todo...
|
|
// 单点有状态服务器
|
|
func main() {
|
|
//记录battleboss pid用来做关闭操作
|
|
sysType := runtime.GOOS
|
|
if sysType != "windows" {
|
|
if pid := syscall.Getpid(); pid != 1 {
|
|
fileName := "battleboss_server.pid" + strconv.Itoa(pid)
|
|
ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
|
|
defer os.Remove(fileName)
|
|
}
|
|
}
|
|
|
|
//go func(){
|
|
// log.Println(http.ListenAndServe("localhost:8005", nil))
|
|
//}()
|
|
|
|
//CPU
|
|
//prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/serverboss.pprof"), profile.NoShutdownHook)
|
|
|
|
baseserver.Init(model.SERVICE_NODE_TYPE_BOSS_STR, self.ConfigInit, &self.BossUpdate{})
|
|
|
|
//prof := profile.Start(profile.MemProfile, profile.ProfilePath("./pprof/serverbossmem.pprof"), profile.NoShutdownHook)
|
|
|
|
sConfig := service.GetServiceConfig()
|
|
//先建立服务器对应的连接,在监听客户端
|
|
//创建监听器
|
|
var acceNode rocommon.ServerNode = nil
|
|
if sConfig.Node.Addr != "" {
|
|
acceNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
|
|
ServiceType: "tcpAcceptor",
|
|
ServiceName: model.SERVICE_NODE_TYPE_BOSS_STR,
|
|
ProcName: "common.backend",
|
|
LisAddr: sConfig.Node.Addr,
|
|
}, sConfig)
|
|
}
|
|
|
|
for _, concern := range sConfig.Node.Concern {
|
|
//建立需要链接的服务器,可以通过服务器发现etcd来处理(包含在了CreateConnector中)
|
|
baseserver.CreateConnector(baseserver.ServiceParam{
|
|
DiscoveryServiceName: concern,
|
|
DiscoveryServiceZone: sConfig.Node.Zone,
|
|
ServiceType: "tcpConnector",
|
|
ServiceName: model.SERVICE_NODE_TYPE_BOSS_STR,
|
|
ProcName: "common.backend",
|
|
})
|
|
}
|
|
|
|
baseserver.Wait()
|
|
//CPU
|
|
//prof.Stop()
|
|
baseserver.Exit(acceNode)
|
|
}
|