main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "rocommon"
  6. "rocommon/service"
  7. _ "rocommon/socket"
  8. _ "rocommon/socket/tcp"
  9. "roserver/baseserver"
  10. "roserver/baseserver/model"
  11. _ "roserver/battlerecord/msg"
  12. "runtime"
  13. "strconv"
  14. "syscall"
  15. )
  16. func main() {
  17. //记录battleboss pid用来做关闭操作
  18. sysType := runtime.GOOS
  19. if sysType != "windows" {
  20. if pid := syscall.Getpid(); pid != 1 {
  21. fileName := "battlerecord_server.pid" + strconv.Itoa(pid)
  22. ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
  23. defer os.Remove(fileName)
  24. }
  25. }
  26. //CPU
  27. //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/rank.pprof"), profile.NoShutdownHook)
  28. //prof := profile.Start(profile.MemProfile, profile.ProfilePath("./pprof/rankmem.pprof"), profile.NoShutdownHook)
  29. baseserver.Init(model.SERVICE_NODE_TYPE_BATTLERECORD_STR, nil, nil)
  30. //先建立服务器对应的连接,在监听客户端
  31. sConfig := service.GetServiceConfig()
  32. //配置文件初始化,如果后续做热更新的话,需要加锁,或者用sync.map
  33. //创建监听器
  34. var acceNode rocommon.ServerNode = nil
  35. if sConfig.Node.Addr != "" {
  36. acceNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
  37. ServiceType: "tcpAcceptor",
  38. ServiceName: model.SERVICE_NODE_TYPE_BATTLERECORD_STR,
  39. ProcName: "common.backend",
  40. LisAddr: sConfig.Node.Addr,
  41. }, sConfig)
  42. }
  43. for _, concern := range sConfig.Node.Concern {
  44. //建立需要链接的服务器,可以通过服务器发现etcd来处理(包含在了CreateConnector中)
  45. baseserver.CreateConnector(baseserver.ServiceParam{
  46. DiscoveryServiceName: concern,
  47. DiscoveryServiceZone: sConfig.Node.Zone,
  48. ServiceType: "tcpConnector",
  49. ServiceName: model.SERVICE_NODE_TYPE_BATTLERECORD_STR,
  50. ProcName: "common.backend",
  51. })
  52. }
  53. baseserver.Wait()
  54. //CPU
  55. //prof.Stop()
  56. baseserver.Exit(acceNode)
  57. }