main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/service/main/identify-game/server/grpc"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. "time"
  10. "go-common/app/service/main/identify-game/conf"
  11. rpc "go-common/app/service/main/identify-game/rpc/server"
  12. "go-common/app/service/main/identify-game/server/http"
  13. "go-common/app/service/main/identify-game/service"
  14. "go-common/library/log"
  15. "go-common/library/net/trace"
  16. )
  17. func main() {
  18. flag.Parse()
  19. // init conf,log,trace,stat,perf.
  20. if err := conf.Init(); err != nil {
  21. panic(err)
  22. }
  23. log.Init(conf.Conf.Xlog)
  24. defer log.Close()
  25. trace.Init(conf.Conf.Tracer)
  26. defer trace.Close()
  27. // service init
  28. svr := service.New(conf.Conf)
  29. rpcSvr := rpc.New(conf.Conf, svr)
  30. http.Init(conf.Conf, svr)
  31. // init warden server
  32. ws := grpc.New(conf.Conf.WardenServer, svr)
  33. // signal handler
  34. log.Info("identify-game-service start")
  35. c := make(chan os.Signal, 1)
  36. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for {
  38. s := <-c
  39. log.Info("identify-game-service get a signal %s", s.String())
  40. switch s {
  41. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  42. rpcSvr.Close()
  43. time.Sleep(time.Second * 2)
  44. svr.Close()
  45. ws.Shutdown(context.Background())
  46. log.Info("identify-game-service exit")
  47. return
  48. case syscall.SIGHUP:
  49. default:
  50. return
  51. }
  52. }
  53. }