main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/interface/main/history/conf"
  10. "go-common/app/interface/main/history/http"
  11. rpc "go-common/app/interface/main/history/server/gorpc"
  12. "go-common/app/interface/main/history/server/grpc"
  13. "go-common/app/interface/main/history/service"
  14. ecode "go-common/library/ecode/tip"
  15. "go-common/library/log"
  16. "go-common/library/net/trace"
  17. "go-common/library/queue/databus/report"
  18. )
  19. func main() {
  20. flag.Parse()
  21. if err := conf.Init(); err != nil {
  22. log.Error("conf.Init() error(%v)", err)
  23. panic(err)
  24. }
  25. log.Init(conf.Conf.Xlog)
  26. defer log.Close()
  27. trace.Init(conf.Conf.Tracer)
  28. defer trace.Close()
  29. log.Info("history start")
  30. ecode.Init(conf.Conf.Ecode)
  31. report.InitUser(conf.Conf.Report)
  32. svr := service.New(conf.Conf)
  33. rpcSvr := rpc.New(conf.Conf, svr)
  34. grpcSvr := grpc.New(conf.Conf.GRPC, svr)
  35. http.Init(conf.Conf, svr)
  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("history get a signal %s", s.String())
  41. switch s {
  42. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  43. log.Info("history exit")
  44. grpcSvr.Shutdown(context.TODO())
  45. time.Sleep(2 * time.Second)
  46. rpcSvr.Close()
  47. svr.Close()
  48. return
  49. case syscall.SIGHUP:
  50. // TODO reload
  51. default:
  52. return
  53. }
  54. }
  55. }