main.go 1.3 KB

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