main.go 1.3 KB

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