main.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/social/model"
  12. _ "roserver/social/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 := "social_server.pid" + strconv.Itoa(pid)
  23. ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
  24. defer os.Remove(fileName)
  25. }
  26. }
  27. //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/social.pprof"), profile.NoShutdownHook)
  28. baseserver.Init(model.SERVICE_NODE_TYPE_SOCIAL_STR, nil, nil)
  29. //先建立服务器对应的连接,在监听客户端
  30. sConfig := service.GetServiceConfig()
  31. //创建监听器
  32. var acceptorNode rocommon.ServerNode = nil
  33. if sConfig.Node.Addr != "" {
  34. acceptorNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
  35. ServiceType: "tcpAcceptor",
  36. ServiceName: model.SERVICE_NODE_TYPE_SOCIAL_STR,
  37. ProcName: "common.backend",
  38. LisAddr: sConfig.Node.Addr,
  39. }, sConfig)
  40. }
  41. for _, concern := range sConfig.Node.Concern {
  42. //建立需要链接的服务器,通过服务器发现etcd来处理(包含在了CreateConnector中)
  43. baseserver.CreateConnector(baseserver.ServiceParam{
  44. DiscoveryServiceName: concern,
  45. DiscoveryServiceZone: sConfig.Node.Zone,
  46. ServiceType: "tcpConnector",
  47. ServiceName: model.SERVICE_NODE_TYPE_SOCIAL_STR,
  48. ProcName: "social.backend",
  49. })
  50. }
  51. baseserver.Wait()
  52. //prof.Stop()
  53. baseserver.Exit(acceptorNode)
  54. }