main.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. model2 "roserver/globalcross_router/model"
  12. _ "roserver/globalcross_router/msg"
  13. "runtime"
  14. "strconv"
  15. "syscall"
  16. )
  17. func main() {
  18. //记录gate pid用来做关闭操作
  19. sysType := runtime.GOOS
  20. if sysType != "windows" {
  21. if pid := syscall.Getpid(); pid != 1 {
  22. fileName := "globalcrossrouter_server.pid" + strconv.Itoa(pid)
  23. ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
  24. defer os.Remove(fileName)
  25. }
  26. }
  27. baseserver.Init(model.SERVICE_NODE_TYPE_GLOBALCROSSROUTER_STR, nil, &model2.GGCrossRouterUpdate{})
  28. //先建立服务器对应的连接,在监听客户端
  29. sConfig := service.GetServiceConfig()
  30. //创建监听器
  31. var acceptorNode rocommon.ServerNode = nil
  32. if sConfig.Node.Addr != "" {
  33. acceptorNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
  34. ServiceType: "tcpAcceptor",
  35. ServiceName: model.SERVICE_NODE_TYPE_GLOBALCROSSROUTER_STR,
  36. ProcName: "crossrouter.backend",
  37. LisAddr: sConfig.Node.Addr,
  38. }, sConfig)
  39. }
  40. for _, concern := range sConfig.Node.Concern {
  41. if concern == model.SERVICE_NODE_TYPE_SOCIAL_STR {
  42. //social来自跨服多区
  43. //建立需要链接的服务器,通过服务器发现etcd来处理(包含在了CreateConnector中)
  44. baseserver.CreateConnector(baseserver.ServiceParam{
  45. DiscoveryServiceName: concern,
  46. ServiceType: "tcpConnector",
  47. ServiceName: model.SERVICE_NODE_TYPE_GLOBALCROSSROUTER_STR,
  48. ProcName: "crossrouter.backend",
  49. })
  50. } else {
  51. //其他服务器节点表示当前服务组自身需要的节点
  52. //建立需要链接的服务器,通过服务器发现etcd来处理(包含在了CreateConnector中)
  53. baseserver.CreateConnector(baseserver.ServiceParam{
  54. DiscoveryServiceName: concern,
  55. DiscoveryServiceZone: sConfig.Node.Zone,
  56. ServiceType: "tcpConnector",
  57. ServiceName: model.SERVICE_NODE_TYPE_GLOBALCROSSROUTER_STR,
  58. ProcName: "crossrouter.backend",
  59. })
  60. }
  61. }
  62. baseserver.Wait()
  63. baseserver.Exit(acceptorNode)
  64. }